當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。