AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 14.09.2017, 13:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
shashidotnet: X++ and Ax7 Whats Changed
Источник: https://shashidotnet.wordpress.com/2...whats-changed/
==============

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

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 errorThe var keyword: ⭐

</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 privateclass 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
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: ⭐

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: ⭐
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++

Источник: https://shashidotnet.wordpress.com/2...whats-changed/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 10:28.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.