title: Testing if an Object is a Dictionary in C#
body: <p>Is there a way to test if an object is a dictionary?</p>
  
  <p>In a method I'm trying to get a value from a selected item in a list box.  In some circumstances, the list box might be bound to a dictionary, but this isn't known at compile time.</p>
  
  <p>I would like to do something similar to this:</p>
  
  <pre><code>if (listBox.ItemsSource is Dictionary&lt;??&gt;)
  {
      KeyValuePair&lt;??&gt; pair = (KeyValuePair&lt;??&gt;)listBox.SelectedItem;
      object value = pair.Value;
  }
  </code></pre>
  
  <p>Is there a way to do this dynamically at runtime using reflection?  I know it's possible to use reflection with generic types and determine the key/value parameters, but I'm not sure if there's a way to do the rest after those values are retrieved.</p>