给定一个函数
function printAndAdd( s: String, a: int, b: int ) {
// ...
}
有没有办法在运行时枚举函数的参数(它们的名称和类型)?就像是
for ( var arg: ArgumentDescriptor in printAndAdd ) {
// arg.type yields the class object of the argument, i.e. 'String' or 'int'.
// arg.name yields the name of the argument, i.e. 's' or 'a'
}
我有一个具有不同签名的事件处理程序列表,并且我得到了要调用的事件处理程序的名称以及Array
对象的名称。我可以只是apply()
函数的数组,但我想先做一些错误检查以提供更好的错误消息。