How to I get the underlying type of a generic list from a property: List<Dog>

How to I get the underlying type of a generic list from a property? (IProperty/IPropertyDescriptor)

Example:
I want to get the Resharper SDK type of 'Dog' for code: List<Dog>

I am currently itterating over a class's PropertyDescriptors and need to get the generic type of "Dog"

1 comment
Comment actions Permalink

Given an IProperty, you can use the ReturnType property to get the type of the property, e.g. List<Dog>. This gives you an IType, but you need to convert this to an instance of ITypeElement, so you should be able to call the GetTypeElement<ITypeElement>() extension method, and you can then iterate of the returned type element's TypeParameters property to get at the generic type(s).

0

Please sign in to leave a comment.