Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
programming4us
Windows 7

Visual Basic 2010 : Documenting the Source Code - Understanding XML Documents

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
8/11/2011 3:58:49 PM
One of the most common programming rules states that documenting the source code is fundamental. This is of course the truth but you have to think about the way source code is commented. Classical comments are useful to explain what code does so that you can easily remember how your code works if you need to retake it after a long time, or they can help other developers to understand your code. But this is not the only way of documenting code in .NET development. A sophisticated environment such as Visual Studio offers the IntelliSense technology that not only speeds up the way you write code but is also shows instructions on how you use objects and members. This is possible because of special kinds of comments that you can add to your code, known as XML comments. Such comments allow writing the source code documentation, explaining objects’ and members’ behavior, and also providing descriptions and examples that can be shown up by IntelliSense. But that is not all. Documenting code with XML comments is particularly important if you develop reusable compiled libraries and allow automating the process of building compiled documentation files (such as .chm files) in a similar way to the MSDN documentation.

Understanding XML Documents

XML documents are not new in Visual Basic 2010; they were first natively introduced with Visual Basic 2005. (In versions prior to 2005, XML comments were possible only via third-party add-ins.) To understand why XML documents are an essential topic, let’s take a look at a method invocation within the code editor. Figure 1 shows how IntelliSense appears on an uncommented method.

Figure 1. Uncommented members make IntelliSense unable to display useful information.

As you can see from Figure 1, IntelliSense will correctly show up, but it will just show the method name in a tooltip, without providing information on the method usage. This is because the method was not commented with XML comments. Now take a look at Figure 2 that shows how IntelliSense can provide information if the method was commented with XML comments.

Figure 2. Commented members are well described when IntelliSense shows up in the code editor.

The difference is evident. Objects and members decorated with XML comments can provide full explanation on their usage. This works in the code editor when IntelliSense shows up with both source files and with compiled executables. As mentioned at the beginning of this chapter, providing XML comments is not only useful for IntelliSense but also when you investigate objects in the Object Browser or for automating the process of building compiled documentation for your libraries. Because of this, adding XML comments to your code is something necessary in most cases, especially if you develop reusable assemblies. In the next sections you learn practical techniques for commenting the source code and getting the most out of XML comments with Visual Basic.

Enabling XML Comments

When Visual Studio builds the project output, it also creates an XML document storing all XML comments. The XML document constitutes the actual code documentation. In Visual Studio 2010 XML comments are enabled by default. Before reading this chapter, ensure that XML comments are effectively enabled in your project. To accomplish this, open My Project; select the Compile tab and, if it’s not checked, check the Generate XML Documentation file box. See Figure 3 for details.

Figure 3. Enabling Xml comments.

Behind the scenes this requires the Visual Basic compiler to be launched by Visual Studio with the /doc option, which makes the compiler also generate the XML documentation. At this point you are ready to implement XML comments in your Visual Basic code.

Other -----------------
- Microsoft Visio 2010 : Linking Data to Shapes Automatically
- Microsoft Visio 2010 : Refreshing Selected Data in Linked Diagrams & Scheduling Data Refresh
- Microsoft Excel 2010 : Building More Powerful Worksheets - Using Logical & Financial Functions
- Microsoft Excel 2010 : Building More Powerful Worksheets - Using Date & Time Functions
- Microsoft PowerPoint 2010 : Editing Comments in a Presentation
- Microsoft PowerPoint 2010 : Adding Comments to a Presentation
- Microsoft Visio 2010 : Creating New Shape Data Fields
- Microsoft Visio 2010 : Refreshing All Data in Linked Diagrams
- Microsoft Visio 2010 : Linking Diagrams to External Data
- Forwarding Events (part 2) - How to Troubleshoot Event Forwarding & How to Configure Event Forwarding in Workgroup Environments
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server