public override IEnumerable <ValidationError> Validate(ModelValidationContext context) { Precondition.Require(context, () => Error.ArgumentNull("context")); if (!_attribute.IsValid(context.Model)) { yield return(new ValidationError(context.Member, _attribute.ErrorMessage)); } }
protected virtual void OnModelUpdated(BindingContext context) { IEnumerable<ModelValidator> validators = ValidatorProvider.GetValidators(context.ModelType); ModelValidationContext inner = new ModelValidationContext(context.ModelName, context.Model); foreach (ModelValidator validator in validators) { foreach (ValidationError error in validator.Validate(inner)) context.ModelState.Add(error.Key, error); } }
public override IEnumerable<ValidationError> Validate (ModelValidationContext context) { if (Object.ReferenceEquals(context.Model, null)) return Enumerable.Empty<ValidationError>(); string memberKey = (String.IsNullOrEmpty(context.Member)) ? _property.Name : String.Format("{0}-{1}", context.Member, _property.Name); ModelValidationContext inner = new ModelValidationContext( memberKey, context.Model, _property.GetValue(context.Model)); return _validators.SelectMany(a => a.Validate(inner)); }
public override IEnumerable<ValidationError> Validate (ModelValidationContext context) { Precondition.Require(context, () => Error.ArgumentNull("context")); IDataErrorInfo model = (context.Container as IDataErrorInfo); if (model != null) { string message = model.Error; if (!String.IsNullOrEmpty(message)) return new ValidationError(context.Member, message).ToEnumerable(); } return Enumerable.Empty<ValidationError>(); }
protected virtual void OnModelUpdated(BindingContext context) { IEnumerable <ModelValidator> validators = ValidatorProvider.GetValidators(context.ModelType); ModelValidationContext inner = new ModelValidationContext(context.ModelName, context.Model); foreach (ModelValidator validator in validators) { foreach (ValidationError error in validator.Validate(inner)) { context.ModelState.Add(error.Key, error); } } }
public override IEnumerable <ValidationError> Validate(ModelValidationContext context) { if (Object.ReferenceEquals(context.Model, null)) { return(Enumerable.Empty <ValidationError>()); } string memberKey = (String.IsNullOrEmpty(context.Member)) ? _property.Name : String.Format("{0}-{1}", context.Member, _property.Name); ModelValidationContext inner = new ModelValidationContext( memberKey, context.Model, _property.GetValue(context.Model)); return(_validators.SelectMany(a => a.Validate(inner))); }
public override IEnumerable <ValidationError> Validate(ModelValidationContext context) { Precondition.Require(context, () => Error.ArgumentNull("context")); IDataErrorInfo model = (context.Container as IDataErrorInfo); if (model != null) { string message = model.Error; if (!String.IsNullOrEmpty(message)) { return(new ValidationError(context.Member, message).ToEnumerable()); } } return(Enumerable.Empty <ValidationError>()); }
public abstract IEnumerable<ValidationError> Validate(ModelValidationContext context);
public abstract IEnumerable <ValidationError> Validate(ModelValidationContext context);
public override IEnumerable<ValidationError> Validate (ModelValidationContext context) { Precondition.Require(context, () => Error.ArgumentNull("context")); if (!_attribute.IsValid(context.Model)) yield return new ValidationError(context.Member, _attribute.ErrorMessage); }