private bool TryParseArgument(string[] args, ref int index, ArgDescr arg, T options) { var type = arg.Property.PropertyType; if (type == typeof(string)) { var argIndex = arg.IsDefault ? index++ : ++index; arg.Property.SetValue(options, args[argIndex], null); } else if (type == typeof(bool)) { arg.Property.SetValue(options, true, null); } else { this.ErrorMessage = "Unknown command line argument type [" + type.FullName + "]"; return(false); } return(true); }
static CommandLineAnalyzer() { foreach (var prop in typeof(T).GetProperties()) { var attribs = prop.GetCustomAttributes(typeof(DefaultArgAttribute), false); if (attribs != null && attribs.Length > 0) { _defaultArgsList.Insert(((DefaultArgAttribute)attribs[0]).Order, new ArgDescr(prop)); } else { var descr = new ArgDescr(prop, false); _optionalArgs.Add(descr.Key, descr); _optionalArgsList.Add(descr); if (descr.Alias != null) { _optionalArgs.Add(descr.Alias, descr); } } } }