What's New: X++ for Developers in Microsoft Dynamics AX 2012

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

This topic describes the new and enhanced X++ features that are available in Microsoft Dynamics AX 2012.

What is new or changed?

This section provides details about the improvements that were made in X++.

  • .NET Proxies to X++ Classes

  • X++ Attributes

  • New Expression Operators in X++ for Inheritance

  • Events in X++

  • X++ Compiled to .NET CIL is Faster

Gg843765.collapse_all(en-us,AX.60).gif.NET Proxies to X++ Classes

What can you do?

Microsoft Dynamics AX 2009

Microsoft Dynamics AX 2012

Why is this important?

Where can I find more information?

Create proxy classes to represent .NET interop to X++.

The feature was not supported.

A .NET proxy is a .NET managed class that represents a class or table that exists in Microsoft Dynamics AX. Your managed program can call proxy methods, just as your X++ code can call methods on a table or class.

The C# compiler detects errors in your calls to the proxy at compile time. You can use this early-bound programming model to fix errors in your code before the code is run. The internal logic of the proxy class uses the late-bound programming model of .NET Business Connector. However, the tools that automatically generate the source code of the proxy have been rigorously tested.

Proxy classes enable you to write managed classes that interoperate with your X++ classes, to form a unified application.

For more information, see Proxy Classes for .NET Interop to X++.

Gg843765.collapse_all(en-us,AX.60).gifX++ Attributes

What can you do?

Microsoft Dynamics AX 2009

Microsoft Dynamics AX 2012

Why is this important?

Where can I find more information?

Use X++ attribute classes for metadata.

The feature was not supported.

X++ classes and methods can now have metadata in the form of attribute classes. An attribute class is any non-abstract class that inherits from the SysAttribute class. Detailed metadata is assigned through the constructor of the attribute class.

Tables and interfaces can also have attribute classes.

By using attributes, you can associate declarative information with X++ code. After an attribute is associated with a program entity, the attribute can be queried at run time and used in many ways.

For more information, see Attributes on X++ Types and Methods.

Gg843765.collapse_all(en-us,AX.60).gifNew Expression Operators in X++ for Inheritance

What can you do?

Microsoft Dynamics AX 2009

Microsoft Dynamics AX 2012

Why is this important?

Where can I find more information?

Use the is operator to test whether X++ objects are a type or a subtype of a specific class.

The feature was not supported.

The X++ language now has the expression operator is. You use the is operator to test whether an object is a type or a subtype of a specific class or table.

When the is operator is used, your code can test whether a particular downcast assignment would be valid.

For more information, see Expression Operators: Is and As for Inheritance.

Use the as operator to make downcast assignments explicit.

The feature was not supported.

In Microsoft Dynamics AX 2009, downcast assignments were implicit. Flawed X++ code sometimes assigned an object to a variable type that was outside the inheritance hierarchy of the object. This incorrect assignment sometimes caused confusing errors during run time.

You can use the as operator to make downcast assignments explicit.

When the as operator is used to make a downcast assignment explicit, the incorrect assignment of the object is prevented during run time. The null value is assigned instead. Therefore, it is easier to diagnose the run-time error.

For more information, see Expression Operators: Is and As for Inheritance.

Gg843765.collapse_all(en-us,AX.60).gifEvents in X++

What can you do?

Microsoft Dynamics AX 2009

Microsoft Dynamics AX 2012

Why is this important?

Where can I find more information?

Implement events and event handling in X++.

The feature was not supported.

The X++ language now has the delegate keyword. When program conditions meet the programmer's criteria for the event, the X++ code can call the delegate. The delegate then calls all the event handler methods that were subscribed to the delegate.

The members of a class can include both methods and delegates.

You can subscribe methods to a delegate by dragging the methods onto the node for the delegate in the Application Object Tree (AOT). Alternatively, you can subscribe methods to the delegate in X++ code by using the += operator together with the eventHandler keyword.

An X++ event can be handled by event handler methods that are written in either X++ or managed languages such as C#.

The event programming model can reduce the chance that your customizations are affected by upgrades to your program or to Microsoft Dynamics AX.

For more information about events and delegates, see the following topics:

Pre-method and post-method events are generated by the system.

The feature was not supported.

The methods on your X++ class each raise an event immediately before they start. The methods raise another event immediately after they end. These two events offer opportunities for custom code to intervene in the program flow.

The pre-method event handler can modify the parameter values before the values are passed to the method. Before the caller of the method receives the value that is returned by the method, the post-method event handler can modify the return value.

The CalledWhen property of each event handler in the AOT Properties window makes it easy to choose between a subscription to the Pre or Post event of the method.

The pre-method and post-method events are stable points at which custom code can run.

For more information about pre-method and post-method events, see Event Handler Nodes in the AOT.

Gg843765.collapse_all(en-us,AX.60).gifX++ Compiled to .NET CIL is Faster

What can you do?

Microsoft Dynamics AX 2009

Microsoft Dynamics AX 2012

Why is this important?

Where can I find more information?

Speed up X++ batch jobs.

The feature was not supported.

Some X++ batch jobs can now complete in much less time. All X++ code that runs on the AX32.exe client still runs as interpreted p-code. However, all batch jobs now run as Microsoft .NET Framework CIL, which is often much faster than p-code.

The X++ developer must now complete the extra step of compiling X++ p-code to CIL. To compile p-code to CIL, right-click AOT, and then click Add-ins > Incremental CIL generation from X++.

Next, if the installation uses multiple instances of Application Object Server (AOS), all AOS instances must be stopped and then restarted. This causes the AOS instances to load the updated assembly.

Finally, a service or a batch job must run the X++ code that was compiled to CIL. Services and batch jobs now run only as CIL.

Some batch jobs run much faster as CIL than they did as p-code.

For more information, see X++ Compiled to .NET CIL.

See also

What's New in Microsoft Dynamics AX 2012 for Developers

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.