Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's what I see in <a href="http://www.red-gate.com/products/reflector/" rel="nofollow noreferrer">Reflector</a>:</p> <pre><code>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 </code></pre> <p>Now, the question is: if passed a <code>Date</code> (VB.NET's keyword for <code>DateTime</code> values), could this method ever return false?</p> <p><strong>No.</strong></p> <pre><code>If (Expression Is Nothing) </code></pre> <p>This will <strong>never</strong> be true for a boxed value type.</p> <pre><code>If TypeOf Expression Is DateTime </code></pre> <p>This will <strong>always</strong> be true if the method is explicitly passed a <code>Date</code>.</p> <p>Even if <code>TypeOf A Is B</code> returned false when <code>B</code> is a subclass of <code>A</code> (which it doesn't), you could <em>still</em> assume this would always return true since <code>DateTime</code>, as a value type, cannot be inherited.</p> <p>So you're good.</p> <p>My best guess is that this code originally called <code>IsDate</code> on a <code>String</code> or <code>Object</code> that was not strongly typed; at some point, someone must have updated the <code>SelectedDate</code> property to be typed as <code>Date</code> without bothering to update this validation code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload