Search code examples
c#genericsgeneric-type-argument

An unexpected "The non-generic type cannot be used with the type arguments"?


I have the following hierarchy of classes:

public abstract class SerializedDelegateBase<TDelegate, TTarget>
    where TDelegate : class
    where TTarget : class
{
   ...
}

public abstract class SerializedMBDelegateBase<TDelegate> : SerializedDelegateBase<TDelegate, MonoBehaviour> where TDelegate : class
{
   ...
}

public class ParameterizedSerializedDelegate<T> : SerializedMBDelegateBase<Action<T>> where T : EventArgs
{
   ...
}

And finally:

[Serializable]
public class OnTransitionArg : EventArgs
{
    public string TransitionName { set; get; }
}

[Serializable]
public class OnTransitionDelegate : ParameterizedSerializedDelegate<OnTransitionArg> { }

Now for some strange reason, I'm getting "The non-generic type 'ParameterizedSerializedDelegate' cannot be used with type arguments" on my OnTransitionDelegate when I'm inheriting from ParameterizedSerializedDelegate

I have no idea why.

Anybody?

Thanks!

EDIT:

I should probably mention that the classes are in different files. I just tried a minimal but similar setup in terms of the generic arguments in one file, it worked! - I don't know what's different about my real setup...


Solution

  • It seems that I was editing 'another' version of the ParameterizedSerializedDelegate file - and so the one VS was looking at was different.