上下文:Windows 7,ExcelDNA 0.30,.NET 4.0
我仍然试图通过ExcelDNA在Excel中使用params / ParamArray方法。通过使用varags,我将避免与System.ParamArrayAttribute有关,并使用System.ArgIterator追踪路径。
可悲的事实是,以下编译但仍然无效。我不断得到价值错误。有些不对劲,但我不知道这个汇编程序(还)已经弄清楚了。任何想法,任何人?
.assembly extern mscorlib { }
.assembly Test {}
.module test.dll
.namespace VTest {
.class public Test {
// Compute sum of undefined number of arguments
.method public static vararg int64 IntSum(/* all arguments optional */)
{
.locals init(valuetype [mscorlib]System.ArgIterator Args,
unsigned int64 Sum,
int32 NumArgs)
ldc.i8 0
stloc Sum
ldloca Args
arglist // Create argument list structure
// Initialize ArgIterator with this structure:
call instance void [mscorlib]System.ArgIterator::.ctor(
value class [mscorlib]System.RuntimeArgumentHandle)
// Get the optional argument count:
ldloca Args
call instance int32 [mscorlib]System.ArgIterator::GetRemainingCount()
stloc NumArgs
// Main cycle:
LOOP:
ldloc NumArgs
brfalse RETURN // if(NumArgs == 0) goto RETURN;
// Get next argument:
ldloca Args
call instance typedref [mscorlib]System.ArgIterator::GetNextArg()
// Interpret it as unsigned int64:
refanyval [mscorlib]System.UInt64
ldind.u8
// Add it to Sum:
ldloc Sum
add
stloc Sum // Sum += *((int64*)&next_arg)
// Decrease NumArgs and go for next argument:
ldloc NumArgs
ldc.i4.m1
add
stloc NumArgs
br LOOP
RETURN:
ldloc Sum
ret
}
}
}
答案 0 :(得分:3)
Excel-DNA(以及Excel C API)目前不支持(版本0.30)'params'可选参数。有关详细信息和可能的解决方法,请参阅此讨论:http://exceldna.codeplex.com/discussions/406719