15.01.2013 Views

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

If the assembly has no AssemblyVersion attribute, the version appears as “0.0.0.0”.<br />

If it is unsigned, its public key token appears as “null”.<br />

An Assembly object’s FullName property returns its fully qualified name. The compiler<br />

always uses fully qualified names when recording assembly references in the<br />

manifest.<br />

A fully qualified assembly name does not include a directory<br />

path to assist in locating it on disk. Locating an assembly residing<br />

in another directory is an entirely separate matter that we<br />

pick up in “Resolving and Loading Assemblies” on page 671.<br />

The AssemblyName Class<br />

AssemblyName is a class with a typed property for each of the four components of a<br />

fully qualified assembly name. AssemblyName has two purposes:<br />

• It parses or builds a fully qualified assembly name.<br />

• It stores some extra data to assist in resolving (finding) the assembly.<br />

You can obtain an AssemblyName object in any of the following ways:<br />

• Instantiate an AssemblyName, providing a fully qualified name.<br />

• Call GetName on an existing Assembly.<br />

• Call AssemblyName.GetAssemblyName, providing the path to an assembly file on<br />

disk.<br />

You can also instantiate an AssemblyName object without any arguments, and then<br />

set each of its properties to build a fully qualified name. An AssemblyName is mutable<br />

when constructed in this manner.<br />

Here are its essential properties and methods:<br />

string FullName { get; } // Fully qualified name<br />

string Name { get; set; } // Simple name<br />

Version Version { get; set; } // Assembly version<br />

CultureInfo CultureInfo { get; set; } // For satellite assemblies<br />

string CodeBase { get; set; } // Location<br />

byte[] GetPublicKey(); // 160 bytes<br />

void SetPublicKey (byte[] key);<br />

byte[] GetPublicKeyToken(); // 8-byte version<br />

void SetPublicKeyToken (byte[] publicKeyToken);<br />

Version is itself a strongly typed representation, with properties for Major, Minor,<br />

Build, and Revision numbers. GetPublicKey returns the full cryptographic public<br />

key; GetPublicKeyToken returns the last eight bytes used in establishing identity.<br />

To use AssemblyName to obtain the simple name of an assembly:<br />

Console.WriteLine (typeof (string).Assembly.GetName().Name); // mscorlib<br />

656 | Chapter 17: Assemblies

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

Saved successfully!

Ooh no, something went wrong!