How to Use Code Maps in Visual Studio 2013
Introduction
Can you remember any time in your development career when you did not have your piece of code worked with the solution your team was building? Think hard. Do you recall any such incidence? I can bet you will have a hard time coming up with one.
Now, think again about the various tools you used to maintain this map. Word document, Visio diagrams, UML diagrams, others?
Requirements
Code maps can be created only with the Ultimate version of Visual Studio 2013. You can also open and view code maps with the other flavors of Visual Studio 2013.
How to Create Code Maps During Development Time
Consider a sample code project (one is available to download below). The solution contains two projects – one console application and one library that the application references.
// Code of ConsoleApplication2 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { ClassLibrary1.Class1 myClass; static void Main(string[] args) { Program myProg = new Program(); myProg.myClass = myProg.InitializeLibrary(); myProg.CallMethod(); } ClassLibrary1.Class1 InitializeLibrary() { return new ClassLibrary1.Class1(); } void CallMethod() { this.myClass.MyMethod(); } } }
Code of ClassLIbrary1.Class1.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class Class1 { public void MyMethod() { throw new Exception(); } } }
Go to any function in the project and right click on the function name and select Show on Code Map to generate the code map.
Generate the Code Map
When we do that, Visual Studio creates a code map file.
Code Map File
We can select the method on the code map and select to display all methods that that function references.
Display All Methods that the Function References
Since the Exception class is external to the solution, it will be shown as External.
Exception Class Shown as External
We can also show all references to that function, but right-clicking on the function name and selecting “Find all references”.
Find All References
We can also select to show the containing type, which will cause the code map to show the Class in which the method resides.
Show Containing Type
Containing Type
We can also show fields that are referenced by a function. For example, right click on CallMethod and select “Show Fields This References”.
Show Fields This References
Referenced Fields
If we play with the Code maps feature a bit more, we will end up with a very comprehensive representation of our code, as shown below.
Representation of Our Code
Besides representing the map, the feature also supports collaborative development by supporting comments.
Right click any area/object in the code map and select “New comment”.
Select New Comment
Comment
Entities on the code map can also be flagged for followup.
Flag for Followup
Code Maps During Debugging
During debugging, code maps help us understand the path that has been traversed. Consider the following scenario: We are within the CallMethod function.
Code Map
We can see that the code map shows the path that has been exercised leading up to the breakpoint in red. It also shows the current method in Yellow.
As we can see from the above walkthroughs, code maps help developers immensely during development time as well as during debugging.
Summary
In this article, we learned about the basics of code maps and how to use them in Visual Studio 2013.
About the Author
Vipul Patel is a technology geek based in Seattle. He can be reached at vipul.patel@hotmail.com . You can visit his LinkedIn profile at
There are no comments yet. Be the first to comment!