-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectFactory.cs
28 lines (28 loc) · 907 Bytes
/
ObjectFactory.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
namespace SimpleMultithreadedAsuncHttpServer
{
static class ObjectFactory
{
private static readonly Dictionary<long, Func<RootObject>> _map = new Dictionary<long, Func<RootObject>>();
static ObjectFactory()
{
_map[0] = () => new CatServer();
_map[1] = () => new MouseServer();
_map[2] = () => new YarnServer();
}
public static RootObject Create(long Signature)
{
var creator = GetCreator(Signature);
if (creator == null)
throw new ArgumentException("Signature");
return creator();
}
private static Func<RootObject>? GetCreator(long Signature)
{
Func<RootObject> creator;
if (_map.TryGetValue(Signature, out creator))
return creator;
else
return null;
}
}
}