oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button O'Reilly Book Excerpts: Programming C#

Programming C#: Attributes and Reflection

Related Reading

Programming C#
By Jesse Liberty

by Jesse Liberty

This excerpt is Chapter 18 from Programming C#, published in July 2001 by O'Reilly.

Throughout this book, I have emphasized that a .NET application contains code, data, and metadata. Metadata is information about the data -- that is, information about the types, code, assembly, and so forth -- that is stored along with your program. This chapter will explore how some of that metadata is created and used.

Attributes are a mechanism for adding metadata, such as compiler instructions and other data about your data, methods, and classes, to the program itself. Attributes are inserted into the metadata and are visible through ILDasm and other metadata-reading tools.

Reflection is the process by which a program can read its own metadata. A program is said to reflect on itself, extracting metadata from its assembly and using that metadata either to inform the user or to modify its own behavior.

In this chapter:


Intrinsic Attributes

Attribute Targets

Applying Attributes

Custom Attributes

Declaring an Attribute

Naming an Attribute

Constructing an Attribute

Using an Attribute


Viewing MetaData

Type Discovery

Reflecting on a Type

Late Binding

Reflection Emit

Dynamic Invocation with InvokeMember( )

Dynamic Invocation with Interfaces

Dynamic Invocation with Reflection Emit

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Next Pagearrow