19

I'm an expert C# 3 / .NET 3.5 programmer looking to start doing some runtime codegen using System.Reflection.Emit.DynamicMethod. I'd love to move up to the next level by becoming intimately familiar with IL.

Any pointers (pun intended)?

Kevin Fairchild
  • 10,891
  • 6
  • 33
  • 52
TheSoftwareJedi
  • 34,421
  • 21
  • 109
  • 151

5 Answers5

6

In addition to Darren's answer, I'd suggest picking or inventing a toy language, and writing a simple compiler for it. Pick something that requires little parsing, like BF or a stack-based language, and you'll find that writing a compiler is actually simpler than it seems.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
5

The best way to learn it, is to write something you understand, then look at the IL it created. Also, depending on what you are doing, you can use expression trees instead of emitting IL, and then when you compile the expression trees, those smart guys at microsoft create the IL for ya.

Darren Kopp
  • 76,581
  • 9
  • 79
  • 93
5

.NET Reflector is great for examining the IL produced by C#/VB.NET.

It's a wonderful learning tool.

Michael Burr
  • 333,147
  • 50
  • 533
  • 760
5

The ECMA 335 specification is freely available for download here: http://www.ecma-international.org/publications/standards/Ecma-335.htm

Partition III is the most relevant for dealing with MSIL, but I'd strongly recommend partition I as well for any .NET developer as it will greatly solidify understanding of the platform.

  • I wanted to mention that in the past few weeks I, too, have wanted to dig deeper into the bowls of .Net and learn about CIL code. The best document I can find is the spec. Unfortunately, I've yet to find a solid "Teach yourself CIL" site that has enough information to be proficient in MSIL. If you want hard-documentation, the spec appears to be the best place to go. – RLH Mar 13 '15 at 11:24
3

Expert .NET 2.0 IL Assembler. Although this book may be a little dated now, it was still a great overview for me.

Nescio
  • 27,645
  • 10
  • 53
  • 72