Пример #1
0
 public static void DoMemberLevelValidation(this IDictionary <string, object> dict, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm)
 {
     if (!fieldConfig.Validators.IsNullOrEmpty() && (vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
     {
         if (fieldConfig.Validator == null)
         {
             ChoValidator.ValidateFor(dict[fn], fn, fieldConfig.Validators);
         }
         else
         {
             if (!fieldConfig.Validator(dict[fn]))
             {
                 throw new ValidationException("Failed to validate '{0}' member. {1}".FormatString(fn, Environment.NewLine));
             }
         }
     }
 }
Пример #2
0
        public static void DoMemberLevelValidation(this object rec, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm)
        {
            if (!((vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel))
            {
                return;
            }

            if (rec is IDictionary <string, object> )
            {
                ((IDictionary <string, object>)rec).DoMemberLevelValidation(fn, fieldConfig, vm);
            }
            else
            {
                if (fieldConfig.Validator == null)
                {
                    if (fieldConfig.PD == null)
                    {
                        fieldConfig.PD = fieldConfig.PropertyDescriptor;
                    }
                    if (fieldConfig.PD != null)
                    {
                        if (fieldConfig.Validators.IsNullOrEmpty())
                        {
                            ChoValidator.ValidateFor(rec, fieldConfig.PD);
                        }
                        else
                        {
                            ChoValidator.ValidateFor(fieldConfig.PD.GetValue(rec), fn, fieldConfig.Validators);
                        }
                    }
                }
                else
                {
                    if (!fieldConfig.Validator(fieldConfig.PD.GetValue(rec)))
                    {
                        throw new ValidationException("Failed to validate '{0}' member. {1}".FormatString(fn, Environment.NewLine));
                    }
                }
            }
        }