コード例 #1
0
        /// <summary>
        /// Parse the array of command line arguments.
        /// </summary>
        /// <param name="args">The array of command line arguments.</param>
        public void Parse(string[] args)
        {
            _ParsedArguments.Clear();
            List <string> arguments = args.ToList();

            Argument lastArgumentWithPrefix = null;

            for (int i = 0; i < arguments.Count; i++)
            {
                string currentValue = arguments[i];
                string parameter;

                if (GetArgumentNameWithoutPrefix(ref currentValue, out parameter))
                {
                    if (!string.IsNullOrEmpty(parameter))
                    {
                        arguments.Insert(i + 1, parameter);
                    }

                    lastArgumentWithPrefix = BuildArgument(currentValue, true);

                    ParsedArguments.Add(lastArgumentWithPrefix);
                }
                else
                {
                    bool addArgument = !string.IsNullOrEmpty(currentValue);

                    if (lastArgumentWithPrefix != null)
                    {
                        if (lastArgumentWithPrefix.ArgumentValue != ArgumentValue.None)
                        {
                            addArgument = false;
                            lastArgumentWithPrefix.Value = currentValue;

                            SetArgumentIsValid(lastArgumentWithPrefix);
                        }

                        lastArgumentWithPrefix = null;
                    }

                    if (addArgument)
                    {
                        ParsedArguments.Add(BuildArgument(currentValue, false));
                    }
                }
            }
        }