samedi 29 août 2015

How to get the concrete type of base generic

Assuming I have a class A:

class A : B<C>, IA
{

}

And I also have a method like this:

Type GetConcreteB<T>() where T : IA
{
//some code here...
}

In this method I would like to check if T inherits from any B (currently I wrap B into an interface IB which does the thing) and if it does, return the concrete type of C.

So, basically I want to return the concrete type of the base generic class only using the subclass type. Is there a way to achieve this?





Aucun commentaire:

Enregistrer un commentaire