title: Instantiating a non-primitive type with CodeDom
body: <p>I'm trying to use CodeDom to instantiate an instance of System.Drawing.Font but I can't work out how to create a new type, specifically for the FontFamily and FontStyle parameters.</p>
  
  <p>If I execute the following code:</p>
  
  <pre><code>CodeExpression[] parms = new CodeExpression[3];
  
  parms[0] = new CodePrimitiveExpression(((System.Drawing.Font)value).FontFamily.Name);
  parms[1] = new CodePrimitiveExpression(((System.Drawing.Font)value).Size);
  parms[2] = new CodePrimitiveExpression(((System.Drawing.Font)value).Style);
  
  codeObjectCreateExpression = new CodeObjectCreateExpression("System.Drawing.Font", parms);
  </code></pre>
  
  <p>I get an error </p>
  
  <blockquote>
    <p>Invalid Primitive Type: System.Drawing.FontStyle. Consider using CodeObjectCreateExpression.</p>
  </blockquote>
  
  <p>From reading around, I know I have to use <code>CodeObjectCreateExpression</code> to create an instance of a type, but I'm unsure how to assign <a href="http://msdn.microsoft.com/en-us/library/system.codedom.codeprimitiveexpression.aspx" rel="nofollow">anything apart from primitives </a> to it. </p>