public void StaticMethodMatchImplAlwaysMatchesRegardless()
        {
            Type oneType               = typeof(One);
            ControlFlowPointcut cut    = new ControlFlowPointcut(oneType);
            IMethodMatcher      filter = cut.MethodMatcher;
            MethodInfo          method = oneType.GetMethod("GetAge");

            Assert.IsTrue(filter.Matches(method, oneType),
                          "Must always match regardless of the supplied arguments.");
            Assert.IsTrue(filter.Matches(method, GetType()),
                          "Must always match even if the supplied argument method and Type are not " +
                          "a match for the name and Type supplied in the ctor.");
            Assert.IsTrue(filter.Matches(null, null),             // args are ingored in this impl...
                          "Must always match even if the supplied arguments are null");
        }
Пример #2
0
        /// <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);
        }
        public void DynamicMethodMatchWithTypeAndMethodNameSpecifiedInCtorNoMatch()
        {
            ControlFlowPointcut cut    = new ControlFlowPointcut(GetType(), "KiloRiley");
            IMethodMatcher      filter = cut.MethodMatcher;

            Assert.IsFalse(filter.Matches(null, null, null),             // args are ingored in this impl...
                           "Must not match - under cflow of Type specified in ctor, but no match on method name.");
        }
        public void DynamicMethodMatchWithJustTypeSpecifiedInCtor()
        {
            ControlFlowPointcut cut    = new ControlFlowPointcut(GetType());
            IMethodMatcher      filter = cut.MethodMatcher;

            Assert.IsTrue(filter.Matches(null, null, null),             // args are ingored in this impl...
                          "Must match - under cflow of Type specified in ctor");
        }
Пример #5
0
 /// <summary>
 /// Performs the least expensive check for a match.
 /// </summary>
 /// <param name="pointcut">
 /// The <see cref="Spring.Aop.IPointcut"/> to be evaluated.
 /// </param>
 /// <param name="method">The candidate method.</param>
 /// <param name="targetType">
 /// The target <see cref="System.Type"/>.
 /// </param>
 /// <param name="args">The arguments to the method</param>
 /// <returns><see langword="true"/> if there is a runtime match.</returns>
 /// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
 public static bool Matches(
     IPointcut pointcut, MethodInfo method, Type targetType, object[] args)
 {
     if (pointcut != null)
     {
         if (pointcut == TruePointcut.True)
         {
             return(true);
         }
         if (pointcut.TypeFilter.Matches(targetType))
         {
             IMethodMatcher mm = pointcut.MethodMatcher;
             if (mm.Matches(method, targetType))
             {
                 return(mm.IsRuntime ? mm.Matches(method, targetType, args) : true);
             }
         }
     }
     return(false);
 }
Пример #6
0
 public bool Matches(MethodInfo m, Type targetType)
 {
     return(a.Matches(m, targetType) && b.Matches(m, targetType));
 }