C# Call Graph Generation Tool - c#

I just got a heaping pile of (mostly undocumented) C# code and I'd like to visualize it's structure before I dive in and start refactoring. I've done this in the past (in other languages) with tools that generate call graphs.
Can you recommend a good tool for facilitating the discovery of structure in C#?
UPDATE
In addition to the tools mentioned here I've seen (through the tubes) people say that .NET Reflector and CLR Profiler have this functionality. Any experience with these?

NDepend is pretty good at this. Additionally Visual Studio 2008 Team System has a bunch of features that allow you to keep track of cyclomatic complexity but its much more basic than NDepend. (Run code analysis)

Concerning NDepend, it can produce some usable call graph like for example:
The call graph can be made clearer by grouping its method by parent classes, namespaces or projects:
Find more explanations about NDepend call graph here.

It's bit late, but http://sequenceviz.codeplex.com/ is an awesome tool that shows the caller graph/Sequence diagram. The diagrams are generated by reverse engineering .NET Assemblies.

As of today (June 2017), the best tool in class is Resharper's Inspect feature. It allows you to find all incoming calls, outgoing calls, value origin/destination, etc.
The best part of ReSharper, compared to other tools mentioned above: it's less buggy.

I've used doxygen to some success. It's a little confusing, but free and it works.

Visual Studio 2010.
Plus, on a method-by-method basis - Reflector (Analyzer (Ctrl+R); "Depends On" and "Used By")

SequenceViz and DependencyStructureMatrix for Reflector might help you out: http://www.codeplex.com/reflectoraddins

I'm not sure if it will do it over just source code, but ANTS Profiler will produce a call graph for a running application (may be more useful anyway).

Related

Is there a tool which analyses which functions call which functions for C#?

For a large porting from VB6 to C# job I wrote a tool which uses a murder of regular expressions to analyse a VB6 code base and extract the dependencies of all the functions in all the forms, bas files and classes.
It allowed us to chop out blocks of code for the developers, generate graphs and extract all the SQL.
I could really use something that does the same thing for C# and although it would be a lot easier for C#, I don't have the time or budget to write it.
We are limited to VS2008
Does anything like this already exist?
I'm not sure but I think NDepend has this. If not, writing it yourself should be pretty straight forward using Roslyn or NRefactory
If you take a look on project Roslyn page, you'll find example which will show you about 70% of what you seem to try to achive.
Walkthrough: Getting Started with Semantic Analysis – C#
It seems you are doing some kind of "refactoring". I found ReSharper is most useful in this case http://www.jetbrains.com/resharper/

Tool to detect missing disposes

im searching for any tool that can detect any missing dispose calls on classes that do data access and file operations. And if it checks another performance issues it will be nice.
BTW, i need to run the tool over the code, not on the execution. Thanks!
DevExpress CodeRush does this for you:
see this article: Code Issues – Undisposed local
Code Rush home: DevExpress CodeRush
I have used the express version of this tool and personally I like it more than ReSharper.
The open-source Gendarme tool provides several rules wrt IDisposable.
disclaimer: I'm Gendarme's maintainer.
If you prefer a free utility, FxCop does this.

Visual Studio add-in for C#-development

I want to write my first Visual Studio 2010 add-in. My aim is to create an add-in that helps to automatically generate code for things like:
implement superclass constructors
create delegation methods for composed object
etc.
Of course, in order to know what to generate, my add-in must have a knowledge of the code-file the user is going to insert generated code into. (classes, base-classes ...)
My first thought was to use a C#-parser. Is this the right way to go? Isn't there any .NET-Framework part, COM-Object or whatever "built-in"?
Thank you in advance.
P.S: Is noticed that CSharpCodeProvider's class Parse() method has not been implemented by Microsoft yet. -_-
You can get a lot of info from the MS Visual Studio Extensibility site. This post from the Visual Studio blog may also get you started with dealing with the in memory code file.
You could start by looking at EnvDTE, which will help you browse through project files and code trees already parsed and analyzed by Visual Studio, as well as modifying them. EnvDTE is pretty basic and error-prone (for the few times I used it). Finding good in-depth tutorials is also difficult.
If you're trying to implement such features yourself, good luck, it's definitely doable but the learning curve might be quite steep. Otherwise, you could have a look at ReSharper which already implements the features you're trying to code (and much more). Plus it also has a very well designed API compared to EnvDTE (although not very well documented), allowing to use its internal C# parser / analyzer.

Is there anyway to trace all classes and interfaces used or referenced in a C# project?

I have a huge cryptography solution that has way more than what we need. I need some way of debugging the program and keeping track of each class that was called after running my main() method. Any tips? Right now I'm attepting to hold down F11 and go through all the classes that opened up one by one and manually check what was called. Not what I want to do. I'm stripping out everything that wasn't needed afterwards for memory leak, performance, and size reasons. It's open source code. Visual Studio 2008
Dottrace should do the trick for you. It has a really handy way of profiling any running .NET code and spitting out an easy-to-consume report. I highly recommend the tool (it's also good for what it's designed for - performance & memory profiling). This sounds like an ad, but I have nothing to do with the company. I just love the app.
You can use the .NET Reflector tool. Also this is a built-in feature in Visual Studio 2010.
Tracing has always been the default showcase for AOP.
PostSharp: http://www.sharpcrafters.com/aop.net

Incremental .NET code coverage tool?

I'm looking for a tool (preferably free) that analyzes incremental code coverage of our C# solution. What I mean by this is that I don't want to know what the total code coverage is for all code or even for a namespace, but only new lines of code or perhaps lines of code that changed since the last checkin. (We use subversion for source control.)
I would like to call this tool as part of our automated build process and report back when someone checks in new code with less than X% code coverage.
Does anyone know of a tool that accomplishes this?
Thanks.
NDepend boasts the following:
NDepend gathers code coverage data from NCover™ and Visual Studio Team System™. From this
data, NDepend infers some metrics on methods, types, namespaces and assemblies :
PercentageCoverage, NbLinesOfCodeCovered, NbLinesOfCodeNotCovered and BranchCoverage
(from NCover only).
These metrics can be used conjointly with others NDepend features. For example you can
know what code have been added or refactored since the last release and is not thoroughly
covered by tests. You can write a CQL constraint to continuously check that a set of
classes is 100% covered. You can list which complex methods need more tests.
I seem to recall NDepend being able to compare with data from earlier builds, so it looks like the combination of NDepend and NCover might do the trick. Haven't tried it myself though. .)
Depending on the version of .Net you can use NCover for free. However if you are on the newer versions of .net it's not so cheap. You would probably still have to write your own stylesheet to parse the results of NCover to get specifically what you are asking.
Other than that I have not heard or seen of another tool to do this unless you wanted to write it yourself.
NCover basically uses the .Net Profiling API so in theory you could just do the same.
I use PartCover to analyse my unit tests for good effect. For the data you're looking for, you can use the console tool and extract the visit and len counts from the report xml.
In addition to the Rythmis answer, I provide this blog post that explains in detail how NDepend coupled with NCover or VSTS coverage answers the question:
Are you sure added and refactored code is covered by tests?

Categories