Macros. How to use macro variable on fly?

Macros. How to use macro variable on fly?

I have no love for macros, using constants in the standard layers is what I was missing in earlier versions. As you know, using macros is not recommended (xpp-macros). Macros are supported for backward compatibility only. It also has many disadvantages compared to constants (constants-read-only-variables-and-macros). Often we can see their use, namely standard elements and patterns (instead of duplicating logic).

As an option, you can use macros on the class declarations level, but with a specific reference to the value in that macro (pull request). This will not impact compiler performance, and you can enable existing standard macros to have cross-references in your development model (as well as all the capabilities of a constant variable and have minimal regression work if macros are abandoned in the future).

private const int RetryNum = #OCCRetryCount#RetryNum;        

One more use of a macro variable directly in a code

try
{
    //todo something
}
#OCCRetryCount#StandardRetryCatchBlock        

P.S. I emphasized the class declarations level because declaring a macro as a file significantly impacts the compiler (range-scope-of-macros).

Christian Madsen

Senior Architect/Developer

7 个月

Well, X++ shouldn't really exist at all anymore ??

回复

Macros are on my top 3 of things I wish didn't exist in X++. The other two are public-by-default and dangling-semicolons. One down, two to go. ??

Alexey Smirnov

Microsoft Dynamics Developer

7 个月

Great work ??

要查看或添加评论,请登录

社区洞察

其他会员也浏览了