Friday, November 18, 2016

Calling method dynamically through DictClass

Sometimes we need to loop through all of the parameters that have been defined within a class or you need to call a method dynamically without knowing what the method name is until you get it from another source.

The following shows how to get a method name from a table and call said method (in our case a parameter method name of type NoYesId) and get the result

This example shown below is being called within a class. If you called it outside of the class you would replace the 'this' object with the class instance name.

Example: TestClass currentTest = new TestClass() you would replace 'this' with currentTest.

validationMap.ParmName = name of method

 

    NoYesId testPass;
    DictClass dictClass;
    ExecutePermission perm;
    TableThatHasParmMethodListing validationMap;


    //allow the code to run
    perm = new ExecutePermission();
    perm.assert();

    //go through all of the require test mappings that will link up to the current class being executed
    while select * from validationMap
    {
        //class the validation parm mapping for the current record
        dictClass = new DictClass(classidget(this));
        testPass = dictClass.callObject(validationMap.ParmName, this);

//testPass variable will now have the result of the parm
    }

    //revert code access
    CodeAccessPermission::revertAssert();

No comments:

Post a Comment