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

时间:2020-03-06 14:20:01  来源:igfitidea点击:

我希望能够做到这一点。

MyInterface interface = new ServiceProxyHelper<ProxyType>();

这是对象结构

MyTypeThatImplementsMyInterface : MyInterface

这会工作吗?

public class ProxyType : MyInterface {}

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

解决方案

我认为这是我们要尝试执行的操作:

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