'如果' IL 中的阻断
我想我可能遗漏了一些重要的东西,但我似乎无法弄清楚如何使用动态方法在 IL 中构造条件语句。我之前只稍微涉足过它,但现在我需要扩展一些代码。
是否有一些我没有找到的文档(除了 CLI 文档),或者有人有一些示例代码?那太棒了。
干杯,
I think I might be missing something important, but I can't seem to figure out how to construct a conditional statement in IL with dynamic method. I've only dabbled lightly in it before, but I need to extend some code now.
Is there some documentation somewhere that I haven't found (apart from the CLI documentation), or does someone have some sample code? That would be fantastic.
Cheers,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的具体代码,各种分支指令是您的朋友。
这是
IL 中的:
您基本上将要比较的值推送到堆栈上,然后调用 bgt 跳转到您需要的地方。
您可以检查 OpCodes 类 IL 命令的快速概述,例如 brtrue/brfalse 或 beq。
我还建议用 C# 编写 if 命令,对其进行编译,然后使用 ILDASM 或 Reflector 查看生成的 IL。
Depending on your exact code, the various branch instructions are your friend.
Here is
in IL:
You basically push the values you want to compare onto the stack and then call bgt to jump where you need to.
You can check the OpCodes Class for a quick overview of IL Commands, for example brtrue/brfalse or beq.
I would also recommend writing the if command in C#, compiling it, and using ILDASM or Reflector to look at the generated IL.
流程如下:
定义一个标签,例如:
调用您的条件:
在您希望其跳到的位置(例如 if 的末尾):
因此您创建了一个标签(您需要先执行此操作,以便存在引用,稍后您可以调用“mark”将标签放置在您想要的代码中的实际位置)。 OpCodes.Brtrue 只是 链接文本文章(感谢迈克尔
Here's how it goes:
Define a label, e.g.:
call your condition:
in the place where you want it to skip to (e.g. the end of the if):
So you create a label (you need to do it first so the reference exists, you call 'mark' later to place the label in the actual spot in code you want it). the OpCodes.Brtrue is just one of many conditional operations listed in the link text article (thanks Michael