最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

X++ and Ax7 Whats Changed

网络文摘 William 2010浏览 0评论

A lot of changes have taken place in the X++ language and to align it close to the C# model which is where we want to be. There is no longer any p-code compilation, everything is run from the CIL.

This my compilation of what has changed and some examples for them as well.

Editing Experience: Visual studio interface only. Finally a more structured way of viewing code.

Declare anywhere :star:

for(int i = 0; i< 10; i++)
{
  // variable i can only be referenced here
}
// Try to retrieve i here and you will receive a compile error

The var keyword: :star:

</pre>
<pre>var counter = 0;
var custTable = salesTable.custTable();

Static constructor and fields: Static member variables Static constructors: TypeNew

class AClass
{
    static string staticString;
    static void TypeNew()
    {
        AClass::staticString = "Static World!";
    }
}

Macros: As i suspected, try avoiding these guys. Will be deprecated in later releases (my view) const (constant) and readonly:

class Square
{
    public const int Sides = 4; // this value cannot be changed
    readonly real _length = 10; // this is a default

    void new(real length)
    {
        this._length = length; // readonly can be changed in constructors only
    }
}
Field Access: :star:
Field access was only protected in Ax (no questions asked, and nothing else you can do about it)
Now: if you havent specified the access they are still protected, but you can specify public, or private
class MyVariables
{
    int myInt;
    protected int myInt2;
    public string Name;
    private real _qty;
}
class MyVariables2 : MyVariables
{
    void WhatCanIDo()
    {
        myInt++;
        myInt2 = myInt + 10;
        Name = "My New World!";
        _qty = 100; // Compilation error
    }
}

class AccessVariables
{
    void WhatCanIDo()
    {
        var myVariables = new MyVariables();
        myVariables.myInt = 10; // Error
        myVariables.myInt2 = 100; // Error
        myVariables.Name = "Hello";
        myVariables._qty = 100; // Error
    }
}

Access variables by reference :star:
Lets the above example

class MyVariables
{
    int myInt;
    public string Name;

    public void AccessVarisables()
    {
        this.myInt = 5;// This references to itself,and works with intellisense :)
        this.Name = "Hello World!";
    }
}
class Access
{
    public AccessVariables()
    {
        var myVars = new MyVariables();
        myVars.Name = "Hello New world!"; // Name is accessed via the class object,no more Parm methods required;
    }
}

try / catch / Finally: :star:

try
{

}
catch(Exception::Error)
{
    // you can add multiple catch types as normal
}
finally
{
   // this code always gets called. So you can do things like close file handles
}

using statement: :star:
Using is here, this is very neat. It destroys the object and the object only exists within the context of the using. Object in the using should implement IDisposable, so all / most of the Streams are an example or webRequests.

using(var sw = new System.IO.StreamWriter("file.txt"))
{
     sw.writeLine("Hello World!");
}

Implement .Net Classes:
Classes in X++ can implement the C# classes 🙂 , so your X++ class can implement IDisposable

Extension Methods:

There are very similar to C# extensions, except the convention is to end the class with _Extension and not Extension

static class HelloWorld_Extensions // Convention is to have _Extension
{
// This adds a method to the salesTable called SalesString returning a string
// salesTable.SalesString()
public static str SalesString(SalesTable salesTable)
{
return salesTable.SalesId + "-" + salesTable.CustName();
}

// you can add more extensions here targetting different types
}

Declarative Eventing (Methods and objects):

Ax 2012 gave us the ability to add events to methods. This is still the same, i.e. events still exist, exept they are called declaratively (i.e. in code and no clicks).

Although, the way to access arguments is still not to my liking and even though it seperates code out a lot, any errors are at runtime only, which can be very “hard” to manage

Casting is standard now:

// Planet class is implemented by class Earth.
var Earth = new Planet(); // this is incorrect, used to work before

Filed under: AX7, Dynamics Ax, X++

转载请注明:ww12345678 的部落格 | AX Helper » X++ and Ax7 Whats Changed

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址