public bool Validate(TypeMoniker parameterType, FacetMoniker moniker)
        {
            var sourceType = ExtraDataType == null
                                 ? parameterType.AssemblyQualifiedName
                                 : ExtraDataType.AssemblyQualifiedName;

            var data = moniker[sourceType, Key];

            if (data == null)
            {
                return(AllowMissing);
            }

            if ((RegularExpression == null) == (ValidValues == null))
            {
                throw new InvalidOperationException("One and only one of ValidValues or RegularExpression must be non-null");
            }

            if (ValidValues != null)
            {
                return(ValidValues.Contains(data, StringComparer.CurrentCultureIgnoreCase));
            }

            return(Regex.IsMatch(data, RegularExpression, RegexOptions.IgnoreCase));
        }
 protected override void ValidValues_CollectionReset(object sender, CollectionItemsChangedEventArgs <T> e)
 {
     if ((Value != null) && !ValidValues.Contains(Value))
     {
         Value = ValidValues.FirstOrDefault();
     }
 }
Exemplo n.º 3
0
        public string CheckUserInput(string input)
        {
            input = input.ToLower();
            if (!ValidValues.Contains(input))
            {
                input = "Error";
            }
            else
            {
                if (input.Length > 1 && input != "spock")
                {
                    input = input[0].ToString();
                }
            }

            return(input);
        }
Exemplo n.º 4
0
 public bool ValueValid(int value) => ValidValues.Contains(value);