CodeModelMacros Sample: Demonstrates How to Use the Code Model Functions
This sample is a collection of macros that use the Code Model to perform useful tasks. The macros included are:
HierarchyGenerator Generates an HTML file with an inheritance tree for the classes, structs, and interfaces in a project.
This macro first assembles a collection of the terminal classes, structs, or interfaces (those that don't have any derived types). It does this by verifying that no other code element has the class, struct, or interface in question in its bases collection. Then it generates an HTML report listing the terminal objects with all of its bases. The macro adds this file to the first project in the solution.
InterfaceDocGenerator Generates HTML documentation for the implemented interfaces in a project. It gathers the comments from the class functions that implement the interface methods.
This macro enumerates the interfaces contained in the CodeModel.Interfaces collection, and then it finds the classes that implement each interface. For each class, it looks up the interface's methods implementation and stores the comments in an HTML file.
UserTypeGenerator Generates a file named usertype.dat containing the names of the classes in your project. If you place this file in the same location where devenv.exe resides (for example, c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE), the source code editor will colorize your class names.
This macro writes to a file (usertype.dat) the names of the classes contained in the CodeModel.Classes collection.
VirtualFunctionFinder Adds a TODO comment to the virtual functions found in the project.
The VirtualFunctionFinder finds the virtual functions declared in the project by recursively verifying the functions of each class or struct. Then it adds a comment to each one by changing the CodeFunction.Comment property.
Security Note |
---|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
- For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
Installing and Running the Sample
To install the macros
Copy the file CodeModelMacros.vsmacros to your hard drive.
Start Visual Studio.
From the Tools menu, point to Macros and then click Macro Explorer. This will open the Macro Explorer window.
From the Tools menu, point to Macros and then click Load Macro Project. This will open the Add Macro Project dialog box.
Browse to the CodeModelMacros.vsmacros file and click the Open button. This action will load the macros file and the macros will appear in the Macro Explorer.
Expand the CodeModelMacros node. You will see one module for each macro.
To execute HierarchyGenerator
Expand the HierarchyGenerator node in the Macro Explorer.
Double-click the HierarchyGenerator macro. This will execute the macro and add an HTML file to the first project in your solution.
To execute InterfaceDocGenerator
Expand the InterfaceDocGenerator node in the Macro Explorer.
Double-click the InterfaceDocGenerator macro. This will execute the macro and add an HTML file to the first project in your solution.
To execute UserTypeGenerator
Expand the UserTypeGenerator node in the Macro Explorer.
Double-click the UsertypeC macro. This will execute the macro and will create a usertype.dat file in the root directory of your C: drive.
To execute VirtualFunctionFinder
Expand the VirtualFunctionFinder node in the Macro Explorer.
Double-click the MainVirtualFunctionFinder macro. This will execute the macro and will add a TODO comment to the virtual functions declared in your project.
Keywords
This sample demonstrates the following keywords:
CodeClass::Members; CodeElement::CodeTypeFromFullName; CodeElement::Children; CodeElement::FullName; CodeElement::Kind; CodeFunction::CanOverride; CodeFunction::Comment; CodeFunction::InfoLocation; CodeFunction::Name; CodeInterface::Name; CodeModel::CodeElements; CodeModel::Language; CodeNamespace::Members; CodeStruct::Members; CodeType::Bases; Project::CodeModel; Solution::Count; VCCodeBase::FullName; VCCodeBase::Name; VCCodeClass::Functions; VCCodeClass::ImplementedInterfaces; VCCodeClass::IsSelf; VCCodeClass::Name; VCCodeFunction::Attributes; VCCodeFunction::Comment; VCCodeFunction::IsVirtual; VCCodeInterface::Functions; VCCodeModel::Classes; VCCodeModel::Interfaces