Modeling and Analyzing Code (Visual C#)
It is not uncommon for software developers to work with source code whose basic architecture is unfamiliar either because it was written by someone else, or because it was written so long ago that its original creators no longer recall completely how it works. Another common scenario is the need to understand the contents of a library that is only available in binary format. Visual C# provides the following tools to help you model, analyze, and understand types and type relationships in source code as well as in binary assemblies:
Class Designer, for visually representing inheritance and association relationships between types.
Object Browser, for examining the types, methods, and events exported by .NET Framework assemblies, and native DLLs including COM objects.
Metadata as source, for viewing type information in managed assemblies as if it were source code in your own project.
In addition to the tools listed above, Visual Studio Team System includes the Code Analysis for Managed Code tool that inspects your code for a wide variety of potential problems.
Class Designer is a graphical tool for visually modeling the relationship between types in a software application or component; you can also use it to design new types and refactor or delete existing types. The following illustration shows a simple class design:
To add a class diagram to a project, click Add New Item on the Project menu, and then click Add Class Diagram.
For more information, see.
The Object Browser enables you to view type information in both native and managed DLLs, including COM objects. Although the information you see in the Object Browser is similar to what you see in Class View, you can use Object Browser to examine any DLL on your system, not only the ones referenced in your own project. In addition, Object Browser also displays XML documentation comments for the selected type. The following illustration shows how Object Browser displays type information in binary files.
For more information, see
Metadata as Source:
The Metadata As Source feature enables you to view type information for classes in managed assemblies as if it were source code in your own project. This is a convenient way to view the signatures for all the public methods in a class at a glance when you do not have access to the actual source code.
For example, if you enter the statement System.Console.WriteLine() in the code editor, place the insertion point within Console and then right-click and select Go To Definition, you will see what looks like a source code file containing the declaration of theclass. This declaration is constructed from the metadata in the assembly using , and although it does not expose the implementation of any methods, it does show any XML documentation comments that are present.
You can also use the Metadata As Source feature by selecting a managed type in the Object Browser, and clicking Code Definition Window on the View menu.
For more information and an illustration, see.
Code Analysis for Managed Code
The code analysis for managed code tool analyzes managed assemblies and reports information such as potential security problems, and violations of the programming and design rules set forth in the Microsoft .NET Framework Design Guidelines. This information is presented as warnings. You access the tool in the Project Designer by right-clicking Properties in Solution Explorer, and selecting Open.
For more information, seeand .