开发者

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#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜