Calling instance methods through reflection

Hi-

Following job can execute instance method in a class. I had a scenario where I wanted to test my upgrade scripts and you know for running upgrade script there is a need to run the process that consumes a large amount of time, so I thought following job would be useful for the developers

static void callMethodJob(Args _args)

{

DictClass dictClass = new DictClass(classNum(ReleaseUpdateDB60_Cust));

Object classObj = dictClass.makeObject();

DictMethod dictMethod;

int i;

for (i=1; i < dictClass.objectMethodCnt(); i++)

{

if (Global::strStartsWith(dictClass.objectMethod(i), “update”))

{

dictClass.callObject(dictClass.objectMethod(i), classObj);

}

info(strFmt(“%1, %2, %3″, dictClass.objectMethodCnt(), dictClass.objectMethod(i), dictClass.name()));

}

}

About these ads

Posted on February 23, 2012, in Dynamics Ax Troubleshooting. Bookmark the permalink. 3 Comments.

  1. Hi Faddy,
    thank you for the info. I just want to mention that with the
    “for (i=1; i < dictClass.objectMethodCnt(); i++)" statement you are missing the last method of the class, as the counter is not zero based.

    • We cannot start with 0 since Arrays or collections in x++ do not start with 0. following should be the code to get all the methods

      for (i=1; i < dictClass.objectMethodCnt() +1; i++)

    • Or may be this
      for (i=1; i <= dictClass.objectMethodCnt(); i++)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 54 other followers

%d bloggers like this: