Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The following code should do the trick. The code I have below can either use a class name or take in an object of the desired type that is already instantiated.</p> <p>The largest problem was dealing with passing the parameters along. Since there are a variable number I am using a switch statement to pass the correct number of parameters to the method. This doesn't look very elegant, but I am not sure there is another way to accomplish this.</p> <pre><code>public static anytype callMethod(str _className, str _methodName, container _parameters, Object _object = null) { DictClass dictClass; anytype returnValue; Object object; ExecutePermission permission; // Grants permission to execute the DictClass.callObject method. // DictClass.callObject runs under code access security. permission = new ExecutePermission(); permission.assert(); if (_object != null) { dictClass = new DictClass(classidget(_object)); object = _object; } else { dictClass = new DictClass(className2Id(_className)); object = dictClass.makeObject(); } if (dictClass != null) { switch (conLen(_parameters)) { case 0: returnValue = dictClass.callObject(_methodName, object); break; case 1: returnValue = dictClass.callObject(_methodName, object, conPeek(_parameters, 1)); break; case 2: returnValue = dictClass.callObject(_methodName, object, conPeek(_parameters, 1), conPeek(_parameters, 2)); break; //... Continue this pattern for the number of parameters you need to support. } } // Closes the code access permission scope. CodeAccessPermission::revertAssert(); return returnValue; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload