Open Forum

 View Only
Expand all | Collapse all

AL language support for generic classes, or: datastructures containing instances of a self-written class

  • 1.  AL language support for generic classes, or: datastructures containing instances of a self-written class

    Posted Oct 26, 2020 04:03 PM

    #Technical #D365BusinessCentral

    Hi Business Central experts,

    The AL language is getting closer to object oriented programming​​​​. I see support for interfaces had been recently added.
    In Java and C# you have generic classes, like Dictionary and List.
    It means you can write your own class (codeunit) called MyClass and then you can have List<MyClass> and Dictionary<int, MyClass> e.g. in C#.

    What is the recommended way in AL if you want a datastructure that contains objects of a a self-written class (codeunit)?
    Is such a thing possible already? If not, what are known workarounds?

    I know of course

    var
        myList: List of [Text];
        myDict: Dictionary of [Integer, Text];

    It is clear you cannot put "Codeunit MyClass" in place of "Text". So, what to do?

    With best regards,



    ------------------------------
    Wolter Kaper
    Entocare C.V.
    Wageningen
    ------------------------------


  • 2.  RE: AL language support for generic classes, or: datastructures containing instances of a self-written class

    Posted Nov 15, 2020 11:17 AM
    I will add my own solution to this thread.
    I used
    array[100] of Codeunit X
    instead of using a List. It has the disadvantage of having to declare the size in advance, but it seems the only way of getting a CodeUnit instance into a data structure.

    With best regards, Wolter

    ------------------------------
    Wolter Kaper
    Entocare C.V.
    Wageningen
    ------------------------------



If you've found this thread useful, dive deeper into User Group community content by role