コード例 #1
0
 public static IInterceptionConfiguration InterceptType(this FluentAspectOptions options, Func <Type, bool> typesFilter)
 {
     if (null == typesFilter)
     {
         throw new ArgumentNullException(nameof(typesFilter));
     }
     return(options.InterceptMethod(m => typesFilter(m.DeclaringType)));
 }
コード例 #2
0
        public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options,
                                                                     Expression <Func <MethodInfo, bool> > andExpression)
        {
            Expression <Func <MethodInfo, bool> > expression = m => m.DeclaringType !.IsAssignableTo <T>();

            expression = expression.And(Guard.NotNull(andExpression, nameof(andExpression)));
            return(options.InterceptMethod(expression.Compile()));
        }
コード例 #3
0
 static FluentAspects()
 {
     AspectOptions = new FluentAspectOptions();
     // register built-in necessary interceptors
     AspectOptions.InterceptAll()
     .With <TryInvokeInterceptor>();
     AspectOptions.InterceptMethod <IDisposable>(m => m.Dispose())
     .With <DisposableInterceptor>();
 }
コード例 #4
0
        public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options,
                                                                     Expression <Func <MethodInfo, bool> > andExpression)
        {
            Expression <Func <MethodInfo, bool> > expression = m => m.DeclaringType.IsAssignableTo <T>();

            if (null != andExpression)
            {
                expression = expression.And(andExpression);
            }
            return(options.InterceptMethod(expression.Compile()));
        }
コード例 #5
0
        public static IInterceptionConfiguration InterceptMethod(this FluentAspectOptions options,
                                                                 MethodInfo method)
        {
            if (null == method)
            {
                throw new ArgumentNullException(nameof(method));
            }
            var methodSignature = method.GetSignature();

            return(options.InterceptMethod(m => m.GetSignature().Equals(methodSignature)));
        }
コード例 #6
0
 static FluentAspects()
 {
     AspectOptions = new FluentAspectOptions();
     // register built-in ignore interceptors
     AspectOptions
     .NoInterceptType(t => t.Namespace?.StartsWith("WeihanLi.Common.Aspect") == true)
     ;
     // register built-in necessary interceptors
     AspectOptions.InterceptAll()
     .With <TryInvokeInterceptor>();
     AspectOptions.InterceptMethod <IDisposable>(m => m.Dispose())
     .With <DisposableInterceptor>();
 }
コード例 #7
0
        public static IInterceptionConfiguration InterceptPropertySetter <T>(this FluentAspectOptions options,
                                                                             Expression <Func <T, object> > expression)
        {
            var prop = expression.GetProperty();

            if (null == prop)
            {
                throw new InvalidOperationException("no property found");
            }
            if (!prop.CanWrite)
            {
                throw new InvalidOperationException($"the property {prop.Name} can not write");
            }
            return(options.InterceptMethod <T>(prop.SetMethod));
        }
コード例 #8
0
        public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options,
                                                                     MethodCallExpression methodCallExpression)
        {
            var innerMethod = methodCallExpression?.Method;

            if (null == innerMethod)
            {
                throw new InvalidOperationException($"no method found");
            }
            Expression <Func <MethodInfo, bool> > expression = m => m.DeclaringType.IsAssignableTo <T>();
            var methodSignature = innerMethod.GetSignature();

            expression = expression.And(m => m.GetSignature().Equals(methodSignature));
            return(options.InterceptMethod(expression.Compile()));
        }
コード例 #9
0
 public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options,
                                                              Expression <Func <T, object> > method)
 {
     return(options.InterceptMethod <T>(method.GetMethodExpression()));
 }
コード例 #10
0
 public static IInterceptionConfiguration InterceptType <T>(this FluentAspectOptions options)
 {
     return(options.InterceptMethod(m => m.DeclaringType.IsAssignableTo <T>()));
 }