1
我需要通过反射来获取通用参数的通用类型。但是真正的类型,而不是类型{Name =“T”;全名= NULL}如何通过反射获得通用参数的类型
public void Sample<T>(T i, object o)
{
MethodBase basee = MethodBase.GetCurrentMethod();
Type[] types = basee.GetGenericArguments();
}
,但我不能使用的typeof(T),因为我使用反射
有没有一种方法(使用反射),以获得通用的参数类型类型。
// in this case i should get (Type) { Name="Int32" ; FullName="System.Int32" }
myClassObj.Sample(10, new object());
在其他千卡,我whant知道如何调用使用typeof调用的方法(T)例如:
// in Il code I see that the compiler use:
// ldtoken !!T => this should get the RuntimeTypeHandle needed as parameter
// System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
Type t = Type.GetTypeFromHandle(? ? ?);
我怎么会从T通用参数得到RuntimTypeHandle
为什么你不能使用'i.GetType()'?对于这个问题,为什么你不能使用typeof(T)?这会告诉你这是一个整数。 – aquinas
价值我可以是空的,并使崩溃...:S –
公平的。但为什么不输入typeof(T)? – aquinas