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


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.


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.


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.


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,

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »