开发者

Do C# libraries exist to generate source files? [duplicate]

This question already has answers here: 开发者_运维知识库 Closed 11 years ago.

Possible Duplicate:

C# code generator

For example, what I would like to do is something like:

Sourcefile sf = new SourceFile("Dog.cs");
sf.add(new Class("Dog"));
sf.Write();

and get some text file like:

public class Dog()
{
}

I can do this myself, but wanted to check around to see if it already existed.


That's what System.Reflection.Emit namespace is for.

Start reading @ MSDN.

Here's a Hello World example.

You might want to look into System.CodeDom as well.

Here's an example on MSDN.

Use the one that better suits your code generation needs.

PS. If you want to generate code at design time you might want to use T4 templates.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜