internal virtual void HandleEvent(EventPublication publication, object sender, EventArgs args) { Delegate handler = Delegate.CreateDelegate( publication.EventHandleType, Target, methodName); handler.DynamicInvoke(sender, args); }
internal void OnEventFired(EventPublication publication, object sender, EventArgs args) { CheckInvalidPublications(); CheckInvalidSubscriptions(); foreach (var subscriber in subscribers) { subscriber.HandleEvent(publication, sender, args); } }
/// <summary> /// 注册发布者 /// </summary> private void RegisterPublication(object target, BindingFlags bindings) { foreach (var info in target.GetType().GetEvents(bindings)) { foreach (EventPublicationAttribute attr in info.GetCustomAttributes(typeof(EventPublicationAttribute), false)) { var publisher = new EventPublication(target, info.Name); var topicName = attr.Topic; EventTopic topic = Topics[topicName] ?? Topics.Add(topicName); topic.AddPublication(publisher); } } }
/// <summary> /// 移除发布者 /// </summary> internal void RemovePublication(EventPublication publisher) { EventContext.Instance.WriteTo("主题:{0} 移除发布者{1}", Name, publisher); publishers.Remove(publisher); }
/// <summary> /// 增加发布者 /// </summary> internal void AddPublication(EventPublication publisher) { EventContext.Instance.WriteTo("主题:{0} 添加发布者{1}", Name, publisher); publisher.EventFired += OnEventFired; publishers.Add(publisher); }