Esempio n. 1
0
        public bool Invoke(AspectValidationContext context, AspectValidationDelegate next)
        {
            var method        = context.Method;
            var declaringType = method.DeclaringType.GetTypeInfo();

            if (!declaringType.CanInherited())
            {
                return(false);
            }
            if (method.IsNonAspect())
            {
                return(false);
            }
            if (!method.IsVisibleAndVirtual())
            {
                if (context.StrictValidation)
                {
                    return(false);
                }
                if (!method.Attributes.HasFlag(MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final))
                {
                    return(false);
                }
            }

            return(next(context));
        }
Esempio n. 2
0
        public bool Invoke(AspectValidationContext context, AspectValidationDelegate next)
        {
            var declaringType = context.Method.DeclaringType.GetTypeInfo();

            if (IsAttributeAspect(declaringType) || IsAttributeAspect(context.Method))
            {
                return(true);
            }

            return(next(context));
        }
        public bool Validate(MethodInfo method, bool isStrictValidation)
        {
            if (method == null)
            {
                return(false);
            }

            var context = new AspectValidationContext {
                Method = method, StrictValidation = isStrictValidation
            };

            if (_aspectValidationDelegate(context))
            {
                return(true);
            }

            var declaringTypeInfo = method.DeclaringType.GetTypeInfo();

            if (!declaringTypeInfo.IsClass)
            {
                return(false);
            }

            foreach (var interfaceTypeInfo in declaringTypeInfo.GetInterfaces().Select(x => x.GetTypeInfo()))
            {
                var interfaceMethod = interfaceTypeInfo.GetMethodBySignature(new MethodSignature(method));
                if (interfaceMethod != null)
                {
                    if (Validate(interfaceMethod, isStrictValidation))
                    {
                        return(true);
                    }
                }
            }

            var baseType = declaringTypeInfo.BaseType;

            if (baseType == typeof(object) || baseType == null)
            {
                return(false);
            }

            var baseMethod = baseType.GetTypeInfo().GetMethodBySignature(new MethodSignature(method));

            return(baseMethod != null && Validate(baseMethod, isStrictValidation));
        }
        public bool Invoke(AspectValidationContext context, AspectValidationDelegate next)
        {
            if (context.StrictValidation)
            {
                var method = context.Method;
                if (_aspectConfiguration.Interceptors.Where(x => x.Predicates.Length != 0).Any(x => x.CanCreated(method)))
                {
                    return(true);
                }
                if (_aspectConfiguration.NonAspectPredicates.Any(x => x(method)))
                {
                    return(false);
                }
                if (_aspectConfiguration.Interceptors.Where(x => x.Predicates.Length == 0).Any(x => x.CanCreated(method)))
                {
                    return(true);
                }
            }

            return(next(context));
        }
Esempio n. 5
0
 public bool Invoke(AspectValidationContext context, AspectValidationDelegate next)
 {
     return(detectorCache.GetOrAdd(context, tuple => next(context)));
 }