-
Notifications
You must be signed in to change notification settings - Fork 2
/
Methods.cs
52 lines (45 loc) · 1.33 KB
/
Methods.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using Fleck;
using ImpromptuInterface;
using Newtonsoft.Json;
using Net.DDP.Server.Interfaces;
namespace Net.DDP.Server
{
public delegate string MethodDelegate(params string[] args);
public class Methods : Dictionary<string, MethodDelegate>
{
internal Methods()
{
}
public new void Add(string name, MethodDelegate deligate)
{
if (ContainsKey(name))
{
throw new DuplicateNameException(String.Format("A method named {0} already exists.", name));
}
base.Add(name, deligate);
}
/// <summary>
/// Invokes a method from a dictionary of method deligates
/// </summary>
/// <param name="name"></param>
/// <param name="params"></param>
/// <returns></returns>
public string Call(string name, dynamic @params)
{
if (!ContainsKey(name))
{
throw new NullReferenceException(String.Format("Unable to find a method named {0}", name));
}
return this[name].Invoke(@params);
}
}
}