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

958 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 best solutions below

0
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.