如何使用.Net Generics继承模板参数?

时间:2021-03-22 09:11:19

I want to be able to do this.

我希望能够做到这一点。

MyInterface interface = new ServiceProxyHelper<ProxyType>();

Here's the object structure

这是对象结构

MyTypeThatImplementsMyInterface : MyInterface

Will this work?

这会有用吗?

public class ProxyType : MyInterface {}

public class ServiceProxyHelper<ProxyType> : IDisposable, MyInterface {}

1 个解决方案

#1


3  

I think this is what you're trying to do:

我想这就是你要做的事情:

public class ServiceProxyHelper<T> where T : MyInterface { ... }

#1


3  

I think this is what you're trying to do:

我想这就是你要做的事情:

public class ServiceProxyHelper<T> where T : MyInterface { ... }