简体   繁体   English

意外的“非泛型类型不能与类型参数一起使用”?

[英]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.

相关问题 非通用类型&#39;IdentityUser&#39;不能与类型参数一起使用 - The non-generic type 'IdentityUser' cannot be used with type arguments 错误非泛型类型“…”不能与类型参数一起使用 - Error The non-generic type '…' cannot be used with type arguments 错误:不能使用非通用类型&#39;GenericTypeIndicator&#39;的类型参数 - Error: The non-generic type 'GenericTypeIndicator' cannot be used type arguments 非通用方法“字典 <Type, Type> .Add(Type,Type)&#39;不能与类型参数一起使用 - The non-generic method 'Dictionary<Type, Type>.Add(Type, Type)' cannot be used with type arguments 非泛型类型&#39;System.Collections.ArrayList&#39;不能与类型参数一起使用 - The non-generic type 'System.Collections.ArrayList' cannot be used with type arguments 非泛型类型'System.Collections.IEnumerable'不能与类型参数一起使用 - The non-generic type 'System.Collections.IEnumerable' cannot be used with type arguments 不知道如何解决“非泛型类型 'ArrayList' 不能与类型参数一起使用”? - Don't know how to fix "The non-generic type 'ArrayList' cannot be used with type arguments"? “非泛型方法‘IServiceProvider.GetService(Type)’不能与类型参数一起使用 - "The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments 非泛型方法“IServiceProvider.GetService(Type)”不能与类型参数一起使用 - The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments “非泛型类型 'System.Web.UI.Pair' 不能与类型参数一起使用”是什么意思? - What does “The non-generic type 'System.Web.UI.Pair' cannot be used with type arguments” mean?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM