Beispiel #1
0
        internal static ValidationFailure CreateValidationFailure <TModel, TProperty>(Expression <Func <TModel, TProperty> > propertyExp, string errorMessage, ValidationContext context)
        {
            if (!(propertyExp.Body is MemberExpression memberExpression) || memberExpression.Expression.NodeType != ExpressionType.Parameter)
            {
                throw new InvalidOperationException("Invalid property expression");
            }

            var newContext = context.Clone();

            newContext.PropertyChain.Add(memberExpression.Member);
            var attemptedValue = context.InstanceToValidate is TModel child
                ? propertyExp.Compile()(child)
                : (object)null;

            return(new ValidationFailure(propertyExp.GetFullPropertyName(), errorMessage, attemptedValue)
            {
                CustomState = new DomainValidationContext(context.InstanceToValidate, attemptedValue, context)
            });
        }
        public ValidationContext BeforeMvcValidation(HttpActionContext cc, ValidationContext context)
        {
            var newContext = context.Clone(selector: new FluentValidation.Internal.MemberNameValidatorSelector(properties));

            return(newContext);
        }
Beispiel #3
0
            public ValidationContext BeforeMvcValidation(ControllerContext cc, ValidationContext context)
            {
                var newContext = context.Clone(selector: new MemberNameValidatorSelector(properties));

                return(newContext);
            }