public Func <IAspectDefinition, IAspectExpressionBuilder> Visit(SetPropertyInterceptionAspect aspect) { return(aspectDefinition => { Func <IAspectExpression, IAspectExpression> ctor = null; var propertyAspectDefinition = aspectDefinition as IPropertyAspectDefinition; if (lastAspect.Top) { ctor = expression => { return new TopSetPropertyInterceptionAspectExpression(expression, propertyAspectDefinition); }; lastAspect = new Aspect(); } else { if (lastAspect.IsInBinding) { ctor = expression => { return new BindingSetPropertyInterceptionAspectExpression(expression, propertyAspectDefinition); }; } } lastAspect.IsInBinding = true; topAspectInScopeDefinition = aspectDefinition; return new AspectNodeExpressionBuilder(ctor); }); }
private void CollectPartialPropertyAspectDefinitionsByPropertyInterceptionAttribute(IEnumerable <IAspectPropertyMap> properties) { properties.ForEach(propertyMap => { MethodInfo method = null; var canWrite = propertyMap.ContractMember.CanWrite; var propertyInterceptionAspects = new List <IAspectDefinition>(); if (propertyMap.Target.IsNotNull()) { propertyMap.Members.ForEach(targetMember => { IEnumerable <IAspectDefinition> aspectDefinitions = null; var aspectsAttrs = targetMember.GetCustomAttributes <PropertyInterceptionAspectAttribute>().ToArray(); if (aspectsAttrs.IsNotNullOrEmpty()) { if (canWrite) { method = propertyMap.Target.GetSetMethod(); aspectDefinitions = aspectsAttrs.Select(aspectAttr => { var aspect = new SetPropertyInterceptionAspect { AspectType = aspectAttr.AspectType, AspectPriority = aspectAttr.AspectPriority, LifetimeStrategy = aspectAttr.LifetimeStrategy }; return(new SetPropertyInterceptionAspectDefinition(aspect, propertyMap.ContractType, propertyMap.ContractMember, targetMember)); }); } else { method = propertyMap.Target.GetGetMethod(); aspectDefinitions = aspectsAttrs.Select(aspectAttr => { var aspect = new GetPropertyInterceptionAspect { AspectType = aspectAttr.AspectType, AspectPriority = aspectAttr.AspectPriority, LifetimeStrategy = aspectAttr.LifetimeStrategy }; return(new GetPropertyInterceptionAspectDefinition(aspect, propertyMap.ContractType, propertyMap.ContractMember, targetMember)); }); } propertyInterceptionAspects.AddRange(aspectDefinitions); } }); AddOrUpdate(propertyMap.Target, propertyMap.ContractMember, method, propertyInterceptionAspects); } }); }
public Func<IAspectDefinition, IAspectExpressionBuilder> Visit(SetPropertyInterceptionAspect aspect) { return aspectDefinition => { Func<IAspectExpression, IAspectExpression> ctor = null; var propertyAspectDefinition = aspectDefinition as IPropertyAspectDefinition; if (lastAspect.Top) { ctor = expression => { return new TopSetPropertyInterceptionAspectExpression(expression, propertyAspectDefinition); }; lastAspect = new Aspect(); } else { if (lastAspect.IsInBinding) { ctor = expression => { return new BindingSetPropertyInterceptionAspectExpression(expression, propertyAspectDefinition); }; } } lastAspect.IsInBinding = true; topAspectInScopeDefinition = aspectDefinition; return new AspectNodeExpressionBuilder(ctor); }; }
internal SetPropertyInterceptionAspectDefinition(SetPropertyInterceptionAspect aspect, Type aspectDeclaringType, PropertyInfo property, MemberInfo target) : base(aspect, aspectDeclaringType, property, target) { this.aspect = aspect; }