How to inherit from a generic parameter?

Posted by Bob on Stack Overflow See other posts from Stack Overflow or by Bob
Published on 2010-06-15T18:12:55Z Indexed on 2010/06/15 18:22 UTC
Read the original article Hit count: 131

Filed under:

I'm basically wanting to do this:

class UILockable<T> : T
    where T : UIWidget
{
}

However, this doesn't work. I've seen people recommend that you do this:

class UILockable<T>
    where T : UIWidget
{
    private T _base;
}

This would require me to override each function UILockable would need and forward it to T. This is impossible since T may derive from UIWidget and have unique abstract/virtual methods of its own.

Is there no way to simply inherit from T?

© Stack Overflow or respective owner

Related posts about c#