如何在.NET程序集中包含源代码位置信息(文件/行/列)?
我需要能够从 .NET 程序集获取源文件中的类/结构/接口定义位置(文件名、begin_line、begin_column、end_line、end_column)。
我想到的第一个解决方案是使用一些 pdb 查询 api,但似乎我只能通过这种方式获取此类信息用于方法定义。 或者也许我错了......
为了提供上下文,我试图构建一个 VS 2008 的插件,它通过 VS 自动化模型编译所有解决方案项目,获取程序集并使用 Reflections 进行一些可视化建模表示。 我需要的是源代码和模型元素之间的连接。 事实上,我什至可以以某种方式分析/修改源,让他们记住位置信息。
任何想法,将不胜感激。
I need to be able to get from .NET assembly a class/struct/interface definition location (filename,begin_line,begin_column,end_line,end_column) in my source files.
First solution that came to my mind was using some pdb quering api, but it seems that I can obtain such info only for method definition this way. Or maybe I'm wrong...
To provide the context, i'm trying to build an add-in to VS 2008 which compiles all solution projects through VS automation model, takes assemblies and using Reflections makes some visual modeling representation. What i need is a connection between source code and model elements. In fact i could even analyze/modify sources in some way to make them remember the location info.
Any ideas would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设现有的类图对您没有帮助,并且您不能使用已经知道如何对 C# 进行逆向工程的工具? 我想到了Sparx Enterprise Architect,因为它不仅可以进行逆向工程 - 它还可以运行用户定义的由此产生的模型的转换。 您应该能够从中生成您想要的任何内容,无论是在模型方面还是在工件方面。
您还需要考虑一个类可能是部分的 - 同一类可能存在于多个部分中。
I'm assuming that the existing Class Diagram does not help you, and that you cannot use a tool that already knows how to reverse-engineer C#? Sparx Enterprise Architect comes to mind because it can not only do the reverse engineering - it can also run user-defined transformations of the resulting models. You should be able to generate anything you want out of that, both in terms of model and in terms of artifacts.
You'll also want to consider that a class may be partial - the same class may exist in several pieces.