title: Read value of dynamically-selected property, e.g. (ListItem.Value/.Text)
body: <p>I have seen lots of <em>seemingly</em> related questions on SO, but my understanding of Reflection isn't sufficient enough to apply those to my case.</p>
  
  <p>I have a method that sorts ListControl.ListItems by either Text or Value.  Rather than sort alphanumerically, the objects must be cast as Doubles, and then sorted, e.g.</p>
  
  <pre><code>&lt;asp:ListItem Value="1.1" Text="1.1" /&gt;
  &lt;asp:ListItem Value="3.4" Text="3.4" /&gt;
  &lt;asp:ListItem Value="10.587" Text="10.587" /&gt;
  </code></pre>
  
  <p>My entire approach may be wrong, but my method first checks to see if any objects are not numeric.  If a potential error is found (non-parseable value)  then the method falls back to alphanumeric sorting:</p>
  
  <pre><code>Public Enum SortBy
      Value
      Text
  End Enum
  
  Public Shared Sub SortListItemsNumerically(lc As ListControl, sortby As SortBy)
      Dim parseFail As Boolean = False
      Select Case sortby
          Case SortBy.Value
              If (From li As ListItem In lc.Items
                  Where Not IsNumeric(li.Value)
                  Select li).ToArray().Count &gt; 0 Then
                  parseFail = True
              End If
          Case SortBy.Text
              If (From li As ListItem In lc.Items
                  Where Not IsNumeric(li.Text)
                  Select li).ToArray().Count &gt; 0 Then
                  parseFail = True
              End If
      End Select
      If parseFail Then
          ' ... fall back
      End If
      ' ... do sort 
  End Sub
  </code></pre>
  
  <p>My issue is that there is repetitive code in the <code>Case</code> block.  Is it possible to <em>dynamically/smartly</em> check for a non-parseable value, to avoid that duplication of code?  Something such as:</p>
  
  <pre><code>Dim SomeMagicHere = li.Value/Text
  If (From li As ListItem In lc.Items
       Where Not IsNumeric(SomeMagicHere)
       Select li).ToArray().Count &gt; 0 Then
       parseFail = True
  End If
  </code></pre>