title: Building Dictionaries with CodeDom
body: <p>I'm trying to figure out a way to build something like this using CodeDom</p>
  
  <pre><code>public System.Collections.Generic.Dictionary&lt;string, string&gt; Attributes
  {
      get
      {
          return new System.Collections.Generic.Dictionary&lt;string, string&gt;()
          {
              {"firstkey", "first value"},
              {"second", "second value"},
              {"third", "third value"}
          };
      }
  }
  </code></pre>
  
  <p>I did read this but it didn't really get me where I wanted to, <a href="http://msdn.microsoft.com/en-us/library/system.codedom.codetypeparameter.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.codedom.codetypeparameter.aspx</a></p>
  
  <p>I did this</p>
  
  <pre><code>Type myType = typeof (System.Collections.Generic.Dictionary&lt;string, string&gt;);
  string dictionaryTypeName = myType.FullName;
  
  CodeTypeReference dictionaryType = new CodeTypeReference(dictionaryTypeName);
  
  var abc = new CodeVariableDeclarationStatement(
      dictionaryType, "dict2",
      new CodeObjectCreateExpression(
          dictionaryType, new CodeSnippetExpression(@"{""firstkey"", ""first value""}")
          )
      );
  
  property.GetStatements.Add(abc);
  </code></pre>
  
  <p>It generates this</p>
  
  <pre><code>public Dictionary&lt;object, object&gt; Attributes
  {
      get
      {
          Dictionary&lt;string, string&gt; dict2 = new Dictionary&lt;string, string&gt;({"firstkey", "first value"});
      }
  }
  </code></pre>
  
  <p>Anyone who built something similar?</p>