示例#1
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(UnwrapNullable(typeof(TValueType)), Minimum.ToString(), Maximum.ToString());

            PopulateErrorMessage(attribute);
            return(new RangeAttributeAdapter(modelMetadata, context, attribute));
        }
示例#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 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 RequiredAttribute();

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

            Configure(validator);
            return(validator);
        }
示例#5
0
        public ModelValidator CreateValidator([NotNull] ExtendedModelMetadata metadata, [NotNull] ControllerContext context)
        {
            //Invariant.IsNotNull(metadata, "metadata");
            //Invariant.IsNotNull(context, "context");

            modelMetadata = metadata;

            return(CreateValidatorCore(metadata, context));
        }
 /// <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));
        }
        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>());
        }
        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);
        }
示例#11
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));
        }
示例#12
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);
        }
示例#13
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);
 }
        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;
        }
示例#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 = new RequiredAttribute();
     PopulateErrorMessage(attribute);
     return new RequiredAttributeAdapter(modelMetadata, context, attribute);
 }
        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;
        }
示例#17
0
 protected abstract ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context);
示例#18
0
 protected abstract ModelValidator CreateValidatorCore(ExtendedModelMetadata modelMetadata, ControllerContext context);