public Action Add(object sender, Action localDelegate, EventQueueMode mode = EventQueueMode.Synchronous) { var key = new EventHandlerKey(localDelegate, sender); Action ourDelegate = () => OnRemoteInvoked(key, new object[0]); return(AddInternal <Action>(key, mode, sender, localDelegate, ourDelegate)); }
// Add custom methods public TDelegateType AddInternal <TDelegateType>( EventHandlerKey key, EventQueueMode mode, object sender, Delegate localDelegate, Delegate ourDelegate) { Assert.IsNotNull(localDelegate); HandlerInfo handler; if (_handlers.TryGetValue(key, out handler)) { Assert.IsEqual(mode, handler.Mode, "Cannot use the same event handler method with multiple different EventQueueMode's"); handler.UsageCount++; return((TDelegateType)(object)handler.OurDelegate); } _handlers.Add(key, new HandlerInfo() { UsageCount = 1, Key = key, Mode = mode, OurDelegate = ourDelegate, DelegateType = typeof(TDelegateType), LocalDelegate = localDelegate, }); return((TDelegateType)(object)ourDelegate); }
public Action <TParam1, TParam2, TParam3> Add <TParam1, TParam2, TParam3>( object sender, Action <TParam1, TParam2, TParam3> localDelegate, EventQueueMode mode) { var key = new EventHandlerKey(localDelegate, sender); Action <TParam1, TParam2, TParam3> ourDelegate = (TParam1 param1, TParam2 param2, TParam3 param3) => OnRemoteInvoked(key, new object[] { param1, param2, param3 }); return(AddInternal <Action <TParam1, TParam2, TParam3> >(key, mode, sender, localDelegate, ourDelegate)); }
// We could make this public but there's only two queue modes // that make sense so it's easier this way void TriggerOneOff(Action localDelegate, EventQueueMode mode) { var key = new EventHandlerKey(localDelegate, null); if (_handlers.ContainsKey(key)) { // Already queued return; } _handlers.Add(key, new HandlerInfo() { UsageCount = 1, Key = key, Mode = mode, IsOneOff = true, DelegateType = typeof(Action), LocalDelegate = localDelegate, }); OnRemoteInvoked(key, new object[0]); }
public Action <TParam1, TParam2, TParam3, TParam4> Add <TParam1, TParam2, TParam3, TParam4>( Action <TParam1, TParam2, TParam3, TParam4> localDelegate, EventQueueMode mode) { return(Add <TParam1, TParam2, TParam3, TParam4>(null, localDelegate, mode)); }
// Zero parameters public Action Add(Action localDelegate, EventQueueMode mode = EventQueueMode.Synchronous) { return(Add(null, localDelegate, mode)); }