コード例 #1
0
 /// <summary>
 /// Fluent API: Used to define the validation rules an results. Validations will be evaluated in the same order they are defined
 /// </summary>
 /// <param name="validate">Validation action passing the object, the validating object and a <see cref="ValidationResultCollection"/> to put the validations result into</param>
 /// <param name="continueOnValidationError">Indicates whether to stop or continue the property change when some validation error happens</param>
 /// <param name="notifyChangeOnValidationError">Indicates if the property must be changed even when some validation errors occur. Setting this to true includes the error in the object validation results. If false, the property change will not be notified.</param>
 /// <param name="when">Indicates whether to execute this rule before, after coerce, or both</param>
 /// <returns>this</returns>
 /// <remarks>
 /// The following example registers an error when a number is found on a person name, before coerce, the wrong value will be set and the change will be notified
 /// RegisterProperty<Person>(p => p.Name).Validate((t, v, vr) => vr.Error((v?.Any(ch => char.IsDigit(ch)) == true), "Cannot contain numbers"), notifyChangeOnValidationError: true, when: ValidationErrorBehavior.BeforeCoerce);
 /// </remarks>
 public ViewModelCollectionPropertyDescriptor <TOwner, TResult> Validate(
     Action <TOwner, TResult, ValidationResultCollection> validate,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true)
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = validate,
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError
     });
     return(this);
 }
コード例 #2
0
 /// <summary>
 /// Fluent API: Used to define the validation rules an results. Validations will be evaluated in the same order they are defined
 /// </summary>
 /// <param name="validate">Validation action passing the object, the validating object and a <see cref="ValidationResultCollection"/> to put the validations result into</param>
 /// <param name="continueOnValidationError">Indicates whether to stop or continue the property change when some validation error happens</param>
 /// <param name="notifyChangeOnValidationError">Indicates if the property must be changed even when some validation errors occur. Setting this to true includes the error in the object validation results. If false, the property change will not be notified.</param>
 /// <param name="when">Indicates whether to execute this rule before, after coerce, or both</param>
 /// <returns>this</returns>
 /// <remarks>
 /// The following example registers an error when a number is found on a person name, before coerce, the wrong value will be set and the change will be notified
 /// RegisterProperty<Person>(p => p.Name).Validate((t, v, vr) => vr.Error((v?.Any(ch => char.IsDigit(ch)) == true), "Cannot contain numbers"), notifyChangeOnValidationError: true, when: ValidationErrorBehavior.BeforeCoerce);
 /// </remarks>
 public ViewModelPropertyDescriptor <TOwner, TResult> Validate(
     Action <TOwner, TResult, ValidationResultCollection> validate,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true,
     ValidationErrorBehavior when       = ValidationErrorBehavior.AfterCoerce)
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = validate,
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError,
         BehaviorOnCoerce = when
     });
     return(this);
 }
コード例 #3
0
 public ViewModelCollectionPropertyDescriptor <TOwner, TResult> Validate <TValidator>(
     ValidationKind kind                = ValidationKind.Error,
     string message                     = null,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true)
     where TValidator : IValidator, new()
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = (vm, x, res) => res.Validate <TValidator>(x, message, kind),
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError
     });
     return(this);
 }
コード例 #4
0
 public ViewModelCollectionPropertyDescriptor <TOwner, TResult> Validate(
     Func <TOwner, TResult, bool> condition,
     ValidationKind kind                = ValidationKind.Error,
     string message                     = null,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true)
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = (vm, x, res) => res.Validate(condition(vm, x), message, kind),
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError
     });
     return(this);
 }
コード例 #5
0
 public ViewModelPropertyDescriptor <TOwner, TResult> Validate(
     IValidator validator,
     ValidationKind kind                = ValidationKind.Error,
     string message                     = null,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true,
     ValidationErrorBehavior when       = ValidationErrorBehavior.AfterCoerce)
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = (vm, x, res) => res.Validate(validator, x, message, kind),
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError,
         BehaviorOnCoerce = when
     });
     return(this);
 }