Dynamics AX - Enumerate subclasses of a specific class

A colleague of mine recently asked me if there was a quick way to find all of the classes that extend a certain base class.

"But of course there is!" I said.  Here is the code block I sent him, should you, dear reader, need to accomplish a similar task.

static void getSubclasses()
{
    List            subclassList;
    ListEnumerator  listEnumerator;
    SysDictClass    dictClass;

    dictClass       = new SysDictClass(classNum(ExchangeRateProvider)); //Your class here
    subclassList    = dictClass.extendedBy();

    if (subclassList.elements())
    {
        listEnumerator = subclassList.getEnumerator();
        setprefix(strfmt("%1 is extended by %2 subclasses", dictClass.name(), int2str(subclassList.elements())));
        while (listEnumerator.moveNext())
        {
            info(ClassId2Name(listEnumerator.current()));
        }
    }
    else
    {
        info(strfmt("%1 is not subclassed", dictClass.name()));
    }
}

Comments

Popular posts from this blog

SQL Reporting Services - Viewer broken in Non-IE Browsers: FIX

Dynamics AX 2012 - Visual Studio Team Services Custom Work Item Fields Break Version Control (Error TF237121)

Dynamics AX SysFileDeployment Framework - Deploy files automatically (using resources) to the client on login