Editor’s note: The following post was written by Visual C# MVP Peter Bromberg
The Visual Studio Code Map feature is designed to help developers visualize relationships in code. The need for code maps will become clear when you are writing or debugging code and need to understand code relationships, particularly when getting involved in a new or unfamiliar codebase.
Channel 9 has an excellent streaming video that covers Code Maps here: http://channel9.msdn.com/Series/Visual-Studio-2012-Premium-and-Ultimate-Overview/Visual-Studio-Ultimate-2012-Understanding-complex-code-with-Code-Map-ENU
To start out with Code Maps, I chose to index Dapper .Net 4.5, a popular micro-ORM developed by the folks at StackOverflow.com. Simply right-click on the project in Solution Explorer, and choose “Show on Code Map.”
This is the main view of the map from Dapper:
You can see that relationships between the classes become instantly clear. This can be very useful, for example, when first getting into a new codebase to get a “bird’s eye” view of how everything is related.
Below, I have expanded my utility helper class, SqlMapperUtil:
All of the methods and their interrelationships become available. When you click on a particular method a detail view including the code is shown:
When I execute my test program in Debug mode, I can click the “CodeMap” Icon right under the Main menu “help” item, and I can have a synchronized debug session with my code and the code map together:
Before this feature, we would step though our code and hope to remember how we got to a particular class and method. Now we can turn on the Code Map feature while debugging and see a synchronized view of what is happening. There are also context menus available that allow you to perform common tasks:
Of course, we still have the Dependency Graph feature from the ARCHITECTURE menu, which will generate a dependency graph of our entire solution:
The enhanced Code Map feature in Visual Studio 2013 (Ultimate) is a welcome new addition for developers. As with many advanced features, we don’t discover it’s usefulness until we actually start to use it.
About the author
Peter Bromberg is a Microsoft C# MVP since 2004, author, and UnEducator based in the Orlando Florida area. He writes mostly about .NET, formerly for eggheadcafe.com and currently at his programming blog at peterbromberg.net. Peter is an ex-jazz musician and stockbroker who dreams of being a philanthropist. Research in microeconomics has given Peter an avid interest in the study of economic and climate change trends and the design of computer algorithms to process historical data sets utilizing neural networks, including some pioneering work with historical solar output data. As a computer programmer with over 25 years of hands-on experience in designing and developing large-scale enterprise applications, he am an expert at solving business problems. In addition to blogging,Peter has participated in Code Camps and has given presentations at local .NET User Group meetings. His motto is a quote from Thelonius Monk: “Wrong is Right”.