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?

Visual Studio 2013 provides tools to work with code maps that can map specific dependencies of your software.  Not only does it support the creation of the maps and using them during the development process, Visual Studio also supports using it during your ninja debugging sessions.

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
Generate the Code Map

When we do that, Visual Studio creates a code map file.

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
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
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
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
Show Containing Type

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
Show Fields This References

Referenced Fields
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
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
Select New Comment

Comment
Comment

Entities on the code map can also be flagged for followup.

Flag 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
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 https://www.linkedin.com/pub/vipul-patel/6/675/508



Related Articles

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 29, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this eSeminar, Gene Kim will discuss these survey findings and will share woeful tales of artifact management gone wrong! Gene will also share examples of how …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds