Edit

Organize AL code with region directives

APPLIES TO: Business Central 2020 release wave 2 and later

Organize code into regions

Use the #region directive to mark a block of code that you can expand or collapse. Regions can improve readability in large files and help you focus on the code you're currently editing. The #endregion directive specifies the end of a #region block.

Note

Add a comment after the #region directive to describe the code block, as shown in the following example.

Syntax

#region [comment]
    code
#endregion

Remarks

A #region block must be terminated with a #endregion directive.

A #region block can't overlap with an #if block. However, a #region block can be nested in an #if block, and an #if block can be nested in a #region block.

Example

In this example, the #region directive makes a code block that is up for refactoring collapsible.

#region Refactoring candidate
    procedure CalculateLegacyValue()
    begin
        // Refactor this implementation.
    end;
#endregion

Development in AL
AL development environment
Pragma directive in AL
Conditional directives
Deprecating explicit and implicit with statements