jeudi 7 mars 2019

Getting generic type from the DeclaringType of a nested type in C# with reflection

Say I have the following class structure:

public class Outer<T>
{
    public class Inner<U>
    {
    }
}

And some code:

var testType = typeof(Outer<string>.Inner<int>);

How can I get the constructed generic type typeof(Outer<string>), or the value of the generic typeof(string) from the testType variable?





Aucun commentaire:

Enregistrer un commentaire