示例#1
0
        public bool VisitType(TypePointcut pointcut, JoinPoint joinPoint)
        {
            ArgumentUtility.CheckNotNull("pointcut", pointcut);
            ArgumentUtility.CheckNotNull("joinPoint", joinPoint);

            return(pointcut.Type.IsAssignableFrom(joinPoint.DeclaringType));
        }
示例#2
0
        private Tuple <Predicate <FieldInfo>, IPointcut> GetTuple(ParameterInfo parameter)
        {
            Predicate <FieldInfo> mapping  = info => false;
            IPointcut             pointcut = new TruePointcut();

            var parameterType = parameter.ParameterType;

            if (parameterType == typeof(IInvocation))
            {
                return(Tuple.Create(mapping, pointcut));
            }
            if (parameterType == typeof(IContext))
            {
                return(Tuple.Create(mapping, pointcut));
            }

            var attributes = parameter.GetCustomAttributes(typeof(StrongContextAttributeBase), true).ToList();

            Assertion.IsTrue(attributes.Count == 1, "must use exactly one strong context attribute");

            var attribute = attributes.Single();

            Assertion.IsTrue(parameterType.IsByRef);
            parameterType = parameterType.GetElementType();

            if (attribute is InstanceAttribute)
            {
                mapping  = info => info.Name == "TypedInstance";
                pointcut = new TypePointcut(parameterType);
                return(Tuple.Create(mapping, pointcut));
            }

            if (attribute is ReturnValueAttribute)
            {
                mapping  = info => info.Name == "TypedReturnValue";
                pointcut = new ReturnTypePointcut(parameterType);
                return(Tuple.Create(mapping, pointcut));
            }

            var parameterAttribute = (ParameterAttribute)attribute;

            if (parameterAttribute.Index != -1)
            {
                mapping  = info => info.Name == "Arg" + parameterAttribute.Index;
                pointcut = new ArgumentIndexPointcut(parameterType, parameterAttribute.Index);
                return(Tuple.Create(mapping, pointcut));
            }

            if (!string.IsNullOrEmpty(parameterAttribute.Name))
            {
                throw new NotImplementedException();
                //pointcuts.Add (new ArgumentNamePointcut (parameter.ParameterType, parameterAttribute.Name));
                //mappings.Add (info => info.Name == parameterAttribute.)
            }

            mapping  = info => parameterType.IsAssignableFrom(info.FieldType);
            pointcut = new ArgumentPointcut(parameterType);

            return(Tuple.Create(mapping, pointcut));
        }
示例#3
0
        protected override IPointcut CreatePointcut(AspectDefinition aspect, string pointcutName)
        {
            var pointcut = aspect.AddPointcut <TypePointcut>(pointcutName);

            if (_types != null)
            {
                pointcut.WhereAny(_types.Select(t =>
                {
                    var typePointcut = new TypePointcut();
                    typePointcut.Where(td => td.IsType(t));
                    return(typePointcut);
                }).Cast <ITypePointcut>().ToArray());
            }
            return(pointcut);
        }