Chapter 1: Introducing Intermediate Language

Overview

Intermediate Language (also known as Common Intermediate Language, CIL, or as Microsoft Intermediate Language, MSIL) lies at the core of .NET. Whatever language you use to write your source code in, if it is to run under the auspices of the .NET Framework, it will end up as IL. So if you want to understand at an advanced level how .NET works then knowing a bit about IL is a huge advantage. If you understand some IL that means you'll be able to:

  • Understand better how the the managed code you write works under the hood. You'll have two sources of information: you can read the docs or you can examine the IL code generated by your compiler - which may give you insights that aren't covered by the documentation.

  • Examine the code that the compiler for your usual language (such as C++, C#, or VB) emits, which may on occasions help you in debugging or in designing code that is optimized for performance. It may also help you understand some of the finer points of how your chosen language works.

  • Actually write some code directly in IL - it's probably not that often that you'll want to do this, but you may occasionally find it useful to be able to take advantage of IL features not implemented in your normal language, in much the same way that in pre-.NET days, people writing high-performance C or C++ code would occasionally drop to native assembly language to improve the performance of some particular function.

  • Obviously, if you are writing developer tools such as compilers or debuggers, understanding IL is a prerequisite!

Because of the importance of IL, we have decided to introduce the language before we do anything else in this book - which we will do in this and the Chapter 2 we'll build on that by showing how to code up classes and structs, and invoke instance methods. In that chapter we'll also cover some more advanced topics such as delegates and exceptions, and calling unmanaged code.

We're not going to go into every nuance of the language, nor will we cover some of the more advanced, and rarely used, features. This is after all a book about advanced .NET programming in general, not a book about IL programming. I'm not expecting you to start writing all your code in IL - for most purposes that would be a pretty silly thing to do, and the only significant result would be to multiply your development and debugging time considerably. Rather, I'm working on the basis that understanding IL will help you to get the most out of the .NET Framework in your high-level language development. So, while we'll inevitably have to cover IL syntax, the emphasis in these chapters is on teaching you the basic concepts sufficiently that you can read IL, and in particular helping you to understand the ways in which your high-level language - be it C#, VB, Managed C++, or some third-party language - is almost certainly hiding or giving a misleading impression of how the .NET Framework does certain tasks. High-level languages tend to do that in order to make things easy for you, but IL, the language that the JIT compiler has to deal with, can hide nothing.

You'll also find this chapter starts at a fairly gentle pace in terms of IL concepts. I'm not assuming you've had any experience of programming in IL (or native machine code for that matter). I do, however, assume you are experienced in your high-level language and understand object-oriented programming and the basic principles of the .NET Framework. At the end of these chapters, you should have a good enough grasp of IL to be able to read most of the IL code generated by your compiler. In addition, the appendix downloadable from the Wrox Press web site gives a comprehensive list of the meanings of every IL instruction, along with the corresponding opcodes, so you can refer to that if you do encounter any IL instructions not mentioned in this chapter.

We should also remind you that you don't strictly have to read these IL chapters - most of our code samples throughout the rest of the book are in C#, so as long as you can read C# you'll be able to get by through most of the rest of the book. If you really feel daunted at the prospect of reading assembly code, feel free to skip ahead. But we do believe that if you have a sound grasp of the principles of IL then your advanced .NET programming will benefit.



Advanced  .NET Programming
Advanced .NET Programming
ISBN: 1861006292
EAN: 2147483647
Year: 2002
Pages: 124

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