// Create parser instance public static Parser Create(params string[] args) { // Init if (cash == null) { cash = new Parser(); var asm = Assembly.GetExecutingAssembly(); // Seach for all methods with Command attribute var methods = asm.GetTypes() .SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)) .Where(y => y.GetCustomAttributes().OfType <CommandAttribute>().Any()) .ToArray(); foreach (var met in methods) { var atr = (CommandAttribute)met.GetCustomAttribute(typeof(CommandAttribute)); if (atr.Path == null || atr.Path.Length == 0) { throw new Exception("Command pattern not set"); } var cmd = atr.Help != null ? new Command(atr.Path, met, atr.Help) : new Command(atr.Path, met); cash.Add(cmd); } } cash.Run(args); return(cash); }