Tuesday, October 22, 2013

Reweaving IL code with Mono.Cecil

Inline image 2


Table of contents

Introduction
Mono.Cecil
Faking return values
Throwing exceptions
Reweaving properties
Conclusion

Introduction

In the past month I had the opportunity to get to know Mono.Cecil and use it extensively in our programs. However when I was learning how to use Mono.Cecil I had trouble because of the abundance of in depth tutorials and the existing few use an older version of Mono.Cecil which has some classes that are now removed or replaced (like AssemblyFactory or CilWorker).

This lack of coverage is the reason why I started writing tutorials for Mono Cecil. My aim is to create a series where the first two tutorials focus on testing while other two on the use of IL code weaving for Aspect Oriented Programming. 

Mono.Cecil library

The Mono.Cecil is a very powerful library for inspecting and reweaving IL code. And even if the target language of these articles is C#, don't forget that we could inspect or reweave any .NET compliant language with Cecil or even generate IL code.

From these characteristics comes that the class hierarchy maps to the concepts of IL programming not to C# and it does that very straightforward so if you know the IL language, getting started with Mono.Cecil will be very easy and fast. But don't worry, I would like to introduce the concepts of the intermediate language in parallel with Cecil, so an in-depth knowledge of IL programming is not a prerequisite. 

Read more: Codeproject
QR: Inline image 1