2

Given:

Type T = typeof(List<string>);

Requirement:

typeof(List<>) == SomeFunction(T)

Many times when I'm reflecting over a type and want to find all properties that return lists of some type...I need the "SomeFunction" shown above. I've searched and searched, but cannot figure out how to get List<> from List<string>. I can use T.GetGenericArguments(), but that only returns string so that doesn't help at all.

1 Answer 1

8
typeof(List<string>).GetGenericTypeDefinition() == typeof(List<>)
Sign up to request clarification or add additional context in comments.

2 Comments

You know, I tried that before, and I saw List`1 and thought that GetGenericTypeDefinition() was returning List<string>. My bad, your solution works great!
List`1 is the same as List<>. Likewise, Func`2 is Func<T,R>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.