/// <summary> /// Parses the current commandline arguments given to this process. /// </summary> /// <param name="args">Commandline args.</param> public void Parse(string[] args) { for (int i = 0; i < args.Length; i++) { string arg = args[i]; foreach (ActionDom action in _actions) { // Contains only the list of synonmous param definitions. string[] synParams = action.Argument.Split('|'); if (synParams.Any(x => x.Equals(arg, StringComparison.OrdinalIgnoreCase))) { action.IsUsed = true; XenoParseEventArgs eventArguments; if (action.RequiredExtraArgument) { if (i + 1 >= args.Length) { Console.WriteLine("[ERROR] The argument \"{0}\" requires an additional parameter.", arg); return; } string extraArgument = args[i + 1]; if (string.IsNullOrWhiteSpace(extraArgument)) { Console.WriteLine("[ERROR] The argument \"{0}\" has an invalid parameter.", arg); return; } eventArguments = new XenoParseEventArgs(args[i + 1]); } else { eventArguments = new XenoParseEventArgs(); } action.Method?.Invoke(this, eventArguments); } } } }
private static void action1(object sender, XenoParseEventArgs e) { Console.WriteLine("1st Message {0}", e.Value); }
private static void action3(object sender, XenoParseEventArgs e) { Console.WriteLine("Reading config from {0}", e.Value); }
private static void help(object sender, XenoParseEventArgs e) { // we can cast the 'sender' object and use the "GetHelp" function directly since the caller of this function passes a 'this'-reference of it's own object to the 'sender'. The cast is totally safe. Console.WriteLine(((XenoParse)sender).GetHelp()); }
private static void connect(object sender, XenoParseEventArgs e) { Console.WriteLine("Connecting to {0}", e.Value); }
private static void stunnel(object sender, XenoParseEventArgs e) { Console.WriteLine("STunnel has been activated!"); }