示例#1
0
        public ArgumentsRule(
            Func <AppliedOption, string> validate,
            IReadOnlyCollection <string> allowedValues = null,
            Func <string> defaultValue = null,
            string description         = null,
            string name = null,
            Func <ParseResult, IEnumerable <string> > suggest = null)
        {
            if (validate == null)
            {
                throw new ArgumentNullException(nameof(validate));
            }

            this.defaultValue = new Lazy <string>(defaultValue ?? (() => null));
            Description       = description;
            Name          = name;
            this.validate = validate;

            if (suggest == null)
            {
                this.suggest = result =>
                               AllowedValues.FindSuggestions(result);
            }
            else
            {
                this.suggest = result =>
                               suggest(result).ToArray()
                               .FindSuggestions(
                    result.TextToMatch());
            }

            AllowedValues = allowedValues ?? Array.Empty <string>();
        }