本文整理汇总了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;
}
示例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));
}
示例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);
}
}
示例5: CallInfoCacheItem
public CallInfoCacheItem(EventInfo ei)
{
this.Call = ei.CreateDynamicFunc();
EI = ei;
MI = ei.EventHandlerType.GetMethod("Invoke");
SetParamInfo();
}
示例6: EventInterceptionAspectDefinition
internal EventInterceptionAspectDefinition(IAspect aspect, Type aspectDeclaringType, EventInfo @event, MemberInfo target)
{
Aspect = aspect;
Member = @event;
Target = target;
AspectDeclaringType = aspectDeclaringType;
}
示例7: DependencyPropertyProxy
public DependencyPropertyProxy(object context, PropertyInfo property, EventInfo updateEvent)
: base(context, updateEvent, _triggerMethodInfo)
{
_context = context;
_property = property;
DetectProperty();
}
示例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;
}
示例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];
});
}
示例10: DocumentedEvent
public DocumentedEvent(Identifier name, XmlNode xml, EventInfo ev, Type targetType)
{
Name = name;
Xml = xml;
Event = ev;
TargetType = targetType;
}
示例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;
}
示例12: CreateProxyEventBuilder
private EventBuilder CreateProxyEventBuilder(TypeBuilder typeBuilder, EventInfo contractEvent)
{
var builder = typeBuilder.DefineEvent(contractEvent.Name, contractEvent.Attributes,
contractEvent.EventHandlerType);
return builder;
}
示例13: BuildPropertyProxy
private void BuildPropertyProxy(TypeBuilder typeBuilder, EventInfo contractEvent)
{
var builder = CreateProxyEventBuilder(typeBuilder, contractEvent);
BuildRemover(typeBuilder, contractEvent, builder);
BuildAdder(typeBuilder, contractEvent, builder);
}
示例14: EventHookupHelper
internal EventHookupHelper(string handlerName, EventInfo eventInfo,
string scriptVirtualPath)
{
_handlerName = handlerName;
_eventInfo = eventInfo;
_scriptVirtualPath = scriptVirtualPath;
}
示例15: EventMonitor
internal EventMonitor(IRoutedMessageHandler messageHandler, EventInfo eventInfo)
{
_messageHandler = messageHandler;
_triggersToNotify = new List<IMessageTrigger>();
EventHelper.WireEvent(messageHandler.Unwrap(), eventInfo, ChangedEventHandler);
}