I’m reviewing some code in VB.net, and in a validation object they have written the following
If Not IsDate(Entity.SelectedDate) Then
ErrorList.Add(New CValidationError("MainReport", "Please select a weekend date"))
SelectedDate is of type Date. It seems to me it would be impossible to ever hit this condition. Is this true?
Here’s what I see in Reflector:
Now, the question is: if passed a
Date(VB.NET’s keyword forDateTimevalues), could this method ever return false?No.
This will never be true for a boxed value type.
This will always be true if the method is explicitly passed a
Date.Even if
TypeOf A Is Breturned false whenBis a subclass ofA(which it doesn’t), you could still assume this would always return true sinceDateTime, as a value type, cannot be inherited.So you’re good.
My best guess is that this code originally called
IsDateon aStringorObjectthat was not strongly typed; at some point, someone must have updated theSelectedDateproperty to be typed asDatewithout bothering to update this validation code.