Upravit

Sdílet prostřednictvím


Pragma Warning directive in AL

APPLIES TO: Business Central 2020 release wave 2 and later

The #pragma warning instruction can enable or disable certain warnings. This can be used as a solution to avoid getting warnings on, for example, string length on fields that you can't change. With the #pragma warning disable statement you disable the emit of the warning for a specific location in code, and with #pragma warning restore you restore the warning back to its original state. If you don't restore, the disable instruction is valid for the rest of the file.

Important

It's important to be aware that most warnings are there for a reason, and suppressing them could lead to sudden impact if warnings are changed to errors, such as obsoletes.

Syntax

#pragma warning disable warning-list  
#pragma warning restore warning-list  

Parameters

warning-list A comma-separated list of warning numbers.

When no warning numbers are specified, disable disables all warnings, and restore enables all warnings.

Note

To find warning numbers in AL, build your AL project in Visual Studio Code and then look for the warning numbers in the Output window. For more information, see Using the Code Analysis Tool.

Example

The following example illustrates how the specific rule AL0468 is temporarily turned off for a specific field definition.

table 50110 MyTable
{
    fields
    {
        #pragma warning disable AL0468
        field(1; TableWithLongIdentifierThatExceedsOurMax; Integer) { }
        #pragma warning restore
    }
}

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