public ParticipantMat(MediatorMat mediator) { this.mediator = mediator; // Remove All Events/Delegates // mediator.RemoveAllEvents(mediator); mediator.Alert += Mediator_Alert; }
public void RemoveAllEvents(MediatorMat mediator) { if (mediator.GetInvocationList() != null) { foreach (var @delegate in mediator.GetInvocationList()) { mediator.RemoveEvent(@delegate); } } }
static void Main(string[] args) { var mediator = new MediatorMat(); var participant = new ParticipantMat(mediator); var participant2 = new ParticipantMat(mediator); var participant3 = new ParticipantMat(mediator); var participant4 = new ParticipantMat(mediator); // It will print 3 times, because we are excluding the object itself 'participant' and using 1 'mediator' for the 4 objects which the are using the 'mediator' byref, // so in the end it will print 3 times 'olá 10' participant.Say(10); }