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);
        }
        public override ParserState Parse(IStringEnumerator argumentEnumerator, OptionMap map, object options)
        {
            IStringEnumerator group = new CharEnumeratorEx(argumentEnumerator.Current.Substring(1));

            while (group.MoveNext())
            {
                OptionInfo option = map[group.Current];
                if (option == null)
                {
                    return(ParserState.Failure);
                }

                option.IsDefined = true;

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && group.IsLast)
                    {
                        return(ParserState.Failure);
                    }

                    if (!group.IsLast)
                    {
                        if (option.SetValue(group.GetRemainingFromNext(), options))
                        {
                            return(ParserState.Success);
                        }
                        else
                        {
                            return(ParserState.Failure);
                        }
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return(ParserState.Failure);
                    }
                    else
                    {
                        if (option.SetValue(argumentEnumerator.Next, options))
                        {
                            return(ParserState.Success | ParserState.MoveOnNextElement);
                        }
                        else
                        {
                            return(ParserState.Failure);
                        }
                    }
                }
                else
                {
                    if (!group.IsLast && map[group.Next] == null)
                    {
                        return(ParserState.Failure);
                    }
                    if (!option.SetValue(true, options))
                    {
                        return(ParserState.Failure);
                    }
                }
            }
            return(ParserState.Success);
        }
        public override ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            innerParser = new OptionGroupParser(switchLength);

            var parts = argumentEnumerator.Current.Substring(switchLength).Split(new char[] { '=' }, 2);
            if(parts[0].Length > 1)
            {
                var option = map[parts[0]];
                if (option != null) innerParser = new LongOptionParser(switchLength);
            }

            return innerParser.Parse(argumentEnumerator, map, options);
        }