Invoking .NET methods via reflection
Reflection is the ability of a program to control its own structure and change the flow dynamically at runtime. .NET Framework provides reflection capabilities through the System.Reflection
assembly. The key class implemented in this assembly is Type
, which gives access to the instantiation of datatypes and allows inspecting type methods and properties.
How to do it...
The following example executes one of two functions on a List object, when the function name becomes known only in runtime.
Create a
Page
object in the C/SIDE page designer. This will be a container for actions executing reflected functions.The code of the function is as follows:
       Item.FINDSET;       REPEAT       ItemList.Add(Item.Description);       UNTIL Item.NEXT = 0;
Create a function in C/AL Globals and name it
RunFunction
. It should have one text parameter,FunctionName
.Declare local variables. All classes in the list are compiled in the
mscorlib
assembly:Name
...