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).
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. ??
Microsoft Dynamics Developer
7 个月Great work ??