是否存在用于生成源文件的 C# 库?

发布于 2024-11-27 13:23:13 字数 380 浏览 2 评论 0原文

可能的重复:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ヤ经典坏疍 2024-12-04 13:23:13

这就是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文