【发布时间】:2025-12-26 02:35:06
【问题描述】:
我想创建一个能够通过名称动态调用其他类中的方法的类。理想情况下,它将接受类和方法名称以及参数集合。 dictClass 适用于静态方法,但似乎不适用于实例方法。
有什么办法可以让下面的代码对非静态方法起作用?
[SysEntryPointAttribute]
public str methodExecute(str className, str methodName, str params)
{
DictClass dictClass;
anytype retVal;
str connMessage;
ExecutePermission perm;
perm = new ExecutePermission();
// Grants permission to execute the DictClass.callStatic method.
// DictClass.callStatic runs under code access security.
perm.assert();
dictClass = new DictClass(className2Id(className));
if (dictClass != null)
{
retVal = dictClass.callStatic(methodName);
connMessage = strfmt("Return value is %1", retVal);
}
// Closes the code access permission scope.
CodeAccessPermission::revertAssert();
return connMessage;
}
【问题讨论】: