【发布时间】:2010-02-04 01:21:30
【问题描述】:
我有一个地址对象,我正在尝试使用 EntLib 验证数据:
给定以下方法:
<ValidatorComposition(CompositionType.And, Ruleset:="FraudAnalysis")> _
<NotNullValidator(MessageTemplate:="Billing address is required.", Ruleset:="FraudAnalysis")> _
<TypeConversionValidator(GetType(Address), MessageTemplate:="Billing address must be an address object.", Ruleset:="FraudAnalysis")> _
Public Property BillingAddress() As Address
Get
Return _BillingAddress
End Get
Set(ByVal value As Address)
_BillingAddress = value
End Set
End Property
我创建一个地址对象:
Address thisAddress = new Address();
thisAddress.Address1 = "12312 Long Street";
thisAddress.City = "Los Angeles";
thisAddress.State = "CA";
thisAddress.Zip = "93322";
// set billing address to address
cardX.BillingAddress = thisAddress;
所以现在在 cardX.billingAddress = thisAddress 处,BillingAddress 属性验证器 (GetType(Address)) 应该触发。它似乎触发了,但返回此错误:
要验证的值不是预期的类型:预期的 System.String 但得到了 Address。
任何人都可以在这里看到问题/建议修复吗?
谢谢。
【问题讨论】:
标签: validation enterprise-library gettype