title: How can I use collection initializer syntax with ExpandoObject?
body: <p>I've noticed that the new <code>ExpandoObject</code> implements <code>IDictionary&lt;string,object&gt;</code> which has the requisite <code>IEnumerable&lt;KeyValuePair&lt;string, object&gt;&gt;</code> and <code>Add(string, object)</code> methods and so it should be possible to use the collection initialiser syntax to add properties to the expando object in the same way as you add items to a dictionary.</p>
  
  <pre><code>Dictionary&lt;string,object&gt; dict = new Dictionary&lt;string,object&gt;() 
  {
      { "Hello", "World" }
  };
  
  dynamic obj = new ExpandoObject()
  {
      { "foo", "hello" },
      { "bar", 42 },
      { "baz", new object() }
  };
  
  int value = obj.bar;
  </code></pre>
  
  <p>But there doesn't seem to be a way of doing that. Error:</p>
  
  <blockquote>
    <p>'System.Dynamic.ExpandoObject' does not contain a definition for 'Add'</p>
  </blockquote>
  
  <p>I assume this doesn't work because the interface is implemented explicitly.
  but is there any way of getting around that? This works fine,</p>
  
  <pre><code>IDictionary&lt;string, object&gt; exdict = new ExpandoObject() as IDictionary&lt;string, object&gt;();
  exdict.Add("foo", "hello");
  exdict.Add("bar", 42);
  exdict.Add("baz", new object());
  </code></pre>
  
  <p>but the collection initializer syntax is much neater.</p>