开发者

Get generic instance generic type using reflection

开发者 https://www.devze.com 2023-03-13 00:02 出处:网络
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

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 开发者_JAVA百科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.


typeof(List<string>).GetGenericTypeDefinition() == typeof(List<>)
0

精彩评论

暂无评论...
验证码 换一张
取 消