我有一个静态的方法的泛型类给出使用类型参数的方法:访问静态方法,其中T是由一个类型实例
GenericClass<T>
{
public static void Method()
{
//takes info from typeof(T)
}
}
现在,我需要访问的静态方法,但不能简单地使用GenericClass<KnownType>.Method()
。我需要做一个Type实例。所以:
public void OutsiderMethod(Type T)
{
GenericClass<T>.Method()
//it's clear this line won't compile, for T is a Type instance
//but i want some way to have access to that static method.
}
使用反射,我大概可以得到一个方式,通过它的字符串名称来调用该方法,使用一些MethodInfo的东西。 这部分好,解决了这个问题。 但是,如果可能的话,我很乐意不用这个名字作为字符串。
任何???
扩展方法不适合这种情况吗? – 2013-04-10 16:50:28
这将需要一个GenericClass的实例,其中T由Type实例给出。 –
2013-04-10 16:59:51