Free mag vol1 | Page 673

CHAPTER 16  DYNAMIC TYPES AND THE DYNAMIC LANGUAGE RUNTIME Figure 16-8. Interop assembly logic can be embedded directly into your .NET application The C# compiler will only include the parts of the interop library you are actually making use of. Thus, if the real interop library has .NET descriptions of hundreds of COM objects, you will bring in only the definitions of the subset you are really making use of in your C# code. Beyond reducing the size of the application you need to ship to the client, you also have an easier installation path, as you don’t need to install any missing PIAs on the target machine. Common COM Interop Pain Points Let’s cover one more preliminary topic before the next example. Before the release of the DLR, when you authored C# code that used a COM library (via the interop assembly), you were sure to face a number of challenges. For example, many COM libraries defined methods, which took optional arguments, which were not supported in C# until .NET 3.5. This required you to specify the value Type.Missing for every occurrence of the optional argument. For example, if a COM method took five arguments, all of which were optional, you would need to write the following C# code in order to accept the default values: myComObj.SomeMethod(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); Thankfully, you are now able to author the following simplified code, given that the Type.Missing values will be inserted at compile time if you don’t specify a specific value. myComObj.SomeMethod(); 615