本文整理汇总了C#中System.Reflection.EventInfo.RemoveEventHandler方法的典型用法代码示例。如果您正苦于以下问题:C# EventInfo.RemoveEventHandler方法的具体用法?C# EventInfo.RemoveEventHandler怎么用?C# EventInfo.RemoveEventHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.EventInfo
的用法示例。
在下文中一共展示了EventInfo.RemoveEventHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnwireEvent
/// <summary>
/// Unwires the event.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="event">The event.</param>
/// <param name="handler">The handler.</param>
public static void UnwireEvent(object sender, EventInfo @event, Action<object, EventArgs> handler)
{
@event.RemoveEventHandler(
sender,
Delegate.CreateDelegate(@event.EventHandlerType, handler.Target, handler.Method)
);
}
示例2: 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];
});
}
示例3: TestProperty
/// <summary>
///
/// </summary>
/// <param name="instance"></param>
/// <param name="property"></param>
/// <param name="eventInfo"></param>
/// <param name="value0">Initial value</param>
/// <param name="value1">Changed value</param>
private static void TestProperty(object instance,PropertyInfo property, EventInfo eventInfo, object value0, object value1)
{
var eventTriggerCount = 0;
var keepAliveHandler = true;
object oldValue = null;
object newValue = null;
var handler = new PropertyChanged(
(o, name, value, nValue) =>
{
eventTriggerCount++;
oldValue = value;
newValue = nValue;
return keepAliveHandler;
});
property.SetValue(instance,value0);
Assert.AreEqual(value0,property.GetValue(instance));
Assert.AreEqual(0,eventTriggerCount);
eventInfo.AddEventHandler(instance, handler);
property.SetValue(instance,value1);
Assert.AreEqual(value1,property.GetValue(instance));
Assert.AreEqual(1,eventTriggerCount);
Assert.AreEqual(value0, oldValue);
Assert.AreEqual(value1, newValue);
property.SetValue(instance,value1); //same value should not be triggered
Assert.AreEqual(value1,property.GetValue(instance));
Assert.AreEqual(1,eventTriggerCount);
eventInfo.RemoveEventHandler(instance, handler);
property.SetValue(instance,value0); //handler should not be triggered
Assert.AreEqual(value0,property.GetValue(instance));
Assert.AreEqual(1,eventTriggerCount);
eventInfo.AddEventHandler(instance, handler);
keepAliveHandler = false; //event should be removed after next trigger
property.SetValue(instance,value1); //test event self remove from return false
Assert.AreEqual(value1,property.GetValue(instance));
Assert.AreEqual(2,eventTriggerCount);
Assert.AreEqual(value0, oldValue);
Assert.AreEqual(value1, newValue);
property.SetValue(instance,value0); //should not trigger handler
Assert.AreEqual(value0,property.GetValue(instance));
Assert.AreEqual(2,eventTriggerCount);
}
示例4: detachEventHandler
private void detachEventHandler(EventInfo @event, Delegate d, object realButton)
{
@event.RemoveEventHandler(realButton, d);
}
示例5: UnhookEvent
/// <summary>
/// Given an EventInfo for an event of the target instance's class, unhook it
/// </summary>
private void UnhookEvent(EventInfo eventInfo)
{
if (TheTarget != null && IsHookedEvent(eventInfo.Name))
{
eventInfo.RemoveEventHandler(TheTarget, m_hooks[eventInfo.Name]);
m_hooks.Remove(eventInfo.Name);
}
}