title: Iterating over dictionary obtained through reflection
body: <p>So I have this code which is supposed to recursively print all the properties and their content of a given object.</p>
  
  <pre><code>static public void PrintProperties(object obj, int indent)
  {
      if (obj == null) return;
      string indentString = new string(' ', indent);
      Type objType = obj.GetType();
      PropertyInfo[] properties = objType.GetProperties();
      foreach (PropertyInfo property in properties)
      {
          object propValue = property.GetValue(obj, null);
          if (property.PropertyType.Assembly == objType.Assembly &amp;&amp; !property.PropertyType.IsEnum)
          {
              Console.WriteLine("{0}{1}:", indentString, property.Name);
              PrintProperties(propValue, indent + 2);
          }
          else
          {
              if (null != propValue)
              {
                  Type t = propValue.GetType();
                  //Console.WriteLine(":::::{0}:::::", propValue.GetType());
                  bool isDict = t.IsGenericType &amp;&amp; t.GetGenericTypeDefinition() == typeof(Dictionary&lt;,&gt;);
                  if (isDict)
                  {
                      Type keyType = t.GetGenericArguments()[0];
                      Type valueType = t.GetGenericArguments()[1];
                      foreach (KeyValuePair&lt;keyType, valueType&gt; kvp in (Dictionary&lt;keyType, valueType&gt;)propValue)
                      {
                          Console.WriteLine(string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value));
                      }
                  }
              }
  
              Console.WriteLine("{0}{1}: {2}", indentString, property.Name, propValue);
          }
      }
  }
  </code></pre>
  
  <p>It doesn't work for <code>List</code> and <code>Dictionary</code> yet, I'm working on the <code>Dictionary</code> part right now.</p>
  
  <p>Problem is, I extract the type of the key and value with:</p>
  
  <pre><code>Type keyType = t.GetGenericArguments()[0];
  Type valueType = t.GetGenericArguments()[1];
  </code></pre>
  
  <p>But then VS2013 tells me that there is a problem with this line:</p>
  
  <pre><code>foreach (KeyValuePair&lt;keyType, valueType&gt; kvp in (Dictionary&lt;keyType, valueType&gt;)propValue)
  </code></pre>
  
  <p>It tells me that the type or namespace KeyType and valueType are not found.
  What am I missing?</p>
  
  <p>Thanks.</p>
  
  <p>PS : .net 4.5.1</p>