Import namespaces in a CodeSnippetCompileUnit
===

When using a CodeCompileUnit to generate code via the CodeDOM, you can import namespaces by creating a CodeNamespace separate from the namespace in which you're defining your type(s).  Using the Imports property allows you to add the namespaces you desire.  If you add the CodeNamespace to the CodeCompile unit, the imports will appear at the top of the file generated by the CodeDOM.

For instance, using a CSharpCodeProvider to compile the following CodeDOM graph:

    CodeCompileUnit compileUnit = new CodeCompileUnit();
    CodeNamespace importsNamespace = new CodeNamespace {Imports = {new CodeNamespaceImport("System"), new CodeNamespaceImport("System.Collections.Generic"), new CodeNamespaceImport("System.Linq")}};
    CodeNamespace typeNamespace = new CodeNamespace("MyTypeNamespace");
    compileUnit.Namespaces.Add(importsNamespace);
    compileUnit.Namespaces.Add(typeNamespace);

will generate

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.269
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace MyTypeNamespace {

    }

The CodeSnippetCompileUnit allows you to compile type definitions which have been entered as a string.  For instance, the string "public class TestClass {}" can be used as the Value for a CodeSnippetCompileUnit.  Using the same code as above with a CodeSnippetCompileUnit:

    const string testClassCodeString = "public class TestClass {}";
    CodeSnippetCompileUnit snippetCompileUnit = new CodeSnippetCompileUnit {Value = testClassCodeString};
    CodeNamespace importsNamespace = new CodeNamespace {Imports = {new CodeNamespaceImport("System"), new CodeNamespaceImport("System.Collections.Generic"), new CodeNamespaceImport("System.Linq")}};
    CodeNamespace typeNamespace = new CodeNamespace("MyTypeNamespace");
    compileUnit.Namespaces.Add(importsNamespace);
    compileUnit.Namespaces.Add(typeNamespace);

will generate a file which contains only:

    public class TestClass {}

How can you enclose this type in a namespace, or import namespaces to the file generated from a CodeSnippetCompileUnit?