Using reflections – intrinsic functions

Using reflections – intrinsic functions

Tutorial
Published on
Jun 30, 2015

As you might notice already there is nothing that much annoying as well hidden run time error in the code that you written.

Imagine simple scenario where you want to prompt user with the name of the method in the table or name of the table itself (generally in practise you would rarely do that, but for the sake of simplicity let say you do), you would probably do something like this

print "MyTableMethod";

what is wrong with this approach is that when for some reasons, you will change the name of the table method you will have to remember to change it here as well, and believe me you will forget about that eventually. Here is not a big problem user will be just prompted with the wrong table method name, but what if other part of our program refers to this method and tries to call it using for example dictionary API like here

dictTable.callObject(“MyTableMethod”);

with this approach you will be doomed to suffer from run time errors, but fortunately there is a way to mitigate that by using so called intrinsic functions, like this

dictTable.callObject(tableMethodStr(MyTable, MyTableMethod)));

or

dictTable.callStatic(tableStaticMethodStr(MyTable, MyTableMethod)));

if it is a static method.

When you do it like this you moved the issue from the run time to the compiler, so every time that you change table name or method name compiler will warn you that there is an error and it should be corrected.

You have corresponding intrinsic function for all elements in AOT, so you can reference them by name. All intrinsic functions beside identifierStr provide you with compile checking, however it is still better to use identifierStr than literals if for example none of the other intrinsic functions are available.

For more information about intrinsic functions please refer to the following link.

https://msdn.microsoft.com/en-us/library/aa626893.aspx

Share it
Written by
Andrzej Lapinski

Student at the Wroclaw University of Technology. Passionate about science and technology. Main areas of interest are probability theory and machine learning. Currently I am working with X++ and Microsoft Dynamics.