Solution Architecture


The Microsoft .NET Framework provides us with the capability to read the contents of assemblies and objects. Every assembly contains metadata, which describes an assembly’s contents in a standardized and language- independent way. An assembly is conceptually similar to a COM type library but redesigned and extended for the new .NET world. The metadata is created by the language compiler that produces the assembly. This metadata lists the properties of an assembly, such as its identity (name, version, public key, and so on), the external assemblies on which it depends, and the objects that it provides to the world. It also contains a description of each object, with its methods, properties, events, and so on. The metadata can also contain attributes, which are additional descriptive elements that modify items within an assembly. The metadata inside an assembly is shown schematically in Figure 11-1.

A .NET assembly contains metadata that describes the assembly’s contents.


Figure 11-1: Metadata inside an assembly

The .NET Framework provides us with the capability of reading the metadata from an assembly or an object. The operation of reading metadata and using its contents is known as reflection, and the system code that provides this capability is known as the .NET Reflection API. Many parts of .NET use reflection intensely. For example, the XML serialization mechanism described in Chapter 7 uses reflection to read the contents of an object (which it didn’t know about at compile time, remember) to know how to save it to an XML document. This process is shown schematically in Figure 11-2.

The .NET Reflection API allows us to read the metadata from an assembly or an object.

click to expand
Figure 11-2: XML serializer reading an object’s metadata to serialize it.

Reflection lets us examine the contents of an assembly, as shown in this chapter’s first example. It also allows us to look at the contents of an individual object, as shown in the second example in this chapter. Finally, it allows us to use this metadata to create an object and access its methods and properties, as shown in the third example of this chapter.

Reflection also allows us to examine, create, and call an individual object.




Introducing Microsoft. NET
Introducing Microsoft .NET (Pro-Developer)
ISBN: 0735619182
EAN: 2147483647
Year: 2003
Pages: 110

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