当前位置: 首页>>代码示例>>C#>>正文


C# EventInfo.GetInvokeMethod方法代码示例

本文整理汇总了C#中System.Reflection.EventInfo.GetInvokeMethod方法的典型用法代码示例。如果您正苦于以下问题:C# EventInfo.GetInvokeMethod方法的具体用法?C# EventInfo.GetInvokeMethod怎么用?C# EventInfo.GetInvokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.EventInfo的用法示例。


在下文中一共展示了EventInfo.GetInvokeMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateEventAspect

        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));
                }
            });
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:75,代码来源:AspectTypeValidator.cs

示例2: BindingRaiseEventAspectDecoratorWeaver

 internal BindingRaiseEventAspectDecoratorWeaver(EventInfo @event, IAspectWeavingSettings aspectWeavingSettings)
     : base(@event.GetInvokeMethod(), aspectWeavingSettings.WeavingSettings)
 {
     [email protected] = @event;
 }
开发者ID:sagifogel,项目名称:NCop,代码行数:5,代码来源:BindingRaiseEventAspectDecoratorWeaver.cs

示例3: CompositeRaiseEventMap

 public CompositeRaiseEventMap(Type contractType, Type implementationType, EventInfo contractEvent, EventInfo implementationEvent, IAspectDefinitionCollection aspectDefinitions)
     : base(contractType, implementationType, contractEvent, implementationEvent, aspectDefinitions)
 {
     FragmentMethod = contractEvent.GetInvokeMethod();
 }
开发者ID:sagifogel,项目名称:NCop,代码行数:5,代码来源:CompositeRaiseEventMap.cs


注:本文中的System.Reflection.EventInfo.GetInvokeMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。