Exemple #1
0
        /// <summary>
        /// Validates the specified value on set.
        /// </summary>
        /// <param name="value">The value.</param>
        public virtual void Validate(object value)
        {
            if (value == null)
            {
                if (!AllowNull)
                {
                    throw new PropertyValidationException("null");
                }
                return;
            }
            if (!typeof(T).IsAssignableFrom(value.GetType()))
            {
                throw new PropertyValidationException("type");
            }
            T val = OnValidate(value);

            if (PossibleValues != null && PossibleValues.Count() != 0 && PossibleValues.Count(v => v.Equals(val)) == 0)
            {
                throw new PropertyValidationException("invalid value");
            }
        }
Exemple #2
0
 /// <summary>
 /// Compares the array of possible values.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns></returns>
 private bool ComparePossibleValues(IValueSchema <T> other)
 {
     if (PossibleValues == null && other.PossibleValues == null)
     {
         return(true);
     }
     if (PossibleValues == null || other.PossibleValues == null)
     {
         return(false);
     }
     if (PossibleValues.Count() != other.PossibleValues.Count())
     {
         return(false);
     }
     for (int i = 0; i < PossibleValues.Count(); i++)
     {
         if (!AreValuesEqual(PossibleValues.ElementAt(i), other.PossibleValues.ElementAt(i)))
         {
             return(false);
         }
     }
     return(true);
 }