生成Code时EnvDTE或CodeDom之间有区别吗

发布于 2024-08-03 01:12:15 字数 541 浏览 3 评论 0原文

我需要使用 DSL 生成和读取一些 CS 类,我采用了一种使用 EnvDTE 读取 CS 文件的方法,而我的同事使用 CodeDom 生成 CS 文件。

它只是糖还是有很大的区别...

codeClass.AddFunction("DoSomething", vsCMFunction.vsCMFunctionFunction, "bool");

我主观上更喜欢 EnvDTE,但

     CodeMemberMethod membMethod = new CodeMemberMethod();
        membMethod.Attributes = MemberAttributes.Static;
        membMethod.ReturnType = new CodeTypeReference("bool");
        membMethod.Name = "DoSomething";

不知道“真正”的区别是什么。

信息:C#、Visual Studio 2010

I have the requirement to generate and read some CS classes with a DSL, I have adopted one method for reading the CS files using EnvDTE and my colleague has used CodeDom to produce the CS files.

Is it just sugar or is there a big difference between...

codeClass.AddFunction("DoSomething", vsCMFunction.vsCMFunctionFunction, "bool");

and

     CodeMemberMethod membMethod = new CodeMemberMethod();
        membMethod.Attributes = MemberAttributes.Static;
        membMethod.ReturnType = new CodeTypeReference("bool");
        membMethod.Name = "DoSomething";

I subjectively prefer the EnvDTE but do not know what the 'real' difference is.

Info: C#, Visual Studio 2010

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

不如归去 2024-08-10 01:12:15

使用 EnvDTE,我不确定您是否可以像使用 CodeDOM 一样操作 AST。我会使用 CodeDOM 或来自 SharpDevelop 项目的 NRefactory,这是另一个开源 C# 解析器/发电机。

Using EnvDTE, I'm not sure you can manipulate AST like you can with CodeDOM. I would go with CodeDOM, or NRefactory from SharpDevelop project, which is another open source C# parser/generator.

格子衫的從容 2024-08-10 01:12:15

CodeDOM 无法读取源代码来生成 AST。如果您需要做的只是生成 C#,那么 CodeDOM 会随 .NET 框架一起提供,因此您的应用程序不需要安装 Visual Studio。

CodeDOM does not have a way to read source code to produce an AST. If all you need to do is generate C#, then CodeDOM ships with the .NET framework and so your application would not require Visual Studio to be installed.

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