I cannot find a way to do this for any generic type, but if you need to do this for a specific type, this is possible in some cases.
For example, I have the following code to check if a type is a collection, and if so, get the element type:
private static bool IsCollectionType(CodeType type, out CodeType elementType) {
As you can see, I do not directly consider the generic type argument, but instead I look at the IEnumerable<T>.GetEnumerator().Current . Of course, this requires specific knowledge of the type you are working with.
Thomas levesque
source share