Using Windows 2012 C# for Windows 8 (WinRT/Metro) I am having problems with the following:
public class HelperClass
{
public static bool test()
{
return true;
}
public static bool test1<T>()
{
return true;
}
public void runTestMethod()
{
Type[] tt = new Type[]{};
object[] param1 = new object[] {};
MethodInfo method = typeof(HelperClass).GetRuntimeMethod("test", tt);
//This works just fine
object o = method.Invoke(null,param1)
}
public void runTestMethod1(PropertyInfo p)
{
Type[] tt = new Type[]{};
object[] param1 = new object[] {};
MethodInfo method = typeof(HelperClass).GetRuntimeMethod("test", tt);
MethodInfo generic = method.MakeGenericMethod(p.GetType());
//This breaks with the error below
object o = generic.Invoke(null,param1)
}
}
The API 'D20OGL.BusinessObjects.HelperClass.test[RuntimePropertyInfo]()' cannot be used on the current platform. See http://go.microsoft.com/fwlink/?LinkId=248273 for more information.
The code i'm writing heavily relies on reflection and generics. Anyone know a workaround to this???
Thanks!
You almost certainly meant
method.MakeGenericMethod(p.PropertyType);
or possibly
method.MakeGenericMethod(p.DeclaringType);
and not
method.MakeGenericMethod(p.GetType());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.