Mono.Cecil 0.9 "cecil/light" 9

Posted by Jb Evain Mon, 12 Apr 2010 18:28:00 GMT

Statue

I started working on Mono.Cecil during the fall of 2004. In its current incarnation, it served me and a lot of people very well. But looking at it now, it aged quite a bit. The code still compiles on .net 1.1, is using old conventions, doesn’t have a real test suite, is quite memory hungry, and is not that optimized. Which doesn’t prevent it to be a useful and wide used library, but looking back; I could have done a lot of things differently.

And doing things differently is basically what I’ve been doing for the past two years in my free time. What originally started as a refactoring of Mono.Cecil for the decompiler, ended up as a rewrite from the ground up. And today I’m excited to make public what is the next version of Cecil, which I’ve been fondly calling “cecil/light”.

Let’s start with a warning; this version contains breaking changes with the previous API. I didn’t promise API stability for the previous code, but this iteration of Mono.Cecil, tagged 0.9, is a huge step towards 1.0 and API stability.

But let’s focus for a while on the bright and new side. Mono.Cecil 0.9 comes with:

  • A cleaned and genericized API, I took this opportunity to clean some parts I hated in the old API.
  • A smaller and easier to maintain C#3 code base (Mono.Cecil 0.9 compiled with optimizations by csc is about 250k against almost 400k for 0.6) which only requires a .net 2.0 compatible runtime.
  • A test suite which is very easy to augment.
  • Better support for pdb and mdb files and strong name assemblies.
  • Complete support for PE32+ assemblies.
  • Bug fixes that weren’t possible without large changes in the old code.
  • Less memory consumption.
  • Lazy loading of every metadata element.
  • Speed and optimizations.
  • Complete Silverlight support.
  • A beginning of documentation on a wiki.
  • A collection of extension methods to add features to Cecil when they’re not necessary to the core assembly.

I ported a few of my projects to this version of Cecil already, and it shows great results. I didn’t spend more than four hours per project to adjust the code in a branch. There’s a migration page on the wiki to help you. If it doesn’t answer your question, reach us on the mono-cecil group.

I took special care in testing this version, and waited to have something stable to make it public, but just like every rewrite, you might face bugs or regressions. I’m confident it won’t take long before it gets really stable. A few people had early access to this code base, and ensured it was at least working as well as the previous version, if not better most of the time.

I moved the development of this version of Mono.Cecil to github while I’ll be maintaining the previous code in the Mono tree, as it’s still used by a lot of tools there, that I haven’t migrated yet.

We’ll also be working on writing more documentation for 1.0, both as a serie of HOWTOs, and as a more traditional class library documentation. But everyone that has already used Cecil should be up to speed promptly.

Thanks to everyone that helped, whether they knew it or not. Many thanks to Rodrigo B. de Oliveira, Carlo Kok, Sébastien Pouliot, and all the contributors to Mono.Cecil. Thanks also to Jeroen Frijters for his fantastic work on his IKVM.Reflection.Emit assembly in which I sometimes took inspiration. Enjoy!

Picture by law_keven some rights reserved

Présentation MonoTouch à Paris 2

Posted by Jb Evain Tue, 06 Oct 2009 14:56:00 GMT

MonoTouch

Certains vont à la Tour Eiffel, d’autres se ruent dans des Starbucks, mais moi, quand je monte conquérir Paris, je vais aux réunions alt.net. C’est souvent amusant, et toujours de bonne compagnie. En plus j’ai l’honneur, que dis-je le privilège d’être en haut de l’affiche de la prochaine réunion. Évidemment, je n’aurai pas de complet bleu, moi j’aime les rayures.

Lundi prochain, 12 octobre, je vais présenter MonoTouch. MonoTouch, c’est un produit de Novell, qui permet d’écrire des applications pour iPhone en C#, comme on le ferait pour le framework .net. Ou presque.

Cette session sera donc l’occasion de voir ce que l’on peut faire avec, de rentrer un peu dans les détails du pourquoi du comment ça marche, et d’en discuter. Parce que c’est vraiment ce qui fait le charme de ces rencontres alt.net. Les discussions post-session, un verre à la main, une cravate dans l’autre.

Notre hôte pour cette session sera Zenika, qui m’a réservé une page rien que pour moi, et surtout qui permet de s’inscrire. Dépêchez vous de vous inscrire, le nombre de place est probablement limité.

Le synopsis de la session:

Aujourd’hui, dans l’informatique, tout le monde ou presque a entendu parler de l’iPhone. Et à plus forte raison depuis que celui-ci supporte le copier-coller. C’est aujourd’hui un acteur important dans le monde de la mobilité, et sa démocratisation rapide en fait une plateforme de choix pour développer des applications, aussi bien pour l’entreprise que pour le particulier.

Si à l’origine développer pour cette platforme signifiait utiliser le langage d’Apple, l’Objective-C, on assiste à la naissance de solutions tierces destinées à fournir d’autres moyens de programmer pour l’iPhone.

Cette session sera l’occasion de voir non seulement comment il est possible de réutiliser son code et ses compétences .net sur l’iPhone grâce à MonoTouch, mais aussi d’en expliquer le fonctionnement.

À lundi prochain donc.

Rebasing System.Reactive to the .net CLR 4

Posted by Jb Evain Thu, 30 Jul 2009 10:24:00 GMT

Purple rain

There has been a lot of interest towards the Rx framework lately. It’s definitely an interesting piece of software, and the video linked on channel 9 is quite fascinating. The only issue is that the only assembly you can get right now is compiled against Silverlight, making it impossible to use on the traditional .net framework. Impossible, really?

Well, I for one would not recommend it, but if you really can’t wait to try it, you could use this little piece of code which uses Cecil to turn the assembly compiled against Silverlight into an assembly that will work on the .net framework. Of course the assembly will lose its strong name in the process. But at least, it will be usable.

For instance, here’s the sample that Jafar is showing on his blog, running on Mono:

Update: don’t miss the comment Sébastien posted, and how he would do it with Reflexil.

Getting the field backing a property using Reflection

Posted by Jb Evain Fri, 01 May 2009 08:46:00 GMT

Pluie, Pluie

Update: the code has been moved to its own project page.

Let’s consider you’re writing a LINQ provider. And that you need to opimize the following LINQ query:

from Person p in db where p.Age > 18 select p;

Let’s add a constraint. The underlying storage engine stores data according to the field name. That would mean that when generating the query for the underlying storage system, you’ll have to map

p.Age
into something that the underlying storage system will understand. In that case, a field. And all you have is a MemberExpression, giving you a PropertyInfo.

The issue here is that you have no way to get the FieldInfo backing the property. If you think about it, it’s normal. The setter and the getter of a property being traditional methods, they can contain any kind of code. Meaning that you can’t always find a field backing the property.

But in that case, it’s ok, we’re only interested in those forms of properties:

public int Age { get; set; }

private string name;

public string Name {
    get { return name; }
    set { name = value; }
}

Of course here what’s interesting is how to actually get the field. I’ve used the Reflection based CIL reader I wrote about yesterday. I disassemble the body of either a getter or a setter of the property, and if it matches a simple IL pattern, that is, if it looks to be a property backed by a field, I simply return the field.

To do the actual IL matching, I re-implemented something Rodrigo and I wrote when we were working on instrumenting assemblies at db4o. The code itself is pretty neat.

Anyway, that’s another opportunity to write a simple extension method:

public static FieldInfo GetBackingField (this PropertyInfo self)

Again, you’re more than welcome to have a look at the implementation. Don’t forget that it depends on the Reflection based CIL reader.

Older posts: 1 ... 3 4 5 6 7 ... 38