简体   繁体   English

用于 C# 开发的 Visual Studio 加载项

[英]Visual Studio add-in for C#-development

I want to write my first Visual Studio 2010 add-in.我想编写我的第一个 Visual Studio 2010 加载项。 My aim is to create an add-in that helps to automatically generate code for things like:我的目标是创建一个加载项,帮助自动为以下内容生成代码:

  • implement superclass constructors实现超类构造函数
  • create delegation methods for composed object为组合对象创建委托方法
  • etc.等等。

Of course, in order to know what to generate, my add-in must have a knowledge of the code-file the user is going to insert generated code into.当然,为了知道要生成什么,我的加载项必须了解用户要将生成的代码插入其中的代码文件。 (classes, base-classes ...) (类,基类...)

My first thought was to use a C#-parser .我的第一个想法是使用C#-parser Is this the right way to go?这是正确的方法吗? Isn't there any .NET-Framework part, COM-Object or whatever "built-in"?没有任何 .NET-Framework 部分、COM-Object 或任何“内置”的东西吗?

Thank you in advance.先感谢您。

PS: Is noticed that CSharpCodeProvider 's class Parse() method has not been implemented by Microsoft yet. PS:注意到CSharpCodeProvider的类Parse()方法还没有被微软实现。 -_- -_-

You can get a lot of info from the MS Visual Studio Extensibility site.您可以从MS Visual Studio 扩展性站点获得大量信息。 This post from the Visual Studio blog may also get you started with dealing with the in memory code file. 这篇来自Visual Studio 博客的文章也可以帮助您开始处理内存中的代码文件。

You could start by looking at EnvDTE , which will help you browse through project files and code trees already parsed and analyzed by Visual Studio, as well as modifying them.您可以从查看EnvDTE开始,这将帮助您浏览已由 Visual Studio 解析和分析的项目文件和代码树,以及修改它们。 EnvDTE is pretty basic and error-prone (for the few times I used it). EnvDTE 非常基础且容易出错(我使用过它几次)。 Finding good in-depth tutorials is also difficult.找到好的深入教程也很困难。

If you're trying to implement such features yourself, good luck, it's definitely doable but the learning curve might be quite steep.如果您尝试自己实现这些功能,祝您好运,这绝对是可行的,但学习曲线可能非常陡峭。 Otherwise, you could have a look at ReSharper which already implements the features you're trying to code (and much more).否则,您可以查看ReSharper ,它已经实现了您尝试编写的功能(以及更多功能)。 Plus it also has a very well designed API compared to EnvDTE (although not very well documented), allowing to use its internal C# parser / analyzer.此外,与 EnvDTE 相比,它还具有设计精良的 API(虽然没有很好的文档记录),允许使用其内部 C# 解析器/分析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM