Tim*_*dge 2 c# generics reflection
鉴于:
Type T = typeof(List<string>);
Run Code Online (Sandbox Code Playgroud)
需求:
typeof(List<>) == SomeFunction(T)
Run Code Online (Sandbox Code Playgroud)
很多时候,当我在一个类型上反思并想要找到返回某些类型列表的所有属性时...我需要上面显示的"SomeFunction".我找啊找,但无法弄清楚如何获得List<>从List<string>.我可以使用T.GetGenericArguments(),但这只会返回,string所以根本没有帮助.
typeof(List<string>).GetGenericTypeDefinition() == typeof(List<>)
Run Code Online (Sandbox Code Playgroud)