我为了好玩而制作了一个愚蠢的 AOT .net 编译器,但遇到了问题。
我只是将程序集加载到内存中(我正在用 C# 编写它)并左右发送垃圾邮件以获取我需要的信息(例如方法体的 CIL)。
此页面显示“我们需要对当前实例的引用(存储在本地参数索引 0 中)[...]”。但是,当我调用 时MethodInfo.GetParameters()
,不会返回此参数。
我正在解析操作码中的字段,例如Ldarg
ParameterInfo 对象,而不是原始索引,因此当“Ldarg.0”在实例方法中时它会变得非常混乱 - 因为 arg 0 不在GetParameters
!
我的主要问题:有什么方法可以获取ParameterInfo
对象的this
对象实例(参数索引 0),还是只需要使用原始索引?(我真的不想使用 int 索引......)
这是一些代码,因为代码很好。(包含在类程序中)
static void Main(string[] args)
{
// obviously throws an IndexOutOfRangeException instead of returning the (true) argument 0
Console.WriteLine(typeof (Program).GetMethod("Test").GetParameters()[0]);
}
public void Test()
{
}