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)));
 }
        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()));
        }
Ejemplo n.º 3
0
 static FluentAspects()
 {
     AspectOptions = new FluentAspectOptions();
     // register built-in necessary interceptors
     AspectOptions.InterceptAll()
     .With <TryInvokeInterceptor>();
     AspectOptions.InterceptMethod <IDisposable>(m => m.Dispose())
     .With <DisposableInterceptor>();
 }
        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()));
        }
        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)));
        }
Ejemplo n.º 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>();
 }
        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));
        }
        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()));
        }
Ejemplo n.º 9
0
 public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options,
                                                              Expression <Func <T, object> > method)
 {
     return(options.InterceptMethod <T>(method.GetMethodExpression()));
 }
Ejemplo n.º 10
0
 public static IInterceptionConfiguration InterceptType <T>(this FluentAspectOptions options)
 {
     return(options.InterceptMethod(m => m.DeclaringType.IsAssignableTo <T>()));
 }