Finding class dependencies in C #

We have a C # application that uses several libraries (which we also wrote). The application depends on different libraries, and some of the libraries depend on some other libraries.

Now that it comes to testing the application, we also need to make sure that the libraries are working correctly. The problem is that the application uses only a small number of functions of these libraries. I can use something like NCover to find which library classes are actually used, but I would also like to know how these classes (through the application and different libraries) are organized - their dependency structure.

So my question is: I want to be able to run my application and then get a list of used classes organized by dependencies (that is, what calls / uses what).

Does anyone know a tool (free or not) that allows you to do this? The code is in VS2008, organized with various libraries / applications as projects.

+4
source share
4 answers

I think you will want to see:

Reflector

from Red Gate software. It is free and probably the best and most famous disassembly / debugging tool for .NET. It also has a plug-in architecture, and there is a Codeplex page, the .NET Reflector AddIns , which contains a number of very useful add-ons for this.

To view the dependencies, I think the Graph plugin should let you know what you need.

There is also a very similar (as well as a very good tool) to SourceForge called Refractor , which also displays dependency graphs.

+2
source

To follow Gergely's answer to NDepend, this tool can help do it in a smart way. Disclaimer: I am one of the developers of this tool

To achieve what you are asking for, you need to write Code Query over LINQ (CQLinq) . For example, we wrote such a request, on the one hand we have NDepend assemblies that invoke DevExpress assemblies. The CQLinq code request below matches the public DevExpress types used by NDepend, but also iteratively, it matches the internal DevExpress types used.

let devExpressTypes = Assemblies.WithNameLike("DevExpress").ChildTypes() let ndependTypes = Assemblies.WithNameLike("NDepend").ChildTypes() let publicDevExpressTypesUsed = devExpressTypes.UsedByAny(ndependTypes) let devExpressTypesUsedRec = publicDevExpressTypesUsed .FillIterative( types=> devExpressTypes.UsedByAny(types)) from t in devExpressTypesUsedRec.DefinitionDomain select new { t, depth = devExpressTypesUsedRec[t], ndependTypesUsingMe = t.TypesUsingMe.Intersect(ndependTypes) } 

Then you can export part of the result to the NDepend dependency graph :

(Note the screenshot below for the depth of the DevExpress types. A depth of zero indicates that the public DevExpress type is directly called by the NDepend type. For such DevExpress types, the NDepend types that directly use it are listed. Of 1 means that the DevExpress type is used by the type directly used by the NDepend type. and so on...)

Export matched types to the dependency graph

... and get the usage schedule of the type you are requesting:

Types usage graph

+4
source

NDepend parses the dll and shows a graph of dependencies between classes, it is a great code analysis tool (but not free). They have a trial version that you can use for several months so you can leave.

+2
source

You can try the RC release of Visual Studio 2010 Ultimate to generate dependency graphs for .NET code. You can create a graph of all your assemblies, namespaces, classes, or a combination of them, or you can use Explorer to select specific artifacts and relationships that you want to visualize:

How to create graphic documents from code : http://msdn.microsoft.com/en-us/library/dd409453%28VS.100%29.aspx#SeeSpecificSource

You can use Visual Studio Ultimate to explore relationships and organize gradient document generation in existing code. These graphs represent code elements and their relationships as a set of nodes that are linked by links or edges. You can use these graphs to help you visualize, examine, and analyze code.

How to find code using Architecture Explorer Architecture : http://msdn.microsoft.com/en-us/library/dd409431%28VS.100%29.aspx

You can select the vertical sections or “snippets” of code that you want to render using the Architecture Explorer. You can examine the source code in a Visual Studio solution or compiled managed code in .dll or .exe files. You can use Architecture Explorer to browse other domains by installing additional providers. When you find the code you want to visualize, you can generate graphs to examine the relationships in this code.

RC Download : http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=457bab91-5eb2-4b36-b0f4-d6f34683c62a .

Visual Studio 2010 Architectural Detection and Modeling Tool : http://social.msdn.microsoft.com/Forums/en-US/vsarch/threads

0
source

All Articles