views:

265

answers:

2

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.

A: 

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.

John Saunders
Yeap. Sparx EA is great, but i need my own case tool. And what i'm not able to provide from this point is the connection between my model elements and source code.I do understand that a class maybe partial and a method and other hard stuff, but i need to do it somehow.Thanx for your reply.
Jan Pavlik
I was suggesting that you create your tool from theirs...
John Saunders
A: 

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,

Brendan Kowitz
Thanx. I'll take a look at it.
Jan Pavlik