Monday 19 November 2012

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

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

What is new or changed?

  • .NET Proxies to X++ Classes
What can you do?:
    Create proxy classes to represent .NET interop to X++.   

Microsoft Dynamics AX 2009:

    The feature was not supported.

Microsoft Dynamics AX 2012:
    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.

Why is this important?:

    Proxy classes enable you to write managed classes that interoperate with your X++ classes, to form a unified application.
  • X++ Attributes
What can you do?:
    Use X++ attribute classes for metadata.

Microsoft Dynamics AX 2009:
    The feature was not supported.

Microsoft Dynamics AX 2012:
    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.

Why is this important?:
    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.
  • New Expression Operators in X++ for Inheritance
What can you do?:
    Use the is operator to test whether X++ objects are a type or a subtype of a specific class.

Microsoft Dynamics AX 2009:
    The feature was not supported.

Microsoft Dynamics AX 2012:
    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.

Why is this important?:
    When the is operator is used, your code can test whether a particular downcast assignment would be valid.


What can you do?:
    Use the as operator to make downcast assignments explicit.

Microsoft Dynamics AX 2009:
    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.

Microsoft Dynamics AX 2012:
    You can use the as operator to make downcast assignments explicit.

Why is this important?:
    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.
  • Events in X++
What can you do?:
    Implement events and event handling in X++.

Microsoft Dynamics AX 2009:
    The feature was not supported.

Microsoft Dynamics AX 2012:
    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#.

Why is this important?:
    The event programming model can reduce the chance that your customizations are affected by upgrades to your program or to Microsoft Dynamics AX.


What can you do?:
    Pre-method and post-method events are generated by the system.

Microsoft Dynamics AX 2009:
    The feature was not supported.

Microsoft Dynamics AX 2012:
    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.

Why is this important?:
    The pre-method and post-method events are stable points at which custom code can run.
  • X++ Compiled to .NET CIL is Faster
What can you do?:
    Speed up X++ batch jobs.

Microsoft Dynamics AX 2009:
    The feature was not supported.

Microsoft Dynamics AX 2012:
    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.

Why is this important?:
    Some batch jobs run much faster as CIL than they did as p-code.

My above blog is based on Microsoft's Official information.
 
I hope this blog about 'Microsoft Dynamics AX 2012 - What's New: X++ for Developers' was informative. Please feel free to leave your comments.

No comments:

Post a Comment