Get generic instance generic type using reflection

2019-07-15 09:42发布

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条回答
闹够了就滚
2楼-- · 2019-07-15 10:05
typeof(List<string>).GetGenericTypeDefinition() == typeof(List<>)
查看更多
登录 后发表回答