CHAPTER 15 UNDERSTANDING CIL AND THE (Web site translator) 504
CHAPTER 15 UNDERSTANDING CIL AND THE 504 THE ROLE OF DYNAMIC ASSEMBLIES Figure 15-4. Your CILCar in action // Call Display() and pass in topmost value on stack. call void [CILCars] CILCars.CILCarInfo::Display( class [CILCars]CILCars.CILCar) ret } } } The one opcode that is important to point out is .entrypoint. Recall from the discussion earlier in this chapter that this opcode is used to mark which method of an *.exe functions as the entry point of the module. In fact, given that .entrypoint is how the CLR identifies the initial method to execute, this method can be called anything at all other than Main(). The remainder of the CIL code found in the Main() method is your basic pushing and popping of stack-based values. Do note, however, that the creation of CILCar involves the use of the .newobj opcode. On a related note, recall that when you wish to invoke a member of a type using raw CIL, you make use of the doublecolon syntax and, as always, make use of the fully qualified name of the type. With this, you can compile your new file with ilasm.exe, verify your assembly with peverify.exe, and execute your program: ilasm CilCarClient.il peverify CilCarClient.exe CilCarClient.exe Figure 15-5 shows the end result. That wraps up the CIL primer and the first goal of this chapter. At this point, I hope you feel confident that you can open a particular .NET assembly using ildasm.exe and gain a better understanding of what exactly is occurring behind the scenes. Understanding Dynamic Assemblies As you may have gathered, the process of building a complex .NET application in CIL would be quite the labor of love. On the one hand, CIL is an extremely expressive programming language that allows you to interact with all of the programming constructs allowed by the CTS. On the other hand, authoring raw CIL is tedious, error-prone, and painful. While it is true that knowledge is power, you may indeed wonder just how important it is to commit the laws of CIL syntax to memory. The answer is, It depends. To be sure, most of your .NET programming endeavors will not require you to view, edit, or author raw CIL code. However, with the CIL primer behind you, you are now ready investigate the world of dynamic assemblies (as opposed to static assemblies) and the role of the System.Reflection.Emit namespace. The first question you may have is, What exactly is the difference between static and dynamic assemblies? By definition, static assemblies are .NET binaries loaded directly from disk storage, meaning they are located somewhere on your hard drive in a physical file (or possibly a set of files in the case of a multifile assembly) at the time the CLR requests them. As you might guess, every time you compile your C# source code, you end up with a static assembly.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.