/// <summary>
 /// Validates the specified object, returning a collection of validation rules.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public override IEnumerable<IValidationFieldResult> Validate(ValidationContext context)
 {
     var results = new List<IValidationFieldResult>();
     var dataErrorInfo = context.ValidationTarget as IDataErrorInfo;
     if (dataErrorInfo != null)
     {
         var fields = "";
         foreach (var field in context.FieldNamesToValidate)
         {
             fields += field + " ";
             var message = dataErrorInfo[field];
             if ((message ?? string.Empty).Trim().Length > 0)
             {
                 results.Add(new ValidationFieldResult
                                  {
                                      AssociatedProperties = new[] { field },
                                      Category = ValidationCategory.Error,
                                      Message = message
                                  });
             }
         }
         Console.WriteLine("Validating fields: {" + fields.Trim() + "} on source " + context.ValidationTarget.GetType().Name);
     }
     return results;
 }
 /// <summary>
 /// Validates the specified object, returning a collection of validation rules.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public override IEnumerable<IValidationFieldResult> Validate(ValidationContext context)
 {
     var validatable = context.ValidationTarget as IValidatable;
     if (validatable != null)
     {
         return validatable.Validate().Where(r => r.AssociatedProperties.Intersect(context.FieldNamesToValidate).Count() > 0);
     }
     return new IValidationFieldResult[0];
 }
 /// <summary>
 /// Determines whether this instance can validate the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>
 /// 	<c>true</c> if this instance can validate the specified context; otherwise, <c>false</c>.
 /// </returns>
 public override bool CanValidate(ValidationContext context)
 {
     return context.ValidationTarget is IValidatable;
 }
        private ValidationProvider GetFirstAppropriateValidationProvider(ValidationContext context)
        {
            var result = null as ValidationProvider;
            foreach (var item in ValidationProviders)
            {
                if (!item.CanValidate(context)) continue;

                result = item;
                break;
            }
            return result;
        }
 /// <summary>
 /// Validates the specified object, returning a collection of validation rules.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public override IEnumerable<IValidationFieldResult> Validate(ValidationContext context)
 {
     var provider = GetFirstAppropriateValidationProvider(context);
     return provider != null ? provider.Validate(context) : new IValidationFieldResult[0];
 }
 /// <summary>
 /// Determines whether this instance can validate the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>
 /// 	<c>true</c> if this instance can validate the specified context; otherwise, <c>false</c>.
 /// </returns>
 public override bool CanValidate(ValidationContext context)
 {
     return GetFirstAppropriateValidationProvider(context) != null;
 }
 /// <summary>
 /// Determines whether this instance can validate the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>
 /// 	<c>true</c> if this instance can validate the specified context; otherwise, <c>false</c>.
 /// </returns>
 public override bool CanValidate(ValidationContext context)
 {
     return context.ValidationTarget is IDataErrorInfo;
 }
Esempio n. 8
0
 public abstract IEnumerable<IValidationFieldResult> Validate(ValidationContext context);
Esempio n. 9
0
 public abstract bool CanValidate(ValidationContext context);