public static FluentAspectOptions UseInterceptorResolver(this FluentAspectOptions options,
                                                                 IInterceptorResolver resolver)
        {
            if (null == resolver)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            options.InterceptorResolver = resolver;
            return(options);
        }
예제 #2
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)));
        }
예제 #3
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()));
        }
예제 #4
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>();
 }
        public static FluentAspectOptions NoInterceptMethod <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.NoInterceptMethod(expression.Compile()));
        }
        public static FluentAspectOptions NoInterceptPropertyGetter <T>(this FluentAspectOptions options,
                                                                        Expression <Func <T, object> > expression)
        {
            var prop = expression.GetProperty();

            if (null == prop)
            {
                throw new InvalidOperationException("no property found");
            }
            if (!prop.CanRead)
            {
                throw new InvalidOperationException($"the property {prop.Name} can not read");
            }
            return(options.NoInterceptMethod <T>(prop.GetMethod));
        }
        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 Intercept(this FluentAspectOptions options,
                                                           Func <IInvocation, bool> predict)
        {
            if (null == predict)
            {
                throw new ArgumentNullException(nameof(predict));
            }

            if (options.InterceptionConfigurations.TryGetValue
                    (predict, out var interceptionConfiguration))
            {
                return(interceptionConfiguration);
            }

            interceptionConfiguration = new InterceptionConfiguration();
            options.InterceptionConfigurations[predict] = interceptionConfiguration;
            return(interceptionConfiguration);
        }
예제 #9
0
 public static FluentAspectOptions WithEnricher <TEnricher>(this FluentAspectOptions options, TEnricher enricher) where TEnricher : IInvocationEnricher
 {
     options.Enrichers.Add(enricher);
     return(options);
 }
예제 #10
0
 public static FluentAspectOptions WithEnricher <TEnricher>(this FluentAspectOptions options) where TEnricher : IInvocationEnricher, new()
 {
     options.Enrichers.Add(new TEnricher());
     return(options);
 }
예제 #11
0
 public static FluentAspectOptions WithProperty(this FluentAspectOptions options, string propertyName,
                                                Func <IInvocation, object> propertyValueFactory, bool overwrite = false)
 {
     options.Enrichers.Add(new PropertyInvocationEnricher(propertyName, propertyValueFactory, overwrite));
     return(options);
 }
예제 #12
0
 public static FluentAspectOptions UseProxyFactory <TProxyFactory>(this FluentAspectOptions options,
                                                                   params object[] parameters) where TProxyFactory : class, IProxyFactory, new()
 {
     options.ProxyFactory = ActivatorHelper.CreateInstance <TProxyFactory>(parameters);
     return(options);
 }
예제 #13
0
 public static FluentAspectOptions UseProxyFactory <TProxyFactory>(this FluentAspectOptions options)
     where TProxyFactory : class, IProxyFactory, new()
 {
     options.ProxyFactory = new TProxyFactory();
     return(options);
 }
예제 #14
0
 public static FluentAspectOptions UseProxyFactory(this FluentAspectOptions options, IProxyFactory proxyFactory)
 {
     options.ProxyFactory = proxyFactory;
     return(options);
 }
예제 #15
0
 public static FluentAspectOptions UseInterceptorResolver <TResolver>(this FluentAspectOptions options)
     where TResolver : IInterceptorResolver, new()
 {
     options.InterceptorResolver = new TResolver();
     return(options);
 }
예제 #16
0
 public static IInterceptionConfiguration InterceptAll(this FluentAspectOptions options)
 => options.Intercept(m => true);
예제 #17
0
 public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options,
                                                              Expression <Func <T, object> > method)
 {
     return(options.InterceptMethod <T>(method.GetMethodExpression()));
 }
예제 #18
0
 public static FluentAspectOptions NoInterceptMethod <T>(this FluentAspectOptions options,
                                                         Expression <Action <T> > method)
 {
     options.NoInterceptMethod <T>(method.GetMethodExpression());
     return(options);
 }
예제 #19
0
 public static bool NoIntercept(this FluentAspectOptions options, Func <IInvocation, bool> predict)
 {
     return(options.NoInterceptionConfigurations.Add(predict));
 }
예제 #20
0
 public static IInterceptionConfiguration InterceptMethod(this FluentAspectOptions options,
                                                          Func <MethodInfo, bool> methodPredict)
 {
     return(options.Intercept(invocation => methodPredict(invocation.Method ?? invocation.ProxyMethod)));
 }
예제 #21
0
 public static IInterceptionConfiguration InterceptType <T>(this FluentAspectOptions options)
 {
     return(options.InterceptMethod(m => m.DeclaringType.IsAssignableTo <T>()));
 }
예제 #22
0
 public static FluentAspectOptions NoInterceptType <T>(this FluentAspectOptions options)
 {
     options.NoInterceptMethod(m => m.DeclaringType.IsAssignableTo <T>());
     return(options);
 }
예제 #23
0
 public static FluentAspectOptions NoInterceptMethod(this FluentAspectOptions options,
                                                     Func <MethodInfo, bool> methodPredict)
 {
     options.NoIntercept(invocation => methodPredict(invocation.Method ?? invocation.ProxyMethod));
     return(options);
 }