.Net Generics를 사용하여 템플릿 매개변수를 상속하려면 어떻게 해야 합니까?

StackOverflow https://stackoverflow.com/questions/90117

  •  01-07-2019
  •  | 
  •  

문제

나는 이것을 할 수 있기를 원합니다.

MyInterface interface = new ServiceProxyHelper<ProxyType>();

객체 구조는 다음과 같습니다

MyTypeThatImplementsMyInterface : MyInterface

이것이 작동할까요?

public class ProxyType : MyInterface {}

public class ServiceProxyHelper<ProxyType> : IDisposable, MyInterface {}
도움이 되었습니까?

해결책

나는 이것이 당신이하려는 일이라고 생각합니다 :

public class ServiceProxyHelper<T> where T : MyInterface { ... }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top