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)); }
public bool VisitReturnType(ReturnTypePointcut pointcut, JoinPoint joinPoint) { ArgumentUtility.CheckNotNull("pointcut", pointcut); ArgumentUtility.CheckNotNull("joinPoint", joinPoint); var method = joinPoint.Method as MethodInfo; return(method != null && pointcut.ReturnType.IsAssignableFrom(method.ReturnType)); }