( I don't have any problem to accept an VB.NET or C# solution )
I've created a new empty WinForms project with this content written in VB.NET only to test the RangeAttribute, but the range and the error message are totally ignored (any error):
Public Class Form1
Private Shadows Sub Load() Handles MyBase.Load
Dim Test As New Test With {.MyInt32 = Integer.MaxValue}
MessageBox.Show(Test.MyInt32) ' Result: 2147483647
End Sub
End Class
Public Class Test
<System.ComponentModel.DataAnnotations.Range(1I, 10I, errormessage:="something")>
Public Property MyInt32 As Integer
Get
Return Me._MyInt32
End Get
Set(ByVal value As Integer)
Me._MyInt32 = value
End Set
End Property
Private _MyInt32 As Integer = 0I
End Class
Why happens this?
Searching for an alternative solution I've done the same using PostSharp to create an Aspect as described in one of the answers of this question, but I don't like this solution because I should not depend on a third party lib to do this in case that the .NET Framework Class Library exposes a way to do the same (and I think is much better 'cause the overloads of the attribute for DateTime types, etc).