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);
        }
Beispiel #2
0
        public void CheckRule(ArgumentDictionary options)
        {
            base.VerifyRule();
            string name = base.Cswitch.Name;

            if (!options.Contains(name))
            {
                if (this.switchRequired)
                {
                    throw new CommandLineException(this, "Switch \"" + name + "\" required but not provided");
                }
                return;
            }
            else
            {
                StringCollection arguments = options.GetArguments(name);
                if (base.Pattern.ToString() != ".*" && arguments.Count == 0)
                {
                    throw new CommandLineException(this, "Value[s] required for switch \"" + name + "\"");
                }
                if (arguments.Count > 1 && !this.multipleValuesAllowed)
                {
                    throw new CommandLineException(this, "Switch \"" + name + "\" may not be assigned multiple values");
                }
                foreach (string current in arguments)
                {
                    if (!base.Pattern.IsMatch(current))
                    {
                        throw new CommandLineException(this, string.Concat(new string[]
                        {
                            "Value \"",
                            current,
                            "\" for switch \"",
                            name,
                            "\" was invalid"
                        }));
                    }
                }
                return;
            }
        }