Dynamics Ax: X++ what’s new

Hi All!

As you’ve probably already heard the new major release of Dynamics Ax is out and it’s called Microsoft Dynamics Ax! I have been to the Ax7 technical preview conference so I’ve already prepared some content for you and now that the release is official I can share it all. Dynamics Ax comes along with a whole bunch of new goodies and the new compiler being the biggest one. This allowed Microsoft to implement a whole bunch of new keywords in our beloved X++ language.

This keyword for variables

We already had the this keyword for calling methods, but now we can also use it to assign values to variables or pass them.

Static constructors and fields

You all probably know this but a static variable is a variable shared among all instances of a class. And what do all we pattern loving developers think? Exactly the singleton pattern is finally possible without dirty caching tricks!

The static constructor is called TypeNew()

  • These are automatically called before the first use of a class.
  • These are called once for each type and each session.

Var variables and declaration

Declaring a variable as a var type (implicitly typing) will let the compiler decide which type it is, therefor you don’t have to. When a var variable is assigned to a type this cannot be changed anymore.

And from now on you can also declare anywhere!

Const/readonly variables

  • Const: This is a constant and can only be assigned a value when declaring it.
  • readonly: The value of this variable can be changed at runtime but only through a constructor.

Public / protected / private access modifier for variables

Data encapsulation can now implemented decent because as in C# we can declare our variables public, protected or private. This makes code more robust when implemented well.

  • public: Access is not restricted.
  • protected: Access is limited to the containing class or types derived from the containing class.
  • private: Access is limited to the containing type.

The difference with C# is that the default modifier still is protected, because changing it to private would break too much existing application code.

Finally in try/catch statements

Finally! A way of executing code when either the entire try statement has finished or a handled exception has occurred.

Typed exceptions

And exception handling even get’s better! Because now we can handle any exception that extends from System.Exception. Which is a big leap forward when using the .NET framework.

Using keyword

No more worries about memory leaks when consuming unmanaged resources because now you can use the using keyword for objects that implement IDisposable.

Extension methods

What if there was a way to add methods to an object without modifying it in your customization layer? Well now there is, it’s called extension methods and the principle is the same as in C#.

Some reminders when using this:

  • Use these in a static class.
  • The name of the class must have the suffix “_Extension”.
  • The method is public.

Declarative enventing: with pre and post events

In 2012 we already had eventing, but one minor flaw most developers had issues with was that you had to change the object you where subscribing to. Since we run fully in IL it is possible to subscribe to an event without modifying the sender object.

For instance the DirPartyTable has a delegate method dirPartyDeleted.


Using clauses

Remember the days when you want to use a .NET library and you always had to write the entire namespace? Well those days are over.

Enjoy your coding with all the new goodies! 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.