Beispiel #1
0
        public static ArgumentDictionary ParseCommand(string[] cmd, CommandSwitch[] switches, ResourceManager resources)
        {
            ArgumentDictionary argumentDictionary = new ArgumentDictionary(cmd.Length);

            for (int i = 0; i < cmd.Length; i++)
            {
                string text  = cmd[i];
                string text2 = text;
                if (text2[0] != '/' && text2[0] != '-')
                {
                    argumentDictionary.Add(string.Empty, text2);
                }
                else
                {
                    if (text2.Length == 1)
                    {
                        throw new CommandLineArgumentException(CommandParser.GetLocalizedText(resources, "CommandArgumentsMissingSwitch", "Invalid argument: switch missing."));
                    }
                    text2 = text2.Substring(1);
                    int num = text2.IndexOfAny(new char[]
                    {
                        ':',
                        '='
                    });
                    if (num == 0)
                    {
                        throw new CommandLineArgumentException(CommandParser.GetLocalizedText(resources, "CommandArgumentsSyntax", "Invalid argument: delimeter (':' or '=') may not start switch."));
                    }
                    string value;
                    if (num == -1)
                    {
                        value = string.Empty;
                    }
                    else
                    {
                        value = text2.Substring(num + 1);
                        text2 = text2.Substring(0, num);
                    }
                    CommandSwitch commandSwitch = CommandSwitch.FindSwitch(text2.ToLower(CultureInfo.InvariantCulture), switches);
                    if (commandSwitch == null)
                    {
                        string text3 = text2.ToLower(CultureInfo.InvariantCulture);
                        throw new CommandLineArgumentException(CommandParser.GetLocalizedText(resources, "CommandArgumentsUnknownSwitch", new string[]
                        {
                            text3
                        }, string.Format("Switch /{0} is an unknown switch", new string[]
                        {
                            text3
                        })));
                    }
                    argumentDictionary.Add(commandSwitch.Name, value);
                }
            }
            return(argumentDictionary);
        }
        public bool AssignDefaults(ArgumentDictionary options)
        {
            base.VerifyRule();
            bool             flag             = false;
            StringCollection arguments        = options.GetArguments(string.Empty);
            StringCollection stringCollection = new StringCollection();

            if (arguments == null)
            {
                return(true);
            }
            foreach (string current in arguments)
            {
                if (base.Pattern.IsMatch(current))
                {
                    options.Add(base.Cswitch.Name, current);
                    stringCollection.Add(current);
                }
                else
                {
                    flag = true;
                }
            }
            foreach (string current2 in stringCollection)
            {
                arguments.Remove(current2);
            }
            return(!flag);
        }