tags:

views:

60

answers:

0

The msdn documentation says add namespaces imports to the CodeNamespace.Imports collection. This puts them inside the namespace (which makes sense, since your adding them to the namespace)

namespace Foo
{
  using Bar;

  //Code
}

However the rest of our code base has using statements outside the namespace:

using Bar;

namespace Foo
{
  //Code
}

Is there a clean way to get CodeDom to emit the second version?

Edit: the code to produce the first example looks something like this:

CodeNamespace ns = new CodeNamespace("Foo");
ns.Imports.Add(new CodenamespaceImport("Bar"));
CodeCompileUnit cu = new CodeCompileUnit();
cu.Namespaces.Add(ns);
new CSharpCodeProvider().GenerateCodeFromCompileUnit(cu, Console.Out, null);