问题
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)?
回答1:
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.
回答2:
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.
回答3:
.NET Reflector is great for examining the IL produced by C#/VB.NET.
It's a wonderful learning tool.
回答4:
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.
回答5:
Expert .NET 2.0 IL Assembler. Although this book may be a little dated now, it was still a great overview for me.
来源:https://stackoverflow.com/questions/155357/what-are-the-best-resources-for-learning-cil-msil