-
Notifications
You must be signed in to change notification settings - Fork 3
/
Multiplexor.cs
37 lines (30 loc) · 936 Bytes
/
Multiplexor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Collections.Generic;
using System.Linq;
namespace ClassLibrary4
{
public class Multiplexor<T> : Handles<T> where T : Message
{
private List<Handles<T>> handlers;
public Multiplexor(params Handles<T>[] handlers)
{
this.handlers = handlers.ToList();
}
#region Handles<T> Members
public void Handle(T message)
{
handlers.ForEach(handler => handler.Handle(message));
}
#endregion
public void Add(Handles<T> handler)
{
var handlersLocal = new List<Handles<T>>(handlers) {handler};
handlers = handlersLocal;
}
public void Remove(Handles<T> handler)
{
var handlersLocal = new List<Handles<T>>(handlers);
handlersLocal.Remove(handler);
handlers = handlersLocal;
}
}
}