How to include source code location information (file/line/column) in .NET assembly?

倖福魔咒の 提交于 2019-12-11 06:47:36

问题


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.


回答1:


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.




回答2:


Your situation almost sounds like you need to somehow parse the sourcecode. Perhaps it's worth checking out DXCore from DevExpress, this can at least provide a foundation for both Graphics within Visual Studio and a parser which gives you a code DOM for all supported languages. It's also free, if you're building your own add-ins.

http://www.devexpress.com/Downloads/Visual_Studio_Add-in/DXCore/

It might not be the solution you're looking for, but it's at least worth a look if it you can leverage what it offers. There are many fairly powerful plug-ins based on this foundation. eg: http://jayflowers.com/WordPress/?p=137,



来源:https://stackoverflow.com/questions/688179/how-to-include-source-code-location-information-file-line-column-in-net-assem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!