Summary

   


This chapter discussed three vaguely related subjects processor directives, XML documentation, and attributes. Whereas most of the important aspects of processor directives were presented, the XML documentation and attributes discussions were only introductory. A review of the most important points mentioned in this chapter follows.

Preprocessor directives can be used to mark parts of the source code for the compiler to treat these parts in a special way. Preprocessor directives are commonly used to exclude source code from being compiled; this is especially handy for testing purposes. In general, they allow you to produce different versions of a program from the same source code just by defining or undefining one or more identifiers.

A few of the preprocessor directives are used for purposes other than excluding source code from the compilation process. Instead, these directives can make the compiler report warnings and errors, mark regions of a program to be recognized by a C# editor, or change the line numbers used by the compiler.

Whereas standard source code comments must be read together with the source code, program documentation is viewed separately and independently from the source code.

The C# compiler can automatically extract XML documentation for your program from documentation comments you insert into the source code. Like standard comments, the compiler otherwise ignores the documentation comments.

A documentation comment starts with three forward slashes /// and consists of XML tags and descriptive text. The compiler recognizes 16 XML tags, but you can expand this number with your own tags.

An attribute allows you to add declarative information to C#'s code elements (assemblies, classes, structs, class and struct members, formal parameters, and return values). Declarative information is highly expressive.

The .NET Framework contains many predefined attributes that can be used for many different purposes. You can also define your own predefined attributes. Any attribute, whether intrinsic or custom designed, must be a subclass of the abstract class System.Attribute.

The additional information provided by an attribute on its target element is stored as part of that element's metadata. This metadata can be viewed through a process called reflection.


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net