-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (42 loc) · 1.19 KB
/
Copy pathProgram.cs
File metadata and controls
50 lines (42 loc) · 1.19 KB
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
using System.Reflection;
namespace Tin;
public class Program
{
public static void Main(string[] args)
{
var assembly = Assembly.GetEntryAssembly()
.GetTypes()
.Where(type => type.IsSubclassOf(typeof(CommandBase))).ToList();
foreach (var type in assembly)
{
string cmdName = args[0];
foreach (var attribute in type.GetCustomAttributes(false))
{
CommandAttribute? attr = attribute as CommandAttribute;
if (attr != null)
{
if (cmdName == attr.Name)
{
CommandBase? command = Activator.CreateInstance(type) as CommandBase;
if (command != null)
{
command.Exec(args);
}
}
}
}
}
}
}
public abstract class CommandBase
{
public virtual void Exec(string[] strParams)
{
throw new NotImplementedException();
}
}
[AttributeUsage(AttributeTargets.Class)]
public class CommandAttribute : Attribute
{
public string Name { get; set; }
}