Validation Entlib验证语法是否只接受数字月数?

Validation Entlib验证语法是否只接受数字月数?,validation,enums,integer,enterprise-library,Validation,Enums,Integer,Enterprise Library,我已将枚举定义为: Private Enum AllowedMonthNumbers _1 _2 _3 _4 _5 _6 _7 _8 _9 _10 _11 _12 End Enum 然后,属性验证器定义为: <TypeConversionValidator(GetType(Int32), MessageTemplate:="Card expiry month must be numeric."

我已将枚举定义为:

Private Enum AllowedMonthNumbers
    _1
    _2
    _3
    _4
    _5
    _6
    _7
    _8
    _9
    _10
    _11
    _12
End Enum
然后,属性验证器定义为:

<TypeConversionValidator(GetType(Int32), MessageTemplate:="Card expiry month must be numeric.", Ruleset:="CreditCard")> _
<EnumConversionValidator(GetType(AllowedMonthNumbers), MessageTemplate:="Card expiry month must be between 1 and 12.", Ruleset:="CreditCard")> _

RangeValidator
只能处理int、float、double、decimal等基本类型。因为您在构造函数中提供了一个整数,所以它试图将该整数与枚举匹配,这将失败,因为VAB使用
Object.Compare(Object)
方法

尝试使用不必将数字范围定义为枚举的设计。请尝试改用简单的整数字段。痛苦要小得多

<RangeValidator(1, RangeBoundaryType.Inclusive, 12, RangeBoundaryType.Inclusive, MessageTemplate:="..."> 
System.Web.Services.Protocols.SoapException : System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: Object must be of type Int32.
   at System.Int32.CompareTo(Object value)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeChecker`1.IsInRange(T target)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeValidator`1.DoValidate(T objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validator`1.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.AndCompositeValidator.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ValueAccessValidator.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.AndCompositeValidator.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.GenericValidatorWrapper`1.DoValidate(T objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validator`1.Validate(T target, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validation.Validate[T](T target, String[] rulesets)
   at ....