private void Initialize(string methodName, object[] argValues, object context) { Type contextType = (context is Type ? context as Type : context.GetType()); // check the context type first MethodInfo mi = GetBestMethod(contextType, methodName, BINDING_FLAGS, argValues); // if not found, probe the Type's type if (mi == null) { mi = GetBestMethod(typeof(Type), methodName, BINDING_FLAGS, argValues); } if (mi == null) { return; } else { ParameterInfo[] parameters = mi.GetParameters(); if (parameters.Length > 0) { ParameterInfo lastParameter = parameters[parameters.Length - 1]; cachedIsParamArray = lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0; if (cachedIsParamArray) { paramArrayType = lastParameter.ParameterType.GetElementType(); argumentCount = parameters.Length; } } cachedInstanceMethod = new SafeMethod(mi); cachedInstanceMethodHash = CalculateMethodHash(contextType, argValues); } }
private void Initialize(string methodName, object[] argValues, object context) { var contextType = (context is Type ? context as Type : context.GetType()); // check the context type first var mi = GetBestMethod(contextType, methodName, DefaultBindingFlags, argValues); // if not found, probe the Type's type if (mi == null) { mi = GetBestMethod(typeof(Type), methodName, DefaultBindingFlags, argValues); } if (mi == null) { return; } var parameters = mi.GetParameters(); if (parameters.Length > 0) { var lastParameter = parameters[parameters.Length - 1]; _cachedIsParamArray = lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0; if (_cachedIsParamArray) { _paramArrayType = lastParameter.ParameterType.GetElementType(); _argumentCount = parameters.Length; } } _cachedInstanceMethod = new SafeMethod(mi); _cachedInstanceMethodHash = CalculateMethodHash(contextType, argValues); }
static WebApplicationContext() { ILog s_weblog = LogManager.GetLogger(typeof(WebApplicationContext)); // register for ContextRegistry.Cleared event - we need to discard our cache in this case ContextRegistry.Cleared += new EventHandler(OnContextRegistryCleared); #if NET_2_0 && !MONO_2_0 if (HttpRuntime.AppDomainAppVirtualPath != null) // check if we're within an ASP.NET AppDomain! { // ensure HttpRuntime has been fully initialized! // this is a problem,.if ASP.NET Web Administration Application is used. This app does not fully set up the AppDomain... HttpRuntime runtime = (HttpRuntime) typeof(HttpRuntime).GetField("_theRuntime", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); bool beforeFirstRequest = false; lock (runtime) { beforeFirstRequest = (bool) typeof(HttpRuntime).GetField("_beforeFirstRequest", BindingFlags.Instance | BindingFlags.NonPublic). GetValue(runtime); } s_weblog.Debug("BeforeFirstRequest:" + beforeFirstRequest); if (beforeFirstRequest) { try { string firstRequestPath = HttpRuntime.AppDomainAppVirtualPath.TrimEnd('/') + "/dummy.context"; s_weblog.Info("Forcing first request " + firstRequestPath); SafeMethod fnProcessRequestNow = new SafeMethod(typeof(HttpRuntime).GetMethod("ProcessRequestNow", BindingFlags.Static | BindingFlags.NonPublic)); SimpleWorkerRequest wr = new SimpleWorkerRequest(firstRequestPath, string.Empty, new StringWriter()); fnProcessRequestNow.Invoke(null, new object[] { wr }); // HttpRuntime.ProcessRequest( // wr); s_weblog.Info("Successfully processed first request!"); } catch (Exception ex) { s_weblog.Error("Failed processing first request", ex); throw; } } } #endif }
/// <summary> /// Invokes the joinpoint using dynamic reflection. /// </summary> /// <remarks> /// <p> /// Subclasses can override this to use custom invocation. /// </p> /// </remarks> /// <returns> /// The return value of the invocation of the joinpoint. /// </returns> /// <exception cref="System.Exception"> /// If invoking the joinpoint resulted in an exception. /// </exception> /// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint"/> protected override object InvokeJoinpoint() { MethodInfo targetMethodInfo = this.proxyMethod ?? Method; IDynamicMethod targetMethod = new SafeMethod(targetMethodInfo); try { AssertUtils.Understands(Target, "target", targetMethodInfo); return(targetMethod.Invoke(Target, Arguments)); } // Only happens if fallback to standard reflection. catch (TargetInvocationException ex) { throw ReflectionUtils.UnwrapTargetInvocationException(ex); } }
/// <summary> /// Avoid beforeFieldInit /// </summary> static LocalResourceManager() { LocalResXResourceProviderFactoryType = typeof(IResourceProvider).Assembly.GetType("System.Web.Compilation.ResXResourceProviderFactory", true); LocalResXResourceProviderType = typeof(IResourceProvider).Assembly.GetType("System.Web.Compilation.LocalResXResourceProvider", true); GetResourceProviderDelegate fnGetResourceProvider = null; ResourceProviderFactory rpf = null; SafeMethod glra = null; SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), delegate { fnGetResourceProvider = (GetResourceProviderDelegate)Delegate.CreateDelegate(typeof(GetResourceProviderDelegate), typeof(ResourceExpressionBuilder).GetMethod("GetLocalResourceProvider", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(TemplateControl) }, null)); rpf = (ResourceProviderFactory)Activator.CreateInstance(LocalResXResourceProviderFactoryType, true); glra = new SafeMethod(LocalResXResourceProviderType.GetMethod("GetLocalResourceAssembly", BindingFlags.Instance | BindingFlags.NonPublic)); }); getLocalResourceProvider = fnGetResourceProvider; LocalResXResourceProviderFactory = rpf; fnGetLocalResourceAssembly = glra; }
object IMethodInterceptor.Invoke(IMethodInvocation invocation) { try { MethodInfo methodInfo = invocation.Method; object returnValue = base.Invoke(methodInfo, invocation.Arguments, invocation.Proxy); if (returnValue != InvokeImplementation) { return(returnValue); } SafeMethod method = new SafeMethod(methodInfo); return(method.Invoke(this.GetImplementation(), invocation.Arguments)); } catch (TargetInvocationException ex) { exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] { }); throw ex.InnerException; } }
public object Invoke(IMethodInvocation invocation) { try { MethodInfo methodInfo = invocation.Method; object returnValue = base.Invoke(methodInfo, invocation.Arguments); if (returnValue != InvokeImplementation) { return(returnValue); } var method = new SafeMethod(methodInfo); return(method.Invoke(realSession, invocation.Arguments)); } catch (TargetInvocationException ex) { throw ReflectHelper.UnwrapTargetInvocationException(ex); } }
public static VoidMethodDelegate ClearNamingContainer(MethodInfo methodInfo) { IDynamicMethod method = new SafeMethod(methodInfo); return new VoidMethodDelegate(new DynamicMethodWrapper(method).ClearNamingContainerInternal); }
public static RemovedControlDelegate RemovedControl(MethodInfo methodInfo) { IDynamicMethod method = new SafeMethod(methodInfo); return new RemovedControlDelegate(new DynamicMethodWrapper(method).RemovedControlInternal); }
public static CreateControlCollectionDelegate CreateControlCollection(MethodInfo methodInfo) { IDynamicMethod method = new SafeMethod(methodInfo); return new CreateControlCollectionDelegate(new DynamicMethodWrapper(method).CreateControlCollectionInternal); }