我正在编写 ILAsm 函数,它接收可变数量的参数并返回它们的总和:
.class public auto ansi TestSentinel
{
.method public static vararg unsigned int64 Sum( /* all arguments are optional */ )
{
.locals init( value class [mscorlib]System.ArgIterator Args,
unsigned int64 Sum,
int32 NumArgs )
...
ldloc Sum
ret
}
}
我的 dll 编译成功,但我无法从 C# 代码调用此函数。当我用
调用它时var k = TestSentinel.Sum(1);
我收到错误信息:
Error The best overloaded method match for 'TestSentinel.Sum(__arglist, ...)' has some invalid arguments
对于任何其他数量的参数,我都会收到 wrong argument number
消息。
调用我的 ILAsm 函数的正确方法是什么?
最佳答案
它需要使用未记录的 __arglist 关键字:
var k = TestSentinel.Sum(__arglist(1));
var l = TestSentinel.Sum(__arglist(1, 2, 3));
这不是很有用,最好关注参数数组。
关于c# - 从 C# 调用 ILAsm vararg 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19268347/