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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds