0
假设我们有下面的代码 C#数据注释窗体应用程序
public class Customer
{
[Required]
[StringLength(50)]
public string LastName { get; set; }
[Range(5, 50)]
public int ReorderLevel { get; set; }
[Range(typeof(Decimal),"5", "5000")]
public decimal ListPrice { get; set; }
}
或VB.NET
Public Class Customer
<Required> _
<StringLength(50)> _
Public Property LastName() As String
Get
Return m_LastName
End Get
Set
m_LastName = Value
End Set
End Property
Private m_LastName As String
<Range(5, 50)> _
Public Property ReorderLevel() As Integer
Get
Return m_ReorderLevel
End Get
Set
m_ReorderLevel = Value
End Set
End Property
Private m_ReorderLevel As Integer
<Range(GetType([Decimal]), "5", "5000")> _
Public Property ListPrice() As Decimal
Get
Return m_ListPrice
End Get
Set
m_ListPrice = Value
End Set
End Property
Private m_ListPrice As Decimal
End Class
是否有可能设置范围和需要开启或关闭web.config?
这将帮助用户在业务需要更改时添加/删除验证。例如。需要使一个字段是必需的或可选的。
或更改范围 干杯
让你的客户类实现IValidatableObject。然后您可以测试条件并在需要时应用验证。 http://www.itorian.com/2013/02/custom-validation-with.html –