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?
You can’t inherit from the generic type parameter. C# generics are very different from C++ templates. Inheriting from the type parameter requires the class to have a completely different representation based on the type parameter, which is not what happens with .NET generics. They are identical at the IL and native level (for all reference type arguments).