vendredi 11 décembre 2015

What is the equivalent of C++ Template Inheritance in C#?

I understand this is not possible in C#, because Generics are not Templates and they are implented differently(processing on runtime rather than during compile):

public class Foo<T> : T
{

}

The question though remains. Is there an equivalent or perhaps an alternative way to achieve this?

In my case I have three different parent classes I want to inherit from, let's call them A, B, C:

public class A {}

public class B {}

public class C {}

Then I have the Foo class, and then MANY more inheriting from Foo but each of them needing only one of the A, B, C:

public class X : Foo<A> {} 

public class Y : Foo<B> {}

public class Z : Foo<C> {}

So class X needs all the functionality in Foo and all the functionality in A, Y from Foo and B and so on...

How do I do this in C#?

Aucun commentaire:

Enregistrer un commentaire