Web site hosting - CHAPTER 15 UNDERSTANDING CIL AND THE ROLE

CHAPTER 15 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES 501 // Define the single-file assembly. .assembly CILCars { .hash algorithm 0×00008004 .ver 1:0:0:0 } .module CILCars.dll As mentioned, this assembly will contain two class types. The first type, CILCar, defines two points of field data and a custom constructor. The second type, CarInfoHelper, defines a single static method named DisplayCarInfo(), which takes CILCar as a parameter and returns void. Both types are in the CILCars namespace. In terms of CIL, CILCar can be implemented as so: // Implementation of CILCars.CILCar type. .namespace CILCars { .class public auto ansi beforefieldinit CILCar extends [mscorlib]System.Object { // The field data of the CILCar. .field public string petName .field public int32 currSpeed // The custom constructor simply allows the caller // to assign the field data. .method public hidebysig specialname rtspecialname instance void .ctor(int32 c, string p) cil managed { .maxstack 8 // Load first arg onto the stack and call base class ctor. ldarg.0 // ‘this’ object, not the int32! call instance void [mscorlib]System.Object::.ctor() // Now load first and second args onto the stack. ldarg.0 // ‘this’ object ldarg.1 // int32 arg // Store topmost stack (int 32) member in currSpeed field. stfld int32 CILCars.CILCar::currSpeed // Load string arg and store in petName field. ldarg.0 // ‘this’ object ldarg.2 // string arg stfld string CILCars.CILCar::petName ret } } } Keeping in mind that the real first argument for any nonstatic member is the current object reference, the first block of CIL simply loads the object reference and calls the base class constructor. Next, you push the incoming constructor arguments onto the stack and store them into the type s field data using the stfld (store in field) opcode. Next, you need to implement the second type in this namespace: CILCarInfo. The meat of the type is found within the static Display() method. In a nutshell, the role of this method is to take the incoming CILCar parameter, extract the values of its field data, and display it in aWindows Forms message box. Here is the complete implementation of CILCarInfo, with analysis to follow:
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply