我感到困惑,无法理解这个问题,希望有人能指点一下我。
我有一个如下的类:
public class Foo<T>
{
public List<T> Data;
}
现在我正在编写代码以反映这个类,并想出一种确定字段Data正在使用泛型参数的方法。
我的初始方法是继续向下走尽可能多的层次,一旦遇到IsGenericParameter字段设置为true,我会将类型名称替换为“Generic Argument”字符串,但是我似乎无法使它按照我想要的方式工作。
我已经搜索过了,但是目前我找到的每个解决方案似乎都指向了死胡同。
System.Type
实例是什么?是typeof(Foo<>)
还是类似于typeof(Foo<SomeType>)
的东西? - Sergey KalinichenkoIsGenericType
是你要找的吗?例如:typeof(Foo<int>).GetField("Data").FieldType.IsGenericType
- D Stanley