当前位置: 首页>>代码示例>>C#>>正文


C# DataAnnotations.ValidationAttribute类代码示例

本文整理汇总了C#中System.ComponentModel.DataAnnotations.ValidationAttribute的典型用法代码示例。如果您正苦于以下问题:C# ValidationAttribute类的具体用法?C# ValidationAttribute怎么用?C# ValidationAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ValidationAttribute类属于System.ComponentModel.DataAnnotations命名空间,在下文中一共展示了ValidationAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ViewModelPropertyValidationRule

 public ViewModelPropertyValidationRule(string clientRule, ValidationAttribute sourceValidationAttribute, string errorMessage, params object[] parameters)
 {
     ClientRuleName = clientRule;
     SourceValidationAttribute = sourceValidationAttribute;
     ErrorMessage = errorMessage;
     Parameters = parameters;
 }
开发者ID:darilek,项目名称:dotvvm,代码行数:7,代码来源:ViewModelPropertyValidationRule.cs

示例2: GetRules

 /// <summary>
 /// Gets the rules the adapter provides.
 /// </summary>
 /// <param name="attribute">The <see cref="ValidationAttribute"/> that should be handled.</param>
 /// <param name="descriptor">A <see cref="PropertyDescriptor"/> instance for the property that is being validated.</param>
 /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
 public override IEnumerable<ModelValidationRule> GetRules(ValidationAttribute attribute, PropertyDescriptor descriptor)
 {
     yield return new StringLengthValidationRule(attribute.FormatErrorMessage,
         new[] { descriptor.Name },
         ((StringLengthAttribute)attribute).MinimumLength,
         ((StringLengthAttribute)attribute).MaximumLength);
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:13,代码来源:StringLengthValidatorAdapter.cs

示例3: ValidationAttributeValidator

        /// <summary>
        ///     Creates an instance of <see cref = "ValidationAttributeValidator" /> class.
        /// </summary>
        /// <param name = "validationAttribute">
        ///     Validation attribute used to validate a property or an entity.
        /// </param>
        public ValidationAttributeValidator(ValidationAttribute validationAttribute, DisplayAttribute displayAttribute)
        {
            //Contract.Requires(validationAttribute != null);

            _validationAttribute = validationAttribute;
            _displayAttribute = displayAttribute;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:13,代码来源:ValidationAttributeValidator.cs

示例4: ValidationAttributeValidator

        // <summary>
        // Creates an instance of <see cref="ValidationAttributeValidator" /> class.
        // </summary>
        // <param name="validationAttribute"> Validation attribute used to validate a property or an entity. </param>
        public ValidationAttributeValidator(ValidationAttribute validationAttribute, DisplayAttribute displayAttribute)
        {
            DebugCheck.NotNull(validationAttribute);

            _validationAttribute = validationAttribute;
            _displayAttribute = displayAttribute;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:ValidationAttributeValidator.cs

示例5: GetAttributeValidation

        public static void GetAttributeValidation(ValidationAttribute attr, IDictionary<string, object> htmlAttributes)
        {
            var str = string.Empty;
              if (attr is RequiredAttribute)
              {
              StringLengthAttribute a = attr as StringLengthAttribute;
              htmlAttributes["required"] = null;

              }
              else if (attr is StringLengthAttribute)
              {
              StringLengthAttribute a = attr as StringLengthAttribute;
              htmlAttributes["maxlength"] = a.MaximumLength;
              htmlAttributes["minlength"] = a.MinimumLength;

              }
              else if (attr is RegularExpressionAttribute)
              {
              RegularExpressionAttribute a = attr as RegularExpressionAttribute;
              htmlAttributes["pattern"] = a.Pattern;

              }
              else if (attr is IdenticalAttribute)
              {
              IdenticalAttribute a = attr as IdenticalAttribute;
              htmlAttributes["data-fv-identical"] = "true";
              htmlAttributes["data-fv-identical-field"] = a.Field;
              }

              if (attr.ErrorMessage.IsNotNull()) {
              htmlAttributes[ ValidateMesAttr[attr.GetType()]]= attr.ErrorMessage;
              }
        }
开发者ID:alittletired,项目名称:SolutionPlatform,代码行数:33,代码来源:ValidationHelper.cs

示例6: Create

        /// <summary>
        /// Create client validation rules for Data Annotation attributes.
        /// </summary>
        /// <param name="attribute">Attribute</param>
        /// <param name="errorMessage">Not formatted error message (should contain {0} etc}</param>
        /// <returns>A collection of rules (or an empty collection)</returns>
        public virtual IEnumerable<ModelClientValidationRule> Create(ValidationAttribute attribute, string errorMessage)
        {
            if (attribute is RangeAttribute)
            {
                var attr = (RangeAttribute) attribute;
                return new[]
                           {
                               new ModelClientValidationRangeRule(errorMessage, attr.Minimum, attr.Maximum)
                           };
            }
            if (attribute is RegularExpressionAttribute)
            {
                var attr = (RegularExpressionAttribute) attribute;
                return new[] {new ModelClientValidationRegexRule(errorMessage, attr.Pattern)};
            }
            if (attribute is RequiredAttribute)
            {
                var attr = (RequiredAttribute) attribute;
                return new[] {new ModelClientValidationRequiredRule(errorMessage)};
            }
            if (attribute is StringLengthAttribute)
            {
                var attr = (StringLengthAttribute) attribute;
                return new[]
                           {
                               new ModelClientValidationStringLengthRule(errorMessage, attr.MinimumLength,
                                                                         attr.MaximumLength)
                           };
            }

            return new ModelClientValidationRule[0];
        }
开发者ID:iceball12,项目名称:griffin.mvccontrib,代码行数:38,代码来源:ValidationAttributeAdapterFactory.cs

示例7: MyValidator

			public MyValidator(ValidationAttribute attribute, string errorMsg, ModelMetadata metadata, ControllerContext controllerContext, IEnumerable<ModelClientValidationRule> create)
				: base(metadata, controllerContext)
			{
				_attribute = attribute;
				_errorMsg = errorMsg;
				_create = create;
			}
开发者ID:damirarh,项目名称:griffin.mvccontrib,代码行数:7,代码来源:LocalizedModelValidatorProvider.cs

示例8: DynamoDataAnnotationsModelValidator

		public DynamoDataAnnotationsModelValidator(IServiceProvider provider, ModelMetadata metadata, ControllerContext context, ValidationAttribute attribute)
			: base(metadata, context, attribute)
		{
			if (provider == null)
				throw new ArgumentNullException("provider");

			_provider = provider;
		}
开发者ID:Kingefosa,项目名称:Dynamo.IoC,代码行数:8,代码来源:DynamoDataAnnotationsModelValidator.cs

示例9: DataAnnotationsModelValidator

        public DataAnnotationsModelValidator(ModelMetadata metadata, ControllerContext context, ValidationAttribute attribute)
            : base(metadata, context)
        {
            if (attribute == null) {
                throw new ArgumentNullException("attribute");
            }

            Attribute = attribute;
        }
开发者ID:jenrom,项目名称:Spikes,代码行数:9,代码来源:DataAnnotationsModelValidator.cs

示例10: AttributeValidationItem

 /// <summary>
 /// Initializes a new instance of the AttributeValidationItem class.
 /// </summary>
 /// <param name="attribute"></param>
 /// <param name="propertyName"></param>
 public AttributeValidationItem(ValidationAttribute attribute, string propertyName)
 {
     if (attribute == null)
         throw new ArgumentNullException("attribute", "attribute is null.");
     if (String.IsNullOrEmpty(propertyName))
         throw new ArgumentException("propertyName is null or empty.", "propertyName");
     _attribute = attribute;
     _propertyName = propertyName;
 }
开发者ID:xebialabs-community,项目名称:xld-manifest-editor,代码行数:14,代码来源:AttributeValidationItem.cs

示例11: DataAnnotationsModelValidator

        public DataAnnotationsModelValidator(ValidationAttribute attribute, IStringLocalizer stringLocalizer)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            Attribute = attribute;
            _stringLocalizer = stringLocalizer;
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:10,代码来源:DataAnnotationsModelValidator.cs

示例12: GetErrorMessages

 public static IEnumerable<string> GetErrorMessages(ValidationAttribute[] attributes,
     object value, ValidationContext context)
 {
     var errorMessages = attributes
             .Select(v => v.GetValidationResult(value, context))
             .Where(r => r != null)
             .Select(r => r.ErrorMessage)
             .Where(e => !string.IsNullOrEmpty(e));
     return errorMessages;
 }
开发者ID:guozanhua,项目名称:phmi,代码行数:10,代码来源:Validator.cs

示例13: HandleErrorMessage

        protected virtual void HandleErrorMessage(string languageKey, ValidationAttribute attribute)
        {
            if (attribute.ErrorMessageResourceName == null)
            {
                attribute.ErrorMessage = LangResource.Resources.GetString(languageKey);

                if (string.IsNullOrEmpty(attribute.ErrorMessage))
                    attribute.ErrorMessage = string.Format("[[{0}]]", languageKey);
            }
        }
开发者ID:sbudihar,项目名称:SIRIUSrepo,代码行数:10,代码来源:LocalizedDataAnnotationsModelMetadataProvider.cs

示例14: AdapterFactory_RegistersAdapters_ForDataAnnotationAttributes

        public void AdapterFactory_RegistersAdapters_ForDataAnnotationAttributes(
               ValidationAttribute attribute,
               Type expectedAdapterType)
        {
            // Arrange and Act
            var adapter = _validationAttributeAdapterProvider.GetAttributeAdapter(attribute, stringLocalizer: null);

            // Assert
            Assert.IsType(expectedAdapterType, adapter);
        }
开发者ID:phinq19,项目名称:git_example,代码行数:10,代码来源:ValidationAttributeAdapterProviderTest.cs

示例15: DataAnnotationsModelValidator

        public DataAnnotationsModelValidator(IEnumerable<ModelValidatorProvider> validatorProviders, ValidationAttribute attribute)
            : base(validatorProviders)
        {
            if (attribute == null)
            {
                throw Error.ArgumentNull("attribute");
            }

            Attribute = attribute;
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:10,代码来源:DataAnnotationsModelValidator.cs


注:本文中的System.ComponentModel.DataAnnotations.ValidationAttribute类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。