Esempio n. 1
0
 /// <summary>
 /// Creates the validator.
 /// </summary>
 /// <param name="modelMetadata">The model metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected override sealed ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
 {
     var attribute = CreateAttribute();
     attribute.PassOnNull = PassOnNull;
     PopulateErrorMessage(attribute);
     return new FoolproofValidator(modelMetadata, context, attribute);
 }
Esempio n. 2
0
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = new RegularExpressionAttribute(Pattern);

            PopulateErrorMessage(attribute);
            return(new RegularExpressionAttributeAdapter(modelMetadata, context, attribute));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = new CompareAttribute(OtherProperty);

            PopulateErrorMessage(attribute);
            return(new DataAnnotationsModelValidator <CompareAttribute>(modelMetadata, context, attribute));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = new RangeAttribute(typeof(TValueType), Minimum.ToString(), Maximum.ToString());

            PopulateErrorMessage(attribute);
            return(new RangeAttributeAdapter(modelMetadata, context, attribute));
        }
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public ModelValidator CreateValidator(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var validator = Factory(modelMetadata, context);

            Configure(validator);
            return(validator);
        }
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public ModelValidator CreateValidator(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            Invariant.IsNotNull(modelMetadata, "modelMetadata");
            Invariant.IsNotNull(context, "context");

            return(CreateValidatorCore(modelMetadata, context));
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = new RequiredIfNotAttribute(OtherProperty, DependentValue);

            PopulateErrorMessage(attribute);
            return(new FoolproofValidator(modelMetadata, context, attribute));
        }
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public ModelValidator CreateValidator(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            Invariant.IsNotNull(modelMetadata, "modelMetadata");
            Invariant.IsNotNull(context, "context");

            return CreateValidatorCore(modelMetadata, context);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected sealed override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = CreateAttribute();

            attribute.PassOnNull = PassOnNull;
            PopulateErrorMessage(attribute);
            return(new FoolproofValidator(modelMetadata, context, attribute));
        }
 /// <summary>
 /// Creates the validator.
 /// </summary>
 /// <param name="modelMetadata">The model metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
 {
     var attribute = new StringLengthAttribute(Maximum)
                         {
                             MinimumLength = Minimum
                         };
     PopulateErrorMessage(attribute);
     return new StringLengthAttributeAdapter(modelMetadata, context, attribute);
 }
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata">The model metadata.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = new StringLengthAttribute(Maximum)
            {
                MinimumLength = Minimum
            };

            PopulateErrorMessage(attribute);
            return(new StringLengthAttributeAdapter(modelMetadata, context, attribute));
        }
Esempio n. 12
0
        private ModelMetadata CreateModelMetadata(Type modelType, Func <object> modelAccessor, ModelMetadataItem metadataItem)
        {
            ModelMetadata modelMetadata = new ExtendedModelMetadata(this, null, modelAccessor, modelType, null, metadataItem);

            if (metadataItem != null)
            {
                Copy(metadataItem, modelMetadata);
            }

            return(modelMetadata);
        }
        private ModelMetadata CreatePropertyMetadata(Type containerType, string propertyName, Type propertyType, ModelMetadataItem propertyMetadata, Func <object> modelAccessor)
        {
            ModelMetadata modelMetadata = new ExtendedModelMetadata(this, containerType, modelAccessor, propertyType, propertyName, propertyMetadata);

            if (propertyMetadata != null)
            {
                Copy(propertyMetadata, modelMetadata);
            }

            return(modelMetadata);
        }
        public override IEnumerable <ModelValidator> GetValidators([NotNull] ModelMetadata metadata, [NotNull] ControllerContext context)
        {
            Invariant.IsNotNull(metadata, "metadata");
            Invariant.IsNotNull(context, "context");

            ExtendedModelMetadata extendedModelMetadata = metadata as ExtendedModelMetadata;

            return(extendedModelMetadata != null && extendedModelMetadata.Metadata != null?
                   extendedModelMetadata.Metadata.Validations.Select(validationMeta => validationMeta.CreateValidator(extendedModelMetadata, context)) :
                       Enumerable.Empty <ModelValidator>());
        }
Esempio n. 15
0
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata"> The model metadata. </param>
        /// <param name="context"> The context. </param>
        /// <returns> </returns>
        protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = Area == null && Controller == null
                                ? new RemoteAttribute(RouteName)
                                : new RemoteAttribute(Action, Controller, Area);

            attribute.AdditionalFields = AdditionalFields;
            attribute.HttpMethod       = HttpMethod;

            PopulateErrorMessage(attribute);
            return(new DataAnnotationsModelValidator <RemoteAttribute>(modelMetadata, context, attribute));
        }
        private ModelMetadata CreateModelMetadata(Type modelType, Func<object> modelAccessor, ModelMetadataItem metadataItem)
        {
            ModelMetadata modelMetadata = new ExtendedModelMetadata(this, null, modelAccessor, modelType, null, metadataItem);

            if (metadataItem != null)
            {
                Copy(metadataItem, modelMetadata);
            }

            return modelMetadata;
        }
Esempio n. 17
0
        /// <summary>
        /// Creates the validator.
        /// </summary>
        /// <param name="modelMetadata"> The model metadata. </param>
        /// <param name="context"> The context. </param>
        /// <returns> </returns>
        protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
        {
            var attribute = Area == null && Controller == null
                                ? new RemoteAttribute(RouteName)
                                : new RemoteAttribute(Action, Controller, Area);

            attribute.AdditionalFields = AdditionalFields;
            attribute.HttpMethod = HttpMethod;

            PopulateErrorMessage(attribute);
            return new DataAnnotationsModelValidator<RemoteAttribute>(modelMetadata, context, attribute);
        }
 /// <summary>
 /// Creates the validator.
 /// </summary>
 /// <param name="modelMetadata">The model metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
 {
     var attribute = new RequiredIfNotRegExMatchAttribute(OtherProperty, Expression);
     PopulateErrorMessage(attribute);
     return new FoolproofValidator(modelMetadata, context, attribute);
 }
Esempio n. 19
0
 /// <summary>
 /// Creates the validator.
 /// </summary>
 /// <param name="modelMetadata">The model metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
 {
     var attribute = new RequiredAttribute();
     PopulateErrorMessage(attribute);
     return new RequiredAttributeAdapter(modelMetadata, context, attribute);
 }
Esempio n. 20
0
 protected abstract ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context);
        private ModelMetadata CreatePropertyMetadata(Type containerType, string propertyName, Type propertyType, ModelMetadataItem propertyMetadata, Func<object> modelAccessor)
        {
            ModelMetadata modelMetadata = new ExtendedModelMetadata(this, containerType, modelAccessor, propertyType, propertyName, propertyMetadata);

            if (propertyMetadata != null)
            {
                Copy(propertyMetadata, modelMetadata);
            }

            return modelMetadata;
        }
Esempio n. 22
0
 /// <summary>
 /// Creates the validator.
 /// </summary>
 /// <param name="modelMetadata">The model metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
 {
     var attribute = new CompareAttribute(OtherProperty);
     PopulateErrorMessage(attribute);
     return new DataAnnotationsModelValidator<CompareAttribute>(modelMetadata, context, attribute);
 }
 /// <summary>
 /// Creates the validator.
 /// </summary>
 /// <param name="modelMetadata">The model metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected override ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context)
 {
     var attribute = new RequiredIfAttribute(OtherProperty, Operator, DependentValue);
     PopulateErrorMessage(attribute);
     return new FoolproofValidator(modelMetadata, context, attribute);
 }
Esempio n. 24
0
 /// <summary>
 /// Creates the validator.
 /// </summary>
 /// <param name="modelMetadata">The model metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected abstract ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context);