我正在编写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函数的正确方法是什么?
发布于 2013-10-09 10:25:43
它需要使用无文档的__arglist关键字:
var k = TestSentinel.Sum(__arglist(1));
var l = TestSentinel.Sum(__arglist(1, 2, 3));这不是很有用,最好把注意力放在一个params数组上。
https://stackoverflow.com/questions/19268347
复制相似问题