Monday, January 20, 2014

Count Methods in Class

We can traverse all the methods and their code in a class using following code:

static void ClassToXml(Args _args)
{

    SysDictClass sysDictClass  = new SysDictClass(1023922);// Provide the ClassID
    TreeNode    treeNode = TreeNode::findNode(sysDictClass.path());
    TreeNode    childNode;
    Counter     counter = 1;

    if (treeNode)
    {
        info(strfmt('Number of methods in the class: %1',treeNode.aotchildnodecount()));
        childnode = treenode.aotfirstchild();
        while(counter <= treeNode.aotchildnodecount())
        {
            info(childNode.treeNodeName()); //Print the methods name
            //info(childNode.AOTgetSource()); Uncomment this to print the coding of the method
            childNode = childNode.aotnextsibling();
            counter++;
        }
    }
}

No comments:

Post a Comment