Are you still using macros? Be sure you read this.

 




You still use a lot of macros in your code, don't you?

Of course you should: Macros, as per Microsoft,  are precompiler directives are processed before the code is compiled. The directives declare and handle macros and their values. The directives are removed by the precompiler so that the X++ compiler never encounters them. The X++ compiler only sees the sequence of characters written into the X++ code by the directives.

However macros, are not quite recomended by Microsoft. They are slow, they can be subsequently deorectaed at any later time. The Macros are actually a type of classes, only that they are not instantiated and not need be defined as classes. Hence runtime garbage collection could be a huge issue, consquently (a class when gets out of scope, gets garbage-collected owing to the destructor classes of DOT net instrumentation classes). Summing up, macrros are a bit old way of writing code.

Use static classes instead.

public static class MyIdentifierMarcoClass.

And I have defined my contants like this in my main:


    public const string peakValue = "January 10th";

    public const string voltVal = '10'



And then in your code simply refer to this class constants by:

private void processnow()

{

    purchParm = PurchParamateres::find();

    If (purchParm.VoltVal == MyIdentifierMarcoClass::voltVal)

    {

        this.postTaxes(salesInvoiejour, salesTotals);

    }

}

This is a smart way to avoid macros by using static classes and thereby avoiding a number of cascaded complexities. 

Comments

Popular posts from this blog

X++ : mistakes which developers commit the most

Make your menu items visible on main menu, conditionally,, using this cool feature of D365FO

Speed up your execution performance by using SysGlobalCaches