
121
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Chapter 9Attributes
9
Attributes
Attributes are declarative tags that can be used to annotate types (classes, struc-
tures, etc.) or type members, thereby modifying their meaning or customizing
their behavior. The descriptive information provided by each attribute is stored as
metadata in the .NET assembly and can be extracted either at design time or at
runtime using a process called reflection.
Consider the following example that uses the
<WebMethod> attribute.
<WebMethod(Description:="Indicates number of visitors to a page")> _
Public Function PageHitCount(baseURL As String) As Integer
Ordinarily, public methods of a class can be invoked locally through an instance
of that class; they are not treated as members of a web service. The
<WebMethod>
attribute marks an ordinary class method so that it is callable over the Internet as
part of a web service. This
<WebMethod> attribute includes a single property,
Description, which provides the text that will appear on the page describing the
web service.
If attributes provide such important software features, why aren’t they simply
implemented as language elements? The answer is “flexibility.” Attributes are
stored as metadata in an assembly, rather than as part of its executable code. As
an item of metadata, the attribute describes the program ...