C# Programming in Depth: and Attribute-Based Programming Lisa (Ling) Liu
C# Programming in Depth: and Attribute-Based Programming Lisa (Ling) Liu
C# Programming in Depth
Prof. Dr. Bertrand Meyer
March 2007 – May 2007
Provide some input vehicle to allow the user to specify the module to
plug in
Determine if the module supports the correct functionality
Obtain a reference to the required infrastructure and invoke the
members to trigger the underlying functionality
answer:
• same language, no, one binary file => Single file assembly
• different languages, yes, multiple binary files =>
Multifile assembly
Manifest
Type Metadata
CIL Code
(Optional) Resourcses
Type Metadata
CIL Code
*.bmp
Shared Assemblies
¾ A single copy of a shared assembly can be used by
several applications on a single machine
¾ Used to create machine-wide class library
.assembly Vehicle
{
...
.ver 1:0:0:0}
*.dll
Manifest
(with public key)
Assembly Private Key Digital
+ =
Type Metadata Hash Code Data Signature
CIL Code
digital signature
Provide some input vehicle to allow the user to specify the module to
plug in (Dynamic loading)
Determine if the module supports the correct functionality (Type
reflection)
Obtain a reference to the required infrastructure and invoke the
members to trigger the underlying functionality (Late binding)
AssembleyName asmName;
asmName = new AssemblyName();
asmName.SetPublicToken(byte[]);
Assembly a = Assembly.Load(“CarLibrary”);
Type miniVan = a.GetType (“CarLibrary.MiniVan”);
object obj = Activator.CreateInstance(miniVan);
MethodInfo mi = miniVan.GetMethod(“TurboBoost”);
mi.Invoke(obj, null);