• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Reflection.EventInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: CLSEvent

 internal CLSEvent(String name, Type type, EventInfo eventInfo, Boolean isStatic)
 {
     this.isStatic = isStatic;
     this.eventInfo = eventInfo;
     this.type = type;
     this.name = name;
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:7,代码来源:CLSEvent.cs


示例17: RemoveEventDecoratorWeaver

 public RemoveEventDecoratorWeaver(IEventTypeBuilder eventTypeBuilder, EventInfo @event, IWeavingSettings weavingSettings)
     : base(@event.GetRemoveMethod(), weavingSettings)
 {
     MethodEndWeaver = new MethodEndWeaver();
     MethodScopeWeaver = new RemoveEventDecoratorScopeWeaver(method, weavingSettings);
     MethodDefintionWeaver = new RemoveEventMethodSignatureWeaver(eventTypeBuilder, weavingSettings.TypeDefinition);
 }
开发者ID:sagifogel,项目名称:NCop,代码行数:7,代码来源:RemoveEventDecoratorWeaver.cs


示例18: ArtificialType

        /// <summary>
        /// 
        /// </summary>
        /// <param name="namespace"></param>
        /// <param name="name"></param>
        /// <param name="isGenericType"></param>
        /// <param name="basetype"></param>
        /// <param name="isValueType"></param>
        /// <param name="isByRef"></param>
        /// <param name="isEnum"></param>
        /// <param name="isPointer"></param>
        /// <param name="ElementType">
        /// Type of the object encompassed or referred to by the current array, pointer or reference type. It's what GetElementType() will return.
        /// Specify null when it is not needed
        /// </param>
        public ArtificialType(string @namespace, string name, bool isGenericType, Type basetype, 
                              bool isValueType, bool isByRef, bool isEnum, bool isPointer, Type ElementType,
                              bool isInterface,
                              bool isAbstract,
                              Type MReturnSynType
                            )
        {
            _Name = name;
            _Namespace = @namespace;
            _IsGenericType = isGenericType;
            _BaseType = basetype;
            _IsValueType = isValueType;
            _IsByRef = isByRef;
            _IsEnum = isEnum;
            _IsPointer = isPointer;
            _IsInterface = isInterface;
            _IsAbstract = isAbstract;


            _Method1 = new ArtificialMethodInfo("M", this, typeof(int[]), MethodAttributes.Public | (_IsAbstract ? MethodAttributes.PrivateScope | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.Abstract : MethodAttributes.Static), null, false);
            _Method2 = new ArtificialMethodInfo("RaiseEvent1", this, typeof(void), MethodAttributes.Public | (_IsAbstract ? MethodAttributes.Abstract : 0), null, false);
            _Method3 = new ArtificialMethodInfo("M1", this, this, MethodAttributes.Public | MethodAttributes.Static | (_IsAbstract ? MethodAttributes.Abstract : 0), new[] { new ArtificialParamInfo("x1", basetype, false) }, false);
            _Method4 = new ArtificialMethodInfo("M2", this, this, MethodAttributes.Public | MethodAttributes.Static | (_IsAbstract ? MethodAttributes.Abstract : 0), new[] { new ArtificialParamInfo("y1", this, false) }, false);

            _Property1 = new ArtificialPropertyInfo("StaticProp1", this, typeof(decimal), true, false);
            _Property2 = new ArtificialPropertyInfo("StaticProp2", this, typeof(System.Tuple<int, int, int, int, int, int, int, System.Tuple<int, int, int>>), true, false);
            _Property3 = new ArtificialPropertyInfo("StaticProp3", this, typeof(System.Tuple<int, int, int>), true, false);
            _Event1 = new ArtificalEventInfo("Event1", this, typeof(EventHandler));
            _Ctor1 = new ArtificialConstructorInfo(this, new ParameterInfo[] {} );  // parameter-less ctor
            _ElementType = ElementType;
        }
开发者ID:xenocons,项目名称:visualfsharp,代码行数:46,代码来源:ArtificialType.cs


示例19: WriteExtensionMethod

        private static void WriteExtensionMethod(Type type, EventInfo eventInfo, StringBuilder builder, SortedSet<string> usingNamespaces)
        {
            var eventType = eventInfo.EventHandlerType.Name; // e.g. MouseEventHandler
            var eventName = eventInfo.Name; // e.g. MouseMove
            var eventArgs = eventInfo.EventHandlerType.GetMethod("Invoke").GetParameters()[1].ParameterType; // e.g. MouseEventArgs

            // TODO: Is event args ever generic? Might need to cope with that

            if (eventInfo.EventHandlerType.IsGenericType)
            {
                switch (eventInfo.EventHandlerType.Name)
                {
                    case "ReturnEventHandler`1":
                        eventType = string.Format("ReturnEventHandler<{0}>", eventArgs.Name);
                        break;
                    case "RoutedPropertyChangedEventHandler`1":
                        eventType = string.Format("RoutedPropertyChangedEventHandler<{0}>", eventArgs.Name);
                        break;
                    case "EventHandler`1":
                        eventType = string.Format("EventHandler<{0}>", eventArgs.Name);
                        break;
                    default:
                        throw new Exception("Can't cope with other generic types");
                }
            }

            usingNamespaces.Add(eventInfo.EventHandlerType.Namespace);
            usingNamespaces.Add(eventArgs.Namespace);

            builder.AppendLine(string.Format("\t\tpublic static IObservable<EventPattern<{0}>> {1}Observer(this {2} This)", eventArgs.Name, eventName, type.Name));
            builder.AppendLine("\t\t{");
            builder.AppendLine(string.Format("\t\t\treturn Observable.FromEventPattern<{0}, {1}>(h => This.{2} += h, h => This.{2} -= h);", eventType, eventArgs.Name, eventName));
            builder.AppendLine("\t\t}");
        }
开发者ID:WilkaH,项目名称:EventToObservableReflection,代码行数:34,代码来源:Program.cs


示例20: ScriptObjectEventInfo

		public ScriptObjectEventInfo (string name, ScriptObject callback, EventInfo ei)
		{
			Name = name;
			Callback = callback;
			EventInfo = ei;
			NativeMethods.html_object_retain (PluginHost.Handle, Callback.Handle);
		}
开发者ID:snorp,项目名称:moon,代码行数:7,代码来源:ScriptObjectEventInfo.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Reflection.FieldInfo类代码示例发布时间:2022-05-26
下一篇:
C# Reflection.CustomAttributeData类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap