public override EntityValidationResult Validate(object value, EntityValidationContext entityValidationContext) { if (entityValidationContext == null) { throw new ArgumentNullException("entityValidationContext", "EntityValidationContext not provided."); } if (value != null) { if (CachedValidationFunc == null) { CachedValidationFunc = Parser.Parse(entityValidationContext.ObjectType, Expression); } if (!CachedValidationFunc(entityValidationContext.ObjectInstance)) { return (new EntityValidationResult(FormatErrorMessage(entityValidationContext.DisplayName, Expression))); } } return(EntityValidationResult.Success()); }
public override EntityValidationResult Validate(object value, EntityValidationContext entityValidationContext) { if (entityValidationContext == null) { throw new ArgumentNullException("entityValidationContext", "EntityValidationContext not provided."); } var isEmpty = value is string && string.IsNullOrWhiteSpace((string)value); if (value == null || (isEmpty && !AllowEmptyStrings)) { if (CachedValidationFunc == null) { CachedValidationFunc = Parser.Parse(entityValidationContext.ObjectType, Expression); } if (CachedValidationFunc(entityValidationContext.ObjectInstance)) { return (new EntityValidationResult(FormatErrorMessage(entityValidationContext.DisplayName, Expression))); } } return(EntityValidationResult.Success()); }