Here's what I see in Reflector:
Public Shared Function IsDate(ByVal Expression As Object) As Boolean
Dim time As DateTime
If (Expression Is Nothing) Then
Return False
End If
If TypeOf Expression Is DateTime Then
Return True
End If
Dim str As String = TryCast(Expression,String)
Return ((Not str Is Nothing) AndAlso Conversions.TryParseDate(str, (time)))
End Function
Now, the question is: if passed a Date
(VB.NET's keyword for DateTime
values), could this method ever return false?
No.
If (Expression Is Nothing)
This will never be true for a boxed value type.
If TypeOf Expression Is DateTime
This will always be true if the method is explicitly passed a Date
.
Even if TypeOf A Is B
returned false when B
is a subclass of A
(which it doesn't), you could still assume this would always return true since DateTime
, as a value type, cannot be inherited.
So you're good.
My best guess is that this code originally called IsDate
on a String
or Object
that was not strongly typed; at some point, someone must have updated the SelectedDate
property to be typed as Date
without bothering to update this validation code.