/// <summary> /// Perform all necessary calls /// </summary> public virtual void Init() { EventInfo myEventBinding = SenderObject.GetType().GetEvent(SenderEvent); if (myEventBinding == null) { throw new NullReferenceException(SenderEvent); } MethodInfo mInfo = ReceiverObject.GetType().GetMethod(ReceiverMethod); if (mInfo == null) { throw new MissingMethodException(ReceiverObject.GetType().ToString(), ReceiverMethod); } try { System.Delegate del = System.Delegate.CreateDelegate(myEventBinding.EventHandlerType, ReceiverObject, mInfo); myEventBinding.AddEventHandler(SenderObject, del); } catch (Exception e) { throw new Exception( String.Format("Cannot subscribe '{0}' method on '{1}' event: {2}", ReceiverMethod, SenderEvent, e.Message), e); } }
private void AddHandler() { if ((SenderObject is null) || string.IsNullOrEmpty(EventName)) { return; } _eventInfo = SenderObject.GetType().GetEvent(EventName); if (_eventInfo is null) { return; } _handler = CreateDelegate(_eventInfo, Activate); _eventInfo.AddEventHandler(SenderObject, _handler); }