user17222
user17222

Reputation: 1711

How do I use .Net Generics to inherit a template parameter?

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 {}

Upvotes: 1

Views: 514

Answers (1)

jfs
jfs

Reputation: 16798

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

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

Upvotes: 3

Related Questions