Specifying a type alias using CodeDom
I am dynamically generating some c# code using the CodeDom. I want to ad a type alias to the namespace.开发者_开发知识库 Something like:
namespace MyNameSpace
{
using Timer = System.Threading.Timer;
...
}
I'm able to create the namespace but do not know how to create the type alias. Code so far:
CodeCompileUnit unitCompile = new CodeCompileUnit();
CodeNamespace nsScript = new CodeNamespace("MyNamespace");
unitCompile.Namespaces.Add(nsScript);
How to add the "using Timer = System.Threading.Timer;" statement to the namespace?
You can directly use in the CodeNamespaceImport
class.
CodeNamespaceImport cd =
new CodeNamespaceImport("Timer = System.Threading.Timer");
It will generate classes like this.
using Timer = System.Threading.Timer;
I tried with VB.Net and it works. I didn't try with C#.
精彩评论