简体   繁体   English

继承泛型类T必须是引用类型

[英]Inherit generic class T must be a reference type

public class _Base_Client<T> : System.ServiceModel.ClientBase<T>

It complains that The type 'T' must be a reference type in order to use it as parameter 'TChannel' 它抱怨The type 'T' must be a reference type in order to use it as parameter 'TChannel'

T is a reference to an interface. T是对接口的引用。

Here is the line I wish to change to use the new base class 这是我希望更改为使用新基类的行

public class EchoServiceClient : 
    System.ServiceModel.ClientBase<IEchoService>, IEchoService

How can I fix this? 我怎样才能解决这个问题? thanks 谢谢

Change: 更改:

public class _Base_Client<T> : System.ServiceModel.ClientBase<T>

To: 至:

public class _Base_Client<T> : System.ServiceModel.ClientBase<T> where T : class

The constraints in your class must be at least as strict as the constraints defined in its base class ( ClientBase ). 类中的约束必须至少与其基类( ClientBase )中定义的约束一样严格。 To wit, here is the declaration of ClientBase : 也就是说,这是ClientBase的声明:

public abstract class ClientBase<TChannel> : ICommunicationObject, 
    IDisposable where TChannel : class

Notice the class constraint. 注意class约束。

You can't use the interface in there. 你不能在那里使用界面。 You need a concrete implementation of IEchoService . 您需要IEchoService的具体实现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Blazor 中创建一个必须从具有泛型类型的类继承的泛型类型? - How to make a generic type that must inherit from a class with generic type in Blazor? 泛型类从T继承 - Generic Class inherit from T C#:如何设计泛型类,以便type参数必须继承某个类? - C#: How to design a generic class so that the type parameter must inherit a certain class? 我可以从泛型类型 T 继承泛型 class 吗? 喜欢我的班级<t> : T</t> - Can I inherit a generic class from a generic type T? Like MyClass<T> : T 为了在通用类型或方法“ QueryAPI.Query”中将其用作参数“ T”,类型“ T”必须是引用类型。 <T> () - The type 'T' must be a reference type in order to use it as parameter 'T' in the generic type or method 'QueryAPI.Query<T>() 从具有泛型类型的类继承 - Inherit from a class that has a generic type 该类型必须是引用类型,才能在通用类型或方法中将其用作参数“ T” - The type must be a reference type in order to use it as parameter 'T' in the generic type or method TOut类型必须是引用类型,才能在通用方法类型中用作参数T - The Type TOut must be a reference type in order to use it as a parameter T in the generic type of method 如何确定 T 是泛型中的值类型还是引用类? - How to determine whether T is a value type or reference class in generic? 类中没有泛型引用的泛型方法 - Generic Type Method Without Generic Reference in Class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM