关于Opcodes.Ldarg加载ref变量而不是out [英] regarding Opcodes.Ldarg loading ref variables instead of out

查看:85
本文介绍了关于Opcodes.Ldarg加载ref变量而不是out的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下代码:

 ILGenerator ilGenForModify = outModifier.GetILGenerator(); 
ilGenForModify.Emit(OpCodes.Ldarga, 1 );



它加载了正确的参数。

但它已将其加载为ref。

如何让它出局?





IL代码不会显示任何特殊内容,因为参数列表将变量保存为输出变量。

这是IL代码。

IL_0001:ldarga.0



在C#中它是,

base.genModifyMethod(ref obj);





我想要它(出参考)。



我如何实现这一目标?







谢谢。

解决方案

获得所需内容的最简单方法是编写c#中的代码,编译并运行 Reflector (或类似工具)以查看生成的IL并在您自己的代码中使用它。


这就是我做得对的吗?

IL代码没有显示任何特殊内容,因为参数列表将变量保存为out变量。

这是IL代码。

IL_0001:ldarga.0



在C#中它是,

base.genModifyMethod(ref obj);





我希望它(参考参考资料)。



我如何实现这一目标?

For the following code:

ILGenerator ilGenForModify = outModifier.GetILGenerator();
ilGenForModify.Emit(OpCodes.Ldarga,1);


it has loaded the correct argument.
But it has loaded it as "ref".
How do I get it to be "out"?


The IL code doesn''t show anything special because the parameter list has the variable saved as an out variable.
This is the IL code.
IL_0001: ldarga.0

In C# it is,
base.genModifyMethod(ref obj);


I want it to be (out ref).

How do i achieve that?



Thank You.

解决方案

The easiest way to get what you want is to write the code in c#, compile and run Reflector (or similar tool) to see the generated IL and use that in your own code.


That''s what I have done right?
The IL code doesn''t show anything special because the parameter list has the variable saved as an out variable.
This is the IL code.
IL_0001: ldarga.0

In C# it is,
base.genModifyMethod(ref obj);


I want it to be (out ref).

How do i achieve that?


这篇关于关于Opcodes.Ldarg加载ref变量而不是out的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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