public int Subscribe(IBusMember subscriber) { if (!HandlerExistsFor(subscriber.GetType())) { throw new ArgumentException(nameof(subscriber), "The argument have no handler"); } if (handlers.FindAll(obj => obj.Instant == subscriber).Count > 0) { return(subscriber.ID); } var handerlist = subscriber.GetType().GetMethods().Where(obj => obj.Name == "Handle").ToList(); foreach (MethodInfo handler in handerlist) { handlers.Add(new Handler(subscriber, handler)); } busMembers.Add(subscriber); return(busMembers.FindIndex(obj => obj == subscriber)); }
public void Unsubscribe(IBusMember subscriber) { handlers.RemoveAll(obj => obj.Instant == subscriber); busMembers.RemoveAll(obj => obj == subscriber); }
public Message(IBusMember sender, int receiverID) { SenderID = sender.ID; ReceiverID = receiverID; }