title: How to iterate through an enumeration of KeyValuePair without knowing the type of the key and the type of the value
body: <p>Say I have a method like this:</p>
  
  <pre><code>public void Foo(object arguments)
  </code></pre>
  
  <p>and say I need to detect if the type of <code>arguments</code> is actually an enumeration. I would write something like this:</p>
  
  <pre><code>if (arguments is IEnumerable)
  </code></pre>
  
  <p>Now, let's say I need to detect if it's an enumeration of KeyValuePair (regardless of the type of the key and the type of the value). My instinct would be to write something like this:</p>
  
  <pre><code>if (arguments is IEnumerable&lt;KeyValuePair&lt;,&gt;&gt;)
  </code></pre>
  
  <p>but visual studio complains that <code>Using the generic type 'KeyValuePair&lt;TKey, TValue&gt;' requires 2 type arguments</code>.</p>
  
  <p>I also tried:</p>
  
  <pre><code>if (arguments is IEnumerable&lt;KeyValuePair&lt;object, object&gt;&gt;)
  </code></pre>
  
  <p>but it returns false if the key is anything but an object (such as a <code>string</code> for example) or if the value is anything but an object (such as an <code>int</code> for example).</p>
  
  <p>Does anybody have suggestions how I could determine if an enumeration contains KeyValuePairs regardless of the key type and the value type and if so, how can I loop through these pairs?</p>