Chapter 11. Reflection and Code Attributes

IN BRIEF

Managed code written for the .NET Framework is always accompanied by various kinds of metadata. This metadata controls everything from defining the list of referenced assemblies that an application needs to run properly, to simpler information such as the product version, product name, and so on.

This metadata is stored on disk, but it is also available to managed code at runtime. While the managed code is running, it can, at any time, make queries against the metadata associated with it. In addition to this metadata, type information including class definitions, members, properties, attributes, and instance data is also available.

The mechanism that makes all of this available is called reflection. Reflection allows managed code to not only inspect metadata about itself, but also about any other code that might be running at the same time. This chapter will show you how to use reflection to discover type and metadata information at runtime, and how to use custom code attributes to create your own runtime-discoverable metadata about your code.

WHAT YOU NEED

RECOMMENDED SOFTWARE.NET Framework SDK v1.1 Visual Studio .NET 2003 with C# installed
RECOMMENDED HARDWAREPC that meets .NET SDK minimum requirements
SKILLS REQUIREDC# and .NET familiarity

REFLECTION AND CODE ATTRIBUTES AT A GLANCE

Working with Reflection228  
 Introduction to Reflection229Discovering Type Information at Runtime229
 How Reflection Works229
Using Code Attributes234  
 Introduction to Code Attributes234Creating Custom Attributes236
 Using Code Attributes235Querying Custom Attributes238
Summary241  
Further Reading241  

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.30.193