如何使用反射获取泛型类的名称
例如
public class SomeGenericClass<T>
{
}
SomeGenericClass<int> test = new SomeGenericClass<int>();
test.GetType().Name
返回"SomeGenericClass'1“
如何让它返回没有'1的"SomeGenericClass“?
发布于 2009-11-18 00:25:46
下面的内容如何?
test.GetType().Name.Split('\'')[0]
它也适用于非泛型类。
发布于 2009-11-18 00:49:45
“1”是名称的一部分,因为,例如,List<T>
和List
(如果我创建了这样一个类)是不同的类。
'1表示它有一个类型参数。如果你想知道该参数的类型,可以使用test.GetType().GetGenericArguments();
发布于 2009-11-18 02:49:27
enum.GetName(test.GetType(), test).ToString()
https://stackoverflow.com/questions/1752823
复制相似问题