public static void ValidateEventAspect(IAspect aspect, EventInfo @event) { var comparedTypes = Type.EmptyTypes; var invokeMethod = @event.GetInvokeMethod(); var methodIsFunction = invokeMethod.IsFunction(); var methodParameters = invokeMethod.GetParameters(); var overridenMethods = aspect.AspectType .GetOverridenMethods() .ToArray(overridenMethod => { return overridenMethod.Name.Equals("OnAddHandler") || overridenMethod.Name.Equals("OnInvokeHandler") || overridenMethod.Name.Equals("OnRemoveHandler"); }); if (!typeof(IEventInterceptionAspect).IsAssignableFrom(aspect.AspectType)) { var argumentException = new ArgumentException(Resources.EventInterceptionAspectAttributeErrorInitialization, "aspectType"); throw new AspectAnnotationException(argumentException); } if (overridenMethods.Length == 0) { throw new AdviceNotFoundException(aspect.GetType()); } overridenMethods.ForEach(overridenMethod => { Type argumentsType = null; var eventName = @event.Name; Type[] genericArguments = null; var aspectParameters = overridenMethod.GetParameters(); var aspectMethodIsFunction = overridenMethod.IsFunction(); if (aspectParameters.Length != 1 || aspectMethodIsFunction) { throw new AspectTypeMismatchException(Resources.AspectEventParametersMismatach.Fmt(eventName)); } argumentsType = aspectParameters[0].ParameterType; genericArguments = argumentsType.GetGenericArguments(); if (methodIsFunction) { var argumentsLength = 0; Type aspectReturnType = null; if (typeof(IEventActionInterceptionArgs).IsAssignableFrom(argumentsType)) { throw new AspectAnnotationException(Resources.EventActionInterceptionAspcetMismatch); } if (genericArguments.Length == 0) { throw new AspectTypeMismatchException(Resources.AspectReturnTypeMismatch.Fmt(eventName)); } argumentsLength = genericArguments.Length - 1; aspectReturnType = genericArguments[argumentsLength]; if (genericArguments.Length > 1) { comparedTypes = genericArguments.Take(argumentsLength) .ToArray(); } if (!ValidateTypesAreEqual(invokeMethod.ReturnType, aspectReturnType)) { throw new AspectTypeMismatchException(Resources.AspectReturnTypeMismatch.Fmt(eventName)); } } else { comparedTypes = genericArguments; if (typeof(IEventFunctionInterceptionArgs).IsAssignableFrom(argumentsType)) { throw new AspectAnnotationException(Resources.EventActionInterceptionAspcetMismatch); } } if (!ValidateParameters(methodParameters, comparedTypes)) { throw new AspectTypeMismatchException(Resources.AspectEventParametersMismatach.Fmt(eventName)); } }); }
internal BindingRaiseEventAspectDecoratorWeaver(EventInfo @event, IAspectWeavingSettings aspectWeavingSettings) : base(@event.GetInvokeMethod(), aspectWeavingSettings.WeavingSettings) { this.@event = @event; }
public CompositeRaiseEventMap(Type contractType, Type implementationType, EventInfo contractEvent, EventInfo implementationEvent, IAspectDefinitionCollection aspectDefinitions) : base(contractType, implementationType, contractEvent, implementationEvent, aspectDefinitions) { FragmentMethod = contractEvent.GetInvokeMethod(); }