开发者

Is there a library that can decompile a method into an Expression tree, with support for CLR 4.0?

开发者 https://www.devze.com 2022-12-21 06:21 出处:网络
Previous questions have asked i开发者_如何学编程f it is possible to turn compiled delegates into expression trees, for example:

Previous questions have asked i开发者_如何学编程f it is possible to turn compiled delegates into expression trees, for example:

  • converting a .net Func<T> to a .net Expression<Func<T>>

The sane answers at the time were:

  • It's possible, but very hard and there's no standard library solution.
  • Use Reflector!

But fortunately there are some greatly-insane/insanely-great people out there who like reverse engineering things, and they make difficult things easy for the rest of us.

Clearly it is possible to decompile IL to C#, as Reflector does it, and so you could in principle instead target CLR 4.0 expression trees with support for all statement types. This is interesting because it wouldn't matter if the compiler's built-in special support for Expression<> lambdas is never extended to support building statement expression trees in the compiler. A library solution could fill the gap. We would then have a high-level starting point for writing aspect-like manipulations of code without having to mess with raw IL.

As noted in the answers to the above linked question, there are some promising signs but I haven't succeeded in finding if there's been much progress since by searching.

So has anyone finished this job, or got very far with it?

Note: CLR 4.0 is now released. Time for another look-see.


I did a library that supports .NET 3.5 expression trees:
https://github.com/ashmind/expressive

I tried to do internal API so that .NET 4.0 support would not be that hard to add.
You can add or change steps in the IPipeline implementation to achieve just that.

One thing that I haven't done and that will be hard is support for loops, though.


Based on the response, I'm going to answer my question:

No.

Though of course if someone comes up with a better answer (or I come across one) I will update.

0

精彩评论

暂无评论...
验证码 换一张
取 消