是否存在用于生成源文件的 C# 库?
可能的重复:
C# 代码生成器
例如,我想做的是:
Sourcefile sf = new SourceFile("Dog.cs");
sf.add(new Class("Dog"));
sf.Write();
获取一些文本文件,例如:
public class Dog()
{
}
我自己可以做到这一点,但想检查一下它是否已经存在。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是 System.Reflection.Emit 命名空间的用途。
开始阅读@MSDN。
这是一个 Hello World示例。
您可能想要查看
System.CodeDom< /代码>也是如此。
这是 MSDN 上的示例。
使用更适合您的代码生成需求的一种。
附言。如果您想在设计时生成代码,您可能需要使用 T4 模板。
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.