G
Guest
I have a generic function I am using to check constraints, an example of
which is the following:
Public Function ValidateMinValue(Of t As IComparable)(ByVal PropertyName As
String, ByVal value As t, ByVal min As t) As Boolean
Dim newMessage As String = String.Empty
If value.CompareTo(min) < 0 Then
newMessage = String.Format("{0} must not be less then {1}, please
enter a valid value.", PropertyName, min)
' Add the message to the validation list
AddValidationError(PropertyName, newMessage)
Return False
Else
Return True
End If
End Function
I have 2 'Nullable(Of DateTime)' variables - DateReceived and DateDeposited.
When I attempt to call the function:
ValidateMinValue("Date Deposited", DateDeposited.Value, DateReceived.Value)
both Date arguments are flaged saying that:
"A value of type 'Date' cannot be converted to 'T'.
but of course, Date (DateTime) implements IComparable.
also, if I make the following change:
dim d1 as DateTime = DateDeposited.Value
dim d2 as DateTime = DateReceived.Value
ValidateMinValue("Date Deposited", d1, d2)
there are no errors. Not sure why this is necessary.
An explaination would be appreciated.
which is the following:
Public Function ValidateMinValue(Of t As IComparable)(ByVal PropertyName As
String, ByVal value As t, ByVal min As t) As Boolean
Dim newMessage As String = String.Empty
If value.CompareTo(min) < 0 Then
newMessage = String.Format("{0} must not be less then {1}, please
enter a valid value.", PropertyName, min)
' Add the message to the validation list
AddValidationError(PropertyName, newMessage)
Return False
Else
Return True
End If
End Function
I have 2 'Nullable(Of DateTime)' variables - DateReceived and DateDeposited.
When I attempt to call the function:
ValidateMinValue("Date Deposited", DateDeposited.Value, DateReceived.Value)
both Date arguments are flaged saying that:
"A value of type 'Date' cannot be converted to 'T'.
but of course, Date (DateTime) implements IComparable.
also, if I make the following change:
dim d1 as DateTime = DateDeposited.Value
dim d2 as DateTime = DateReceived.Value
ValidateMinValue("Date Deposited", d1, d2)
there are no errors. Not sure why this is necessary.
An explaination would be appreciated.