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


C# Reflection.EventInfo类代码示例

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


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

示例1: GetHandler

		/// <summary>
		/// Gets the event handler.
		/// </summary>
		/// <param name="instance">
		/// The instance that is registering for the event notification.
		/// </param>
		/// <param name="info">
		/// Event metadata about the event.
		/// </param>
		/// <returns>
		/// The event handler.
		/// </returns>
		protected override Delegate GetHandler(object instance, EventInfo info)
		{
			MethodInfo methodMeta = ResolveHandlerMethod(
				ReflectionUtils.TypeOfOrType(instance),
				info.EventHandlerType,
				InstanceEventHandlerValue.InstanceMethodFlags);
			Delegate callback = null;
			if (methodMeta.IsStatic)
			{
				// case insensitive binding to a static method on an (irrelevant) instance
				callback = Delegate.CreateDelegate(
					info.EventHandlerType,
					methodMeta);
			}
			else
			{
				// case insensitive binding to an instance method on an instance
				callback =
					Delegate.CreateDelegate(
						info.EventHandlerType,
						instance,
						MethodName,
						true);
			}
			return callback;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:38,代码来源:InstanceEventHandlerValue.cs

示例2: EventBuilder

 public EventBuilder(TypeBuilder toType, FieldInfo objBase, EventInfo parentEvent)
     : base(toType, objBase)
 {
     ParentEvent = parentEvent;
     if (!CompareExchange.ContainsKey(ParentEvent.EventHandlerType))
         CompareExchange.TryAdd(ParentEvent.EventHandlerType, _CompareExchange.MakeGenericMethod(ParentEvent.EventHandlerType));
 }
开发者ID:ShaneGH,项目名称:Dynamox,代码行数:7,代码来源:EventBuilder.cs

示例3: RuntimeInitialize

		// ReSharper restore UnusedMember.Local

		public override void RuntimeInitialize( EventInfo eventInfo )
		{
			// An event always has a declaring type.
			Contract.Assume( eventInfo.DeclaringType != null );

			base.RuntimeInitialize( eventInfo );

			Type declaringType = eventInfo.DeclaringType;
			_declaringGenericType = declaringType.IsGenericType ? declaringType.GetGenericTypeDefinition() : declaringType;

			_addEmptyEventHandlers = new CachedDictionary<Type, Action<object>>( type =>
			{
				// Find the type in which the constructor is defined.
				// Needed since events can be private, and those wouldn't be returned otherwise, even when searching a flattened hierarchy.
				Type baseType = type.GetMatchingGenericType( _declaringGenericType );

				EventInfo runtimeEvent = baseType.GetEvents( ReflectionHelper.ClassMembers ).Where( e => e.Name == eventInfo.Name ).First();

				MethodInfo delegateInfo = DelegateHelper.MethodInfoFromDelegateType( runtimeEvent.EventHandlerType );
				ParameterExpression[] parameters = delegateInfo.GetParameters().Select( p => Expression.Parameter( p.ParameterType ) ).ToArray();
				Delegate emptyDelegate
					= Expression.Lambda( runtimeEvent.EventHandlerType, Expression.Empty(), "EmptyDelegate", true, parameters ).Compile();

				// Create the delegate which adds the empty handler to an instance.
				MethodInfo addMethod = runtimeEvent.GetAddMethod( true );
				if ( addMethod.IsPublic )
				{
					return instance => runtimeEvent.AddEventHandler( instance, emptyDelegate );
				}

				return instance => addMethod.Invoke( instance, new object[] { emptyDelegate } );
			} );
		}
开发者ID:amithasan,项目名称:Framework-Class-Library-Extension,代码行数:35,代码来源:InitializeEventHandlersAttribute.cs

示例4: RaiseEventImpl

		public static void RaiseEventImpl(object instance, EventInfo evt, object[] args)
		{
			if (evt == null)
				throw new MockException("Unable to deduce which event was specified in the parameter.");

			if (args.Length == 1
				&& (evt.EventHandlerType.IsGenericType && evt.EventHandlerType.GetGenericTypeDefinition() == typeof(EventHandler<>)
					|| evt.EventHandlerType == typeof(EventHandler)
					|| args[0] is EventArgs)
				)
			{
				args = new[] { instance, args[0] };
			}

			if (!(instance is IMockMixin))
			{
				var mockMixin = MocksRepository.GetMockMixin(instance, evt.DeclaringType);
				if (mockMixin != null)
					instance = mockMixin;
			}

			var mixin = instance as IEventsMixin;
			if (mixin != null)
			{
				mixin.RaiseEvent(evt, args);
			}
			else
			{
				MockingUtil.RaiseEventThruReflection(instance, evt, args);
			}
		}
开发者ID:BiBongNet,项目名称:JustMockLite,代码行数:31,代码来源:RaiseEventBehavior.cs

示例5: CallInfoCacheItem

 public CallInfoCacheItem(EventInfo ei)
 {
     this.Call = ei.CreateDynamicFunc();
     EI = ei;
     MI = ei.EventHandlerType.GetMethod("Invoke");
     SetParamInfo();
 }
开发者ID:scottishclaymore,项目名称:CallBox,代码行数:7,代码来源:CallInfoCacheItem.cs

示例6: EventInterceptionAspectDefinition

 internal EventInterceptionAspectDefinition(IAspect aspect, Type aspectDeclaringType, EventInfo @event, MemberInfo target)
 {
     Aspect = aspect;
     Member = @event;
     Target = target;
     AspectDeclaringType = aspectDeclaringType;
 }
开发者ID:sagifogel,项目名称:NCop,代码行数:7,代码来源:EventInterceptionAspectDefinition.cs

示例7: DependencyPropertyProxy

 public DependencyPropertyProxy(object context, PropertyInfo property, EventInfo updateEvent)
     : base(context, updateEvent, _triggerMethodInfo)
 {
     _context = context;
     _property = property;
     DetectProperty();
 }
开发者ID:snipervld,项目名称:StormXamarin,代码行数:7,代码来源:DependencyPropertyProxy.Support.cs

示例8: ReflectedEvent

 public ReflectedEvent(EventIdentifier name, EventInfo ev, Type targetType)
     : base(name, null, ev, targetType)
 {
     DeclaringName = ev.DeclaringType != targetType
         ? IdentifierFor.Event(ev, ev.DeclaringType)
         : name;
 }
开发者ID:cdrnet,项目名称:docu,代码行数:7,代码来源:ReflectedEvent.cs

示例9: DomEventInstance

        public DomEventInstance(DomNodeInstance node, EventInfo eventInfo)
        {
            Getter = new ClrFunctionInstance(node.Engine, (thisObject, arguments) => _function ?? JsValue.Null);
            Setter = new ClrFunctionInstance(node.Engine, (thisObject, arguments) =>
            {
                if (_handler != null)
                {
                    eventInfo.RemoveEventHandler(node.Value, _handler);
                    _handler = null;
                    _function = null;
                }

                if (arguments[0].Is<FunctionInstance>())
                {
                    _function = arguments[0].As<FunctionInstance>();
                    _handler = (s, ev) => 
                    {
                        var sender = s.ToJsValue(node.Context);
                        var args = ev.ToJsValue(node.Context);
                        _function.Call(sender, new [] { args });
                    };
                    eventInfo.AddEventHandler(node.Value, _handler);
                }

                return arguments[0];
            });
        }
开发者ID:AlgorithmsAreCool,项目名称:AngleSharp.Scripting,代码行数:27,代码来源:DomEventInstance.cs

示例10: DocumentedEvent

 public DocumentedEvent(Identifier name, XmlNode xml, EventInfo ev, Type targetType)
 {
     Name = name;
     Xml = xml;
     Event = ev;
     TargetType = targetType;
 }
开发者ID:jujis008,项目名称:docu,代码行数:7,代码来源:DocumentedEvent.cs

示例11: Init

        public void Init(string fullName, int flags, JsTypeFunction thisType, JsTypeFunction baseType, JsTypeFunction[] interfaces, JsTypeFunction[] typeArguments, FieldInfo[] fields, MethodInfo[] methods, ConstructorInfo[] constructors, PropertyInfo[] properties, EventInfo[] events, JsTypeFunction elementType, JsTypeFunction unconstructedType)
        {
            FullName = fullName;

            typeFlags = (TypeFlags)flags;

//            this.typeAttributes = typeAttributes;
            this.thisType = thisType;
            this.baseType = baseType;
            this.interfaces = interfaces;
            this.typeArguments = typeArguments;
            this.fields = fields ?? new FieldInfo[0];
            this.methods = methods ?? new MethodInfo[0];
            this.properties = properties ?? new PropertyInfo[0];
            this.constructors = constructors ?? new ConstructorInfo[0];
            this.events = events ?? new EventInfo[0];
            this.elementType = elementType;
            this.unconstructedType = unconstructedType;

            foreach (var field in this.fields)
                field.declaringType = this;
            foreach (var method in this.methods)
                method.declaringType = this;
            foreach (var property in this.properties)
            {
                property.declaringType = this;
                if (property.GetMethod != null)
                    property.GetMethod.declaringType = this;
                if (property.SetMethod != null)
                    property.SetMethod.declaringType = this;
            }
            foreach (var constructor in this.constructors)
                constructor.declaringType = this;
        }
开发者ID:MarkStega,项目名称:WootzJs,代码行数:34,代码来源:Type.cs

示例12: CreateProxyEventBuilder

        private EventBuilder CreateProxyEventBuilder(TypeBuilder typeBuilder, EventInfo contractEvent)
        {
            var builder = typeBuilder.DefineEvent(contractEvent.Name, contractEvent.Attributes,
                                                  contractEvent.EventHandlerType);

            return builder;
        }
开发者ID:fkalseth,项目名称:tinyaop,代码行数:7,代码来源:ProxyEventImplementationStrategy.cs

示例13: BuildPropertyProxy

        private void BuildPropertyProxy(TypeBuilder typeBuilder, EventInfo contractEvent)
        {
            var builder = CreateProxyEventBuilder(typeBuilder, contractEvent);

            BuildRemover(typeBuilder, contractEvent, builder);
            BuildAdder(typeBuilder, contractEvent, builder);
        }
开发者ID:fkalseth,项目名称:tinyaop,代码行数:7,代码来源:ProxyEventImplementationStrategy.cs

示例14: EventHookupHelper

 internal EventHookupHelper(string handlerName, EventInfo eventInfo,
     string scriptVirtualPath)
 {
     _handlerName = handlerName;
     _eventInfo = eventInfo;
     _scriptVirtualPath = scriptVirtualPath;
 }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:EventHookupHelper.cs

示例15: EventMonitor

		internal EventMonitor(IRoutedMessageHandler messageHandler, EventInfo eventInfo)
		{
			_messageHandler = messageHandler;
			_triggersToNotify = new List<IMessageTrigger>();

			EventHelper.WireEvent(messageHandler.Unwrap(), eventInfo, ChangedEventHandler);
		}
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:7,代码来源:EventMonitor.cs


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