/// <summary> /// Gets the list of /// <see langword="static"/> interceptors and dynamic interception /// advice that may apply to the supplied <paramref name="method"/> /// invocation. /// </summary> /// <param name="config">The proxy configuration.</param> /// <param name="proxy">The object proxy.</param> /// <param name="method"> /// The method to evaluate interceptors for. /// </param> /// <param name="targetType"> /// The <see cref="System.Type"/> of the target object. /// </param> /// <returns> /// A <see cref="System.Collections.IList"/> of /// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> (if there's /// a dynamic method matcher that needs evaluation at runtime). /// </returns> public static IList <object> CalculateInterceptors( IAdvised config, object proxy, MethodInfo method, Type targetType) { IList <object> interceptors = new List <object>(config.Advisors.Count); foreach (IAdvisor advisor in config.Advisors) { if (advisor is IPointcutAdvisor) { IPointcutAdvisor pointcutAdvisor = (IPointcutAdvisor)advisor; if (pointcutAdvisor.Pointcut.TypeFilter.Matches(targetType)) { IMethodInterceptor interceptor = (IMethodInterceptor)GlobalAdvisorAdapterRegistry.Instance.GetInterceptor(advisor); IMethodMatcher mm = pointcutAdvisor.Pointcut.MethodMatcher; if (mm.Matches(method, targetType)) { if (mm.IsRuntime) { // Creating a new object instance in the GetInterceptor() method // isn't a problem as we normally cache created chains... interceptors.Add(new InterceptorAndDynamicMethodMatcher(interceptor, mm)); } else { interceptors.Add(interceptor); } } } } } return(interceptors); }
/// <summary> /// Can the supplied <paramref name="advisor"/> apply at all on the /// supplied <paramref name="targetType"/>? /// </summary> /// <remarks> /// <p> /// This is an important test as it can be used to optimize out an /// advisor for a class. /// </p> /// </remarks> /// <param name="advisor">The advisor to check.</param> /// <param name="targetType">The class being tested.</param> /// <param name="proxyInterfaces"> /// The interfaces being proxied. If <see langword="null"/>, all /// methods on a class may be proxied. /// </param> /// <param name="hasIntroductions">whether or not the advisor chain for the target object includes any introductions.</param> /// <returns> /// <see langword="true"/> if the advisor can apply on any method. /// </returns> public static bool CanApply(IAdvisor advisor, Type targetType, Type[] proxyInterfaces, bool hasIntroductions) { if (advisor is IIntroductionAdvisor) { return(((IIntroductionAdvisor)advisor).TypeFilter.Matches(targetType)); } else if (advisor is IPointcutAdvisor) { IPointcutAdvisor pca = (IPointcutAdvisor)advisor; return(CanApply(pca.Pointcut, targetType, proxyInterfaces, hasIntroductions)); } // no pointcut specified so assume it applies... return(true); }