Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
                    }
                }
            }
        }