15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

❘<br />

What are assemblies 433<br />

The second example shows a single assembly spread across three files (see Figure 18-2). Component.dll<br />

has assembly metadata, type metadata, <strong>and</strong> MSIL code, but no resources. The assembly uses a picture from<br />

picture.jpeg that is not embedded inside Component.dll, but is referenced from within the assembly<br />

metadata. The assembly metadata also references a module called util.netmodule, which itself includes<br />

only type metadata <strong>and</strong> MSIL code for a class. A module has no assembly metadata; thus, the module itself<br />

has no version information. It also cannot be installed separately. All three files in this example make up<br />

a single assembly; the assembly is the installation unit. It would also be possible to put the manifest in a<br />

different file.<br />

Component.dll<br />

Util.netmodule<br />

Assembly<br />

Metadata<br />

Type Metadata<br />

Type Metadata<br />

IL Code<br />

IL Code<br />

Picture.jpeg<br />

Resource<br />

figure 18-2<br />

assembly manifests<br />

An important part of an assembly is a manifest, which is part of the metadata. It describes the assembly<br />

with all the information that’s needed to reference it <strong>and</strong> lists all its dependencies. The parts of the manifest<br />

are as follows:<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Identity — Name, version, culture, <strong>and</strong> public key.<br />

A list of files — Files belonging to this assembly. A single assembly must have at least one file but may<br />

contain a number of files.<br />

A list of referenced assemblies — All assemblies used from the assembly are documented inside the<br />

manifest. This reference information includes the version number <strong>and</strong> the public key, which is used to<br />

uniquely identify assemblies. The public key is discussed later in this chapter.<br />

A set of permission requests — These are the permissions needed to run this assembly. You can find<br />

more information about permissions in Chapter 21, “Security.”<br />

Exported types — These are included if they are defined within a module <strong>and</strong> the module is referenced<br />

from the assembly; otherwise, they are not part of the manifest. A module is a unit of reuse. The type<br />

description is stored as metadata inside the assembly. You can get the structures <strong>and</strong> classes with the<br />

properties <strong>and</strong> methods from the metadata. This replaces the type library that was used with COM to<br />

describe the types. For the use of COM clients, it’s easy to generate a type library from the manifest.<br />

The reflection mechanism uses the information about the exported types for late binding to classes.<br />

See Chapter 14, “Reflection,” for more information about reflection.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!