MethodInfo method = typeof(BuildManager).GetMethod("ThrowIfPreAppStartNotRunning", BindingFlags.Static | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
dynamicModuleReflectionUtil.ThrowIfPreAppStartNotRunning = CommonReflectionUtil.MakeDelegate<Action>(method);
public static T MakeDelegate<T>(MethodInfo method) where T : class
{
return CommonReflectionUtil.MakeDelegate<T>(null, method);
}
public static T MakeDelegate<T>(object target, MethodInfo method) where T : class
{
return CommonReflectionUtil.MakeDelegate(typeof(T), target, method) as T;
}
[ReflectionPermission(SecurityAction.Assert, MemberAccess = true)]
public static Delegate MakeDelegate(Type delegateType, object target, MethodInfo method)
{
//ReflectionPermission permission = new ReflectionPermission(PermissionState.Unrestricted);
//permission.Assert();
return Delegate.CreateDelegate(delegateType, target, method);
}
这样调用会抛出权限异常,可是使用了断言了呀,何解?
修改web.config