title: How to dynamic new Anonymous Class?
body: <p>In C# 3.0 you can create anonymous class with the following syntax</p>
  
  <pre><code>var o1 = new { Id = 1, Name = "Foo" };
  </code></pre>
  
  <p>Is there a way to dynamic create these anonymous class to a variable?</p>
  
  <hr>
  
  <p>Example:</p>
  
  <pre><code>var o1 = new { Id = 1, Name = "Foo" };
  var o2 = new { SQ = 2, Birth = DateTime.Now };
  </code></pre>
  
  <hr>
  
  <p>Dynamic create Example:<br/></p>
  
  <pre><code>var o1 = DynamicNewAnonymous(new NameValuePair("Id", 1), new NameValuePair("Name", "Foo"));
  var o2 = DynamicNewAnonymous(new NameValuePair("SQ", 2), new NameValuePair("Birth", 
  DateTime.Now));
  </code></pre>
  
  <p>Beacuse I need to do:</p>
  
  <pre><code>dynamic o1 = new ExpandObject(); 
  o1."ID" = 1;    &lt;--"ID" is dynamic name
  o1."Name" = "Foo";  &lt;--"Name" is dynamic name
  </code></pre>
  
  <p>And Scene1:</p>
  
  <pre><code>void ShowPropertiesValue(object o)
  {
    Type oType = o.GetType();
    foreach(var pi in oType.GetProperties())
    {
      Console.WriteLine("{0}={1}", pi.Name, pi.GetValue(o, null));
    }
  }
  </code></pre>
  
  <p>if I call:</p>
  
  <pre><code>dynamic o1 = new ExpandObject();
  o1.Name = "123";
  ShowPropertiesValue(o1);
  </code></pre>
  
  <p>It can't show the result:</p>
  
  <pre><code>Name = 123
  </code></pre>
  
  <p>And also I how to Convert the ExpandoObject to AnonymouseType ?</p>
  
  <pre><code>Type type = o1.GetType();
  type.GetProperties();   &lt;--I hope it can get all property of o1
  </code></pre>
  
  <p>Last, I modify ShowPropertiesValue() method</p>
  
  <pre><code>void ShowPropertiesValue(object o)
  {
    if( o is static object ) &lt;--How to check it is dynamic or static object?
    {
      Type oType = o.GetType();
      foreach(var pi in oType.GetProperties())
      {
        Console.WriteLine("{0}={1}", pi.Name, pi.GetValue(o, null));
      }
    }
    else if( o is dynamic object )  &lt;--How to check it is dynamic or static object?
    {
      foreach(var pi in ??? )  &lt;--How to get common dynamic object's properties info ?
      {
        Console.WriteLine("{0}={1}", pi.Name, pi.GetValue(o, null));
      } 
    }
  }
  </code></pre>
  
  <p>How to implement DynamicNewAnonymous method or how to modify the ShowPropertiesValue()?</p>
  
  <p>My motivations is:</p>
  
  <pre><code>dynamic o1 = new MyDynamic();
  o1.Name = "abc";
  Type o1Type = o1.GetType();
  var props = o1Type.GetProperties(); &lt;--I hope can get the Name Property
  </code></pre>
  
  <p>If i can hook dynamicObject's GetType Method, and Compel convert to strongly-typed Type.
  The above Seamless code can work fine.</p>