.NULLABLE
|
|
|
NSupported in Synergy .NET
|
.NULLABLE enable|disable
Arguments
enable
Indicate the start of a nullable region.
disable
Indicate the end of a nullable region.
Discussion
The combination of .NULLABLE enable and .NULLABLE disable can be used multiple times in a single file to indicate the start and end of a nullable region. Inside a nullable region, reference types are not intended to be null. Assigning or initializing a non-null variable will result in a level 3 INVTYP or INITVERR warning, depending on whether the variable is being assigned or initialized, respectively.
You can use a null suppression operator (!) to suppress nullability warnings that involve a particular variable or expression. See Null suppression operator for more information.
Nullable directives inside a record don’t give warnings on uninitialized reference type variables within that record.
Nullable regions can only be used in projects that target .NET 6 and higher. If you attempt to use .NULLABLE in a non–.NET 6 and higher project, you’ll get a NOTSUPT error.
See also
Examples
In the example below, the field fldn is allowed to be nullable even though it’s in a nullable region because the question mark operator (?) has been appended to the end of the type name, and this particular type is a reference type instead of a value type. However, the field fld resides in a nullable region and has no question mark. It should not be initialized with the contents of the field fred, because fred is outside of a nullable region and is therefore “potentially null.” A warning will be given for this kind of initialization.
public class class1 public fred, @class1 ;Implicitly null because never initialized .nullable enable public fld, @class1, fred ;Not allowed; give warning if initialized to ^null ; (fred is null field) public fldn, @class1? .nullable disable endclass