How to get underlying type for IEnumerable<T> with Roslyn?

962 views Asked by At

How can I get an underlying type from ITypeSymbol for IEnumerable<MyType>? I see ITypeSymbol.OriginalDefinition contains link to IEnumerable<>, but where can I get ITypeSymbol for MyType?

1

There are 1 answers

0
SLaks On BEST ANSWER

Generic type parameters are a feature of named types (as opposed to arrays or pointers).

You need to cast to INamedTypeSymbol; you can then look at the TypeArguments property.

Side note: To get the open generic type, use ConstructedFrom, not OriginalDefinition.