Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Enabled for | Public preview | General availability |
---|---|---|
Admins, makers, marketers, or analysts, automatically | ![]() |
![]() |
Business value
Contractual behavior of interfaces limits updates and future extensibility. Adding casting greatly increases the usefulness of interfaces in AL. In this version, the AL language supports type testing and casting interfaces. Two new operators, is
and as
, facilitate these operations. The is
keyword checks if an interface is a specific type. This check is useful for ensuring type safety within code. The as
keyword attempts to cast an interface to another interface. These operators improve the extensibility and usefulness of interfaces in AL. They align with the broader programming practice of building systems for future growth and adaptability. With these operators, you can update and maintain your code seamlessly.
Feature details
In this version, we introduce support for casting between AL interfaces. Given an interface A, you can cast it to interface B if the underlying object (only codeunit objects for now) implements interface B. To make these operations easier, we added two new operators: is
and as
.
The is
operator
The is
operator lets you test whether an instance of an interface or the content of a variant supports a specific interface. Here's the syntax for using the is
keyword:
You can also use the is
operator with variants:
The as
operator
Use the as
operator to cast an instance of an interface to a specific interface. If the source interface doesn't implement the target interface, the operation throws an error at runtime. Here's an example:
The as
keyword works with variants too:
Geographic areas
Visit the Explore Feature Geography report for Microsoft Azure areas where this feature is planned or available.
Language availability
Visit the Explore Feature Language report for information on this feature's availability.
Tell us what you think
Help us improve Dynamics 365 Business Central by discussing ideas, providing suggestions, and giving feedback. Use the forum at https://aka.ms/bcideas.