有没有解决的ILGenerator一个很好的包装? [英] Is there a good wrapper around ILGenerator?

查看:141
本文介绍了有没有解决的ILGenerator一个很好的包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用System.Reflection.Emit有一段时间了,并发现它(谁不?)那样痛苦的错误倾向。

I'm using System.Reflection.Emit for a while now, and find it (who don't?) as painful as bug prone.

你知道,如果周围有白细胞介素生成一个很好的包装,这东西我可以靠发射IL在一个更安全和更容易的方式不是直接与SRE玩?

Do you know if there is a good wrapper around the IL Generator, something that I can rely on to emit IL in a more safe and easier manner than with playing directly with SRE?

编辑:

我知道,操纵EX pression树是明确更容易,不是直接发射IL更安全,但也有一些限制,现在。我无法创建code集团,利用循环,声明和几个当地人,等等。我们需要等到.NET 4中出来的工作:)

I know that manipulating expression trees is definitively easier and safer than emitting IL directly, but they also have some constraints right now. I can't create code blocs, use loops, declare and work with several locals, etc. We need to wait until .NET 4 comes out :)

此外,我处理与已经依赖于SRE一个code基地。

Moreover, I'm dealing with a code base which already relies on SRE.

显然,的ILGenerator尽我所需要的。但是我操作的时候它会AP preciate更多的援助。当我指的是一个的ILGenerator包装,它仍保持在pretty的较低水平,我想一些东西,可以提供类似的方法:

Obviously, ILGenerator do everything I need. But I would appreciate more assistance when manipulating it. When I'm referring to a ILGenerator wrapper, which remains at a pretty low level, I think about something which could provide methods like:

// Performs a virtual or direct call on the method, depending if it is a 
// virtual or a static one.
Call(MethodInfo methodInfo)

// Pushes the default value of the type on the stack, then emit 
// the Ret opcode.
ReturnDefault(Type type)

// Test the object type to emit the corresponding push 
// opcode (Ldstr, Ldc_I*, Ldc_R*, etc.)
LoadConstant(object o)

这真的很幼稚3的例子,但它可能是足以证明我的期望。我们可以看到,作为一组扩展方法,但它可能是不错的条件语句的支持和循环像的 RunSharp 。事实上,RunSharp是pretty的接近,我想要什么,但它抽象化的ILGenerator太多,不公开其所有功能。

It's really 3 naive examples, but it could be enough to demonstrate what I expect. We can see that as a set of extension methods, but it could be nice to have support for conditional statements and loops like in RunSharp. In fact, RunSharp is pretty close that what I want, but it abstracts the ILGenerator too much and doesn't expose all its functionality.

我不记得在哪里,但我已经看到了这样的帮手一个开源项目。

I can't remember where, but I already saw such an helper in an open source project.

推荐答案

如果您使用的是.NET 3.5,您可能会发现使用防爆pression树更加合理。这完全取决于你在做什么 - 它仍然可以是相当痛苦的 - 但它肯定另一种选择要知道

If you're using .NET 3.5, you may find using Expression Trees to be more reasonable. It entirely depends on what you're doing - and it can still be quite painful - but it's certainly another option to be aware of.

这篇关于有没有解决的ILGenerator一个很好的包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆