private void CollectEventsAspectDefinitions(Type aspectDeclaringType, EventInfo contract, EventInfo target) { var addMethod = contract.GetAddMethod(); var raiseMethod = contract.GetInvokeMethod(); var removeMethod = contract.GetRemoveMethod(); var raiseMethodHash = Guid.NewGuid().GetHashCode(); var eventInterceptionAspect = target.GetCustomAttributes <EventInterceptionAspectAttribute>(); eventInterceptionAspect.ForEach(aspectAttribute => { var aspectDefinition = new EventInterceptionAspectDefinition(aspectAttribute, aspectAttribute.AspectType, contract, target); var bindingTypeReflectorBuilder = new EventBindingTypeReflectorBuilder(aspectDefinition); var addEventAspect = new AddEventFragmentInterceptionAspect { AspectType = aspectAttribute.AspectType, AspectPriority = aspectAttribute.AspectPriority, LifetimeStrategy = aspectAttribute.LifetimeStrategy }; var raiseEventAspect = new RaiseEventFragmentInterceptionAspect { AspectType = aspectAttribute.AspectType, AspectPriority = aspectAttribute.AspectPriority, LifetimeStrategy = aspectAttribute.LifetimeStrategy }; var removeEventAspect = new RemoveEventFragmentInterceptionAspect { AspectType = aspectAttribute.AspectType, AspectPriority = aspectAttribute.AspectPriority, LifetimeStrategy = aspectAttribute.LifetimeStrategy }; AddOrUpdate(contract, target, addMethod, new[] { new AddEventFragmentInterceptionAspectDefinition(bindingTypeReflectorBuilder, addEventAspect, aspectDeclaringType, contract, target) }); AddOrUpdate(raiseMethodHash, contract, target, raiseMethod, new[] { new RaiseEventFragmentInterceptionAspectDefinition(bindingTypeReflectorBuilder, raiseEventAspect, aspectDeclaringType, contract, target) }); AddOrUpdate(contract, target, removeMethod, new[] { new RemoveEventFragmentInterceptionAspectDefinition(bindingTypeReflectorBuilder, removeEventAspect, aspectDeclaringType, contract, target) }); }); }
public Func <IAspectDefinition, IAspectExpressionBuilder> Visit(AddEventFragmentInterceptionAspect aspect) { return(aspectDefinition => { Func <IAspectExpression, IAspectExpression> ctor = null; var eventAspectDefinition = (IFullEventAspectDefinition)aspectDefinition; if (lastAspect.Top) { ctor = expression => { var eventBuilder = eventAspectDefinition.EventBuilder; eventBuilder.SetAddExpression(expression); return new TopAddEventFragmentInterceptionAspectExpression(expression, eventAspectDefinition, eventBuilder); }; lastAspect = new Aspect(); } else { if (lastAspect.IsInBinding) { ctor = expression => { var eventBuilder = eventAspectDefinition.EventBuilder; eventBuilder.SetAddExpression(expression); return new BindingAddEventFragmentInterceptionAspectExpression(expression, eventAspectDefinition, eventBuilder); }; } } lastAspect.IsInBinding = true; topAspectInScopeDefinition = aspectDefinition; return new AspectNodeExpressionBuilder(ctor); }); }
public Func<IAspectDefinition, IAspectExpressionBuilder> Visit(AddEventFragmentInterceptionAspect aspect) { return aspectDefinition => { Func<IAspectExpression, IAspectExpression> ctor = null; var eventAspectDefinition = (IFullEventAspectDefinition)aspectDefinition; if (lastAspect.Top) { ctor = expression => { var eventBuilder = eventAspectDefinition.EventBuilder; eventBuilder.SetAddExpression(expression); return new TopAddEventFragmentInterceptionAspectExpression(expression, eventAspectDefinition, eventBuilder); }; lastAspect = new Aspect(); } else { if (lastAspect.IsInBinding) { ctor = expression => { var eventBuilder = eventAspectDefinition.EventBuilder; eventBuilder.SetAddExpression(expression); return new BindingAddEventFragmentInterceptionAspectExpression(expression, eventAspectDefinition, eventBuilder); }; } } lastAspect.IsInBinding = true; topAspectInScopeDefinition = aspectDefinition; return new AspectNodeExpressionBuilder(ctor); }; }
internal AddEventFragmentInterceptionAspectDefinition(IEventExpressionBuilder eventBuilder, AddEventFragmentInterceptionAspect aspect, Type aspectDeclaringType, EventInfo @event, MemberInfo target) : base(eventBuilder, aspect, aspectDeclaringType, @event, target) { Aspect = this.aspect = aspect; }