Пример #1
0
        public int ParseArgs(string[] args, int startFrom)
        {
            int i = startFrom;

            for (; i < args.Length; i++)
            {
                foreach (ConsoleApplicationOption option in supportedOptions)
                {
                    String optionString = String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                        "{0}{1}", optionMarker, option.OptionName);

                    if (args[i].Equals(optionString, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ConsoleApplicationOption usedOption = (ConsoleApplicationOption)option.Clone();
                        usedOptions.Add(usedOption);

                        for (int j = 0; j < option.ParametersCount; j++)
                        {
                            if (i + 1 + j >= args.Length)
                            {
                                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                          "Too few arguments ('{0}').", option.OptionName));
                            }

                            // NOTE (Igor) 15.10.07: this condition prevented negative values as parameters, so I had to remove it
                            //if (args [i + 1 + j].StartsWith (optionMarker))
                            //    throw new ArgumentException (String.Format (System.Globalization.CultureInfo.InvariantCulture,
                            //        "Too few arguments ('{0}').", option.OptionName));

                            usedOption.AddParameter(args[i + 1 + j]);
                        }
                        break;
                    }
                }
            }

            return(i);
        }
Пример #2
0
 public void AddOption(ConsoleApplicationOption option)
 {
     supportedOptions.Add(option);
 }