Пример #1
0
        public static void Validate(MemberInfo memberInfo, object memberValue)
        {
            IChoSurrogateValidator validator = ChoCompositeValidatorBuilder.GetValidator(memberInfo);

            if (validator == null)
            {
                return;
            }

            validator.Validate(memberInfo, memberValue);
        }
Пример #2
0
        private static void DoValidate <T>(T target, ChoValidationResults validationResults)
        {
            bool validationRoutineFound = false;
            bool canContinue            = true;

            foreach (MethodInfo methodInfo in GetValidationRoutines(target.GetType()))
            {
                canContinue            = false;
                validationRoutineFound = true;
                canContinue            = (bool)ChoType.InvokeMethod(target, methodInfo.Name, new object[] { validationResults });
                if (!canContinue)
                {
                    break;
                }
            }

            //Do built-in attribute validations
            if (!validationRoutineFound)
            {
                MemberInfo[] memberInfos = ChoType.GetMembers(target.GetType());
                foreach (MemberInfo memberInfo in memberInfos)
                {
                    IChoSurrogateValidator validator = ChoCompositeValidatorBuilder.GetValidator(memberInfo);
                    if (validator == null)
                    {
                        continue;
                    }

                    try
                    {
                        validator.Validate(memberInfo, ChoType.GetMemberValue(target, memberInfo.Name));
                    }
                    catch (ChoFatalApplicationException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        validationResults.AddResult(new ChoValidationResult(ex.Message));
                    }
                }
            }
        }