Using Class Augmentation

Using Class Augmentation

The ILAsm-specific technique of class augmentation can be useful when you want to add new components written in ILAsm to your application written in a high-level language. If you need to add new types, an obvious solution is to declare these classes in a separate ILAsm source file, disassemble your application, and reassemble it with this additional .il file. Class augmentation allows you to apply the same approach if you need to add new members to some of the types defined in your application. In other words, you don’t need to edit the disassembly text of your application, inserting new members in the type definitions, because you can augment the respective type definitions in a separate source file.

For example, suppose that you would like to have a thread local storage (TLS) mapped field in class X and a vararg method in class Y, but the high-level language of your choice does not allow you to specify such items. You can write the following amendment file, Amend.il:

.class X {    .field public static int32 tlsField at TLSD001 } .data tls TLSD001 = int32(1234) .class Y {    .method public vararg int64 Sum()    {           } }

Then you can disassemble your original (incomplete) module and reassemble it with an amendment:

ildasm MyApp.exe /out:MyApp.il ilasm MyApp Amend

The last line is so laconic because it uses three defaults: the default source file extension (IL), the default output file type and extension (EXE), and the default output file name (the same as the name of the first source file).



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net