开发者

Specifying a type alias using CodeDom

开发者 https://www.devze.com 2023-02-10 09:57 出处:网络
I am dynamically generating some c# code using the CodeDom.I want to ad a type aliasto the namespace.开发者_开发知识库Something like:

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

精彩评论

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