Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 253
dubtar Avatar asked Dec 23 '22 22:12

dubtar


1 Answers

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.

like image 169
SLaks Avatar answered May 16 '23 04:05

SLaks