I have a simple .NET application that runs as a Windows service. Say he has one class
MyClass { Run(Destination d) Walk(Destination d) Wash(Dishes d) }
I want to create a console application where I would type simple humanoid commands like
run left walk right
Pretty similar to what you do in the Windows console. I wonder what is the best way to implement this mapping. Direct methods, of course, create their own line parser with a lot of switch statements, but I think if there is a better and faster method.
, , , , , , :
[ScriptableClass] public class MyClass { [ScriptableMethod(typeof (Destination),typeof(int))] public void Run (Destination f, int distance) {} }
, ScriptableClass. , , ScriptableMethod, ( ). "MyClass.Run", . , / .
, , .
:
, approrpiate .
, Run(). , .
Run()
UPDATE: Aggreed, (. Guffa). - , IMHO.
. , , , , .
, .:
var methods = new Dictionary<string, Action<int>>(); methods.Add("run", n => MyClass.Run(n)); methods.Add("walk", n => MyClass.Walk(n)); methods.Add("wash", n => MyClass.Wash(n)); string cmd = "run"; int param = 42; if (methods.ContainsKey(cmd)) { methods[cmd](param); } else { Console.WriteLine('Say what, human?'); }
Perhaps PowerShell CommandLet will be an option, although it will limit you or your PowerShell users (which is an excellent IMO shell).