public static bool Parse(string[] args, IArgumentsParsable optionsObject) { //parses arguments and then tries to invoke OnParsed method using (var parser = new Parser(settings => { settings.CaseSensitive = false; settings.HelpWriter = Console.Out; settings.ParsingCulture = CultureInfo.InvariantCulture; settings.IgnoreUnknownArguments = true; })) { optionsObject.OnParsingArguments(); var result = parser.ParseArguments(args, optionsObject); optionsObject.OnArgumentsParsed(); return(result); } }
public static string[] GetArgs(IArgumentsParsable optionsObject, bool longNameFormat = true) { //get all properties of option attribute type var options = ReflectionUtil.GetProperties <BaseOptionAttribute>(optionsObject); if (options == null) { return(null); } //asks object to update before getting args optionsObject.OnGetArguments(); //gets the values of such properties in the object var list = new List <string>(); foreach (var option in options) { var property = (BaseOptionAttribute)option.Key; var propertyValue = option.Value.GetValue(optionsObject); list.AddRange(GetArgs(property, propertyValue, longNameFormat)); } return(list.ToArray()); }