/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int Compare(object x, object y) { MethodInfo m1 = (MethodInfo)x; MethodInfo m2 = (MethodInfo)y; InterceptorAttribute i1 = (InterceptorAttribute)m1.GetCustomAttributes(typeof(InterceptorAttribute), false)[0]; InterceptorAttribute i2 = (InterceptorAttribute)m2.GetCustomAttributes(typeof(InterceptorAttribute), false)[0]; return(i1.Index - i2.Index); }
private static void AddInterceptors(ITypedAspect aspect, IList pointcuts) { ArrayList methodsList = new ArrayList(); MethodInfo[] methods = aspect.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (MethodInfo method in methods) { object[] interceptorAttributes = method.GetCustomAttributes(typeof(InterceptorAttribute), false); if (interceptorAttributes != null && interceptorAttributes.Length > 0) { methodsList.Add(method); } } methodsList.Sort(new InterceptorMethodSorter()); foreach (MethodInfo method in methodsList) { object[] interceptorAttributes = method.GetCustomAttributes(typeof(InterceptorAttribute), false); if (interceptorAttributes != null) { InterceptorAttribute interceptor = (InterceptorAttribute)interceptorAttributes[0]; IPointcut pointcut = null; Delegate interceptorDelegate = CreateDelegate(aspect, method); if (interceptor.TargetAttribute != null) { pointcut = new AttributePointcut(interceptor.TargetAttribute, interceptorDelegate); } else if (interceptor.TargetSignature != null) { pointcut = new SignaturePointcut(interceptor.TargetSignature, interceptorDelegate); } else { throw new Exception("Interceptor attribute does not contain any target info"); } pointcuts.Add(pointcut); } } }