Mono.Cecil is great library, no doubt about that. But there are some things that are bugging me.
This one is serious. A framework without documentation is very hard to use. Usually time is being wasted just to figure out how to do some of the very simple things.
API is hard to use
Generally, the API is OK, but it requires a lot of writing. Also, it’s easy to get lost in all of the MemberReferences, MethodReferences, MethodDefinitions, FieldReferences, FieldDefinitions, TypeReferences stuff. Writing IL is not easy at all. Especially when things get a bit complicated. Wouldn’t it be nice if Mono.Cecil had a interpreter/compiler in it. So, we could write C# code that would be translated to IL. Add to that a nice fluent interface:
AssemblyDefinition assembly = AssemblyFactory.GetAssembly("SomeAssembly.dll"); assembly.WithType("MyClass") .WithMethod("SomeMethod") .AppendCode(@" int x = 5; Console.WriteLine(x); ");
I guess that I’m asking for too much with the interpreter/complier stuff, but a Mono.Cecil fluent interface would be very convenient.
Testability – unit testing
How do you test code that works with Mono.Cecil? Here is my Mono.Cecil development cycle:
- Write code that uses Mono.Cecil
- Write the dummy assembly to the disk
- Open the assembly in the Reflector to see if everything is fine.
As you can see there is no test automation here whatsoever. The whole process is manual and very time consuming.
As I said, Mono.Cecil is great but more documentation and an Fluent Interface would make it much more better. If you have any advices on how to overcome these difficulties please let me know.