Beispiel #1
0
        public static ValidationNotification ValidateProperty <T>(T instance, Expression <Func <T, object> > property)
        {
            var context = new TContext();
            var prop    = new PropertyValidator <T, object>(property);

            return(ValidationCatalog.ValidateProperty(instance, prop.PropertyInfo.Name, null, context.SpecificationContainer));
        }
Beispiel #2
0
        private PropertyValidator <T, TProperty> registerValidator <TProperty>(Expression <Func <T, TProperty> > expression)
        {
            var propertyValidator = new PropertyValidator <T, TProperty>(expression);

            PropertyValidators.Add(propertyValidator);
            return(propertyValidator);
        }
Beispiel #3
0
 /// <summary>
 /// Defines a set of rules for a property of T as expressed in the expression parameter.  The name of the property
 /// specified in the propertyNameOverride property.  The set of rules will be enforced in order for the specification
 /// to be valid.
 /// </summary>
 /// <typeparam name="T">The type of entity being validated.</typeparam>
 /// <typeparam name="TProperty">The type of the property being validated.</typeparam>
 /// <param name="expression">Lambda expression returning the property to evaluate (i.e. "c => c.FirstName").</param>
 /// <param name="propertyNameOverride">Name of property to use in resulting error messages.</param>
 /// <returns><see cref="ActionOptionConditionBuilder&lt;T, TProperty&gt;"/></returns>
 public ActionOptionConditionBuilder <T, TProperty> Check <TProperty>(Expression <Func <T, TProperty> > expression,
                                                                      string propertyNameOverride)
 {
     lock (this)
     {
         PropertyValidator <T, TProperty> validator = registerValidator(expression);
         validator.PropertyNameOverride = propertyNameOverride;
         validator.Level = ValidationLevelType.Error;
         return(new ActionOptionConditionBuilder <T, TProperty>(validator));
     }
 }