title: Convert Dictionary<string, object> to class and subclass
body: <p>How do I convert a Dictionary to class and subclasses recursively?
  These are my classes:</p>
  
  <pre><code>public class UiItem
  {
      public string id { get; set; }
      public string text { get; set; }
      public Rect rect { get; set; } 
  }
  
  public class Rect
  {
      public int height { get; set; }
      public int width { get; set; }
      public int y { get; set; }
      public int x { get; set; }
  }
  </code></pre>
  
  <p>I wrote this, but i don't know how create object <code>Rect</code> in class <code>UiItem</code>:</p>
  
  <pre><code>public static T GetObject&lt;T&gt;(this Dictionary&lt;string, object&gt; dict)
      {
          Type type = typeof(T);
          var obj = Activator.CreateInstance(type);
  
          foreach (var kv in dict)
          {
              var prop = type.GetProperty(kv.Key);
              object value = kv.Value;
              if (kv.Value.GetType() == typeof(Dictionary&lt;string, object&gt;))
              {
                  value = GetObject&lt;_???_&gt;((Dictionary&lt;string, object&gt;) value) // &lt;= This line
              }
  
              if(prop == null) continue;
              prop.SetValue(obj, value, null);
          }
          return (T)obj;
      }
  </code></pre>