-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandManager.cs
More file actions
29 lines (25 loc) · 906 Bytes
/
CommandManager.cs
File metadata and controls
29 lines (25 loc) · 906 Bytes
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
namespace CommandMiddleware
{
using System;
using System.Collections.Generic;
using System.Linq;
public static class CommandManager
{
private static Dictionary<string, Command> commands = new();
public static bool TryGetCommand(string name, out Command? commandInfo) =>
commands.TryGetValue(name.ToLower(), out commandInfo);
public static void RegisterApiService(Type type, string? prefix = null)
{
foreach (var mtd in type.GetMethods()
.Where(x => x.DeclaringType != typeof(object) && !x.IsDefined(typeof(NotCommandAttribute), false))
.Reverse())
{
commands[(prefix + mtd.Name).ToLower()] = new ServiceCommand(mtd.Name, type, mtd);
}
}
public static void Register(string name, Delegate @delegate, bool? allowAnonymous = null, bool? rawResult = null)
{
commands[name.ToLower()] = new DelegateCommand(name, @delegate, allowAnonymous, rawResult);
}
}
}