[英]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
现在由于某种奇怪的原因,当我从
ParameterizedSerializedDelegate
继承时,我在OnTransitionDelegate
上收到了“非通用类型'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...
-我不知道我的实际设置有什么不同...
看来我正在编辑ParameterizedSerializedDelegate
文件的“另一个”版本-因此VS所查看的是不同的。
@vexe's solution worked for me but I worked out what I did to reproduce it (explanation will use original question type names). @vexe的解决方案对我有用,但是我想出了重现它的方法(解释将使用原始问题类型名称)。
In VS2013, this can happen when you are using the CTRL-.
在VS2013中,使用
CTRL-.
时可能会发生这种情况CTRL-.
shortcut menu and not paying attention. 快捷菜单,而不关注。 Rather than choosing "Add << namespace >>", it is possible to select "Generate class for...", which will create a new stub class called
ParameterizedSerializedDelegate
in the same folder as OnTransitionDelegate
. 可以选择“ Generate class for ...”,而不是选择“ Add << namespace >>”,这将在与
OnTransitionDelegate
相同的文件夹中创建一个名为ParameterizedSerializedDelegate
的新存根类。
What is confusing is that if you hit F12
(go to definition) on ParameterizedSerializedDelegate
in the example above, it will find the generic version of it and take you there - even if the namespace is not available in that file. 令人困惑的是,如果您在上面的示例中在
ParameterizedSerializedDelegate
上单击了F12
(转到定义),它将找到它的通用版本并将您带到那里-即使该文件中没有命名空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.