Inheritance: IStringEnumerator
        private static bool ParseArgumentList(string[] args, object options)
        {
            bool               hadError  = false;
            OptionMap          optionMap = OptionInfo.CreateMap(options);
            IList <string>     valueList = ValueListAttribute.GetReference(options);
            ValueListAttribute vlAttr    = ValueListAttribute.GetAttribute(options);

            IStringEnumerator arguments = new StringEnumeratorEx(args);

            while (arguments.MoveNext())
            {
                string argument = arguments.Current;
                if (argument != null && argument.Length > 0)
                {
                    ArgumentParser parser = ArgumentParser.Create(argument);
                    if (parser != null)
                    {
                        ParserState result = parser.Parse(arguments, optionMap, options);
                        if ((result & ParserState.Failure) == ParserState.Failure)
                        {
                            hadError = true;
                            break;
                        }
                        if ((result & ParserState.MoveOnNextElement) == ParserState.MoveOnNextElement)
                        {
                            arguments.MoveNext();
                        }
                    }
                    else if (valueList != null)
                    {
                        if (vlAttr.MaximumElements < 0)
                        {
                            lock (valueListLock)
                            {
                                valueList.Add(argument);
                            }
                        }
                        else if (vlAttr.MaximumElements == 0)
                        {
                            hadError = true;
                            break;
                        }
                        else
                        {
                            if (vlAttr.MaximumElements > valueList.Count)
                            {
                                lock (valueListLock)
                                {
                                    valueList.Add(argument);
                                }
                            }
                            else
                            {
                                hadError = true;
                                break;
                            }
                        }
                    }
                }
            }

            hadError |= !optionMap.EnforceRules();
            return(!hadError);
        }
Esempio n. 2
0
        private bool ParseArgumentList(string[] args, object options)
        {
            bool hadError = false;
            IOptionMap optionMap = OptionInfo.CreateMap(options);
            IList<string> valueList = ValueListAttribute.GetReference(options);
            ValueListAttribute vlAttr = ValueListAttribute.GetAttribute(options);

            IStringEnumerator arguments = new StringEnumeratorEx(args);
            while (arguments.MoveNext())
            {
                string argument = arguments.Current;
                if (argument != null && argument.Length > 0)
                {
                    ArgumentParser parser = ArgumentParser.Create(argument);
                    if (parser != null)
                    {
                        ParserState result = parser.Parse(arguments, optionMap, options);
                        if ((result & ParserState.Failure) == ParserState.Failure)
                        {
                            hadError = true;
                            break;
                        }
                        if ((result & ParserState.MoveOnNextElement) == ParserState.MoveOnNextElement)
                        {
                            arguments.MoveNext();
                        }
                    }
                    else if (valueList != null)
                    {
                        if (vlAttr.MaximumElements < 0)
                        {
                            lock (valueListLock)
                            {
                                valueList.Add(argument);
                            }
                        }
                        else if (vlAttr.MaximumElements == 0)
                        {
                            hadError = true;
                            break;
                        }
                        else
                        {
                            if (vlAttr.MaximumElements > valueList.Count)
                            {
                                lock (valueListLock)
                                {
                                    valueList.Add(argument);
                                }
                            }
                            else
                            {
                                hadError = true;
                                break;
                            }
                        }
                    }
                }
            }

            hadError |= !optionMap.EnforceRules();
            return !hadError;
        }