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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 15.12.2015, 12:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
mfp: X++ in AX7: Readonly keyword
Источник: http://blogs.msdn.com/b/mfp/archive/...y-keyword.aspx
==============
In AX7 X++ now supports the readonly keyword. Semantically it is identical to readonly in C#.

In short; it allows you to define members on a class that can only be initialized in the declaration and in the constructor.

class MyClass
{
readonly str identifier = "XYZ";
readonly str identifier2;

public void new(str _identifier)
{
identifier2 = _identifier;
}

public void foo()
{
// The field 'identifier2' is read only. A value cannot be assigned to it.
//identifier2 = "ABC";
}
}





The big question is "when to use it?" In my opinion the actual use scenarios are limited – simply because other language constructs are still missing.

In X++ we still recommend the construct pattern and the newFrom pattern. These patterns recommend the new method to not have any parameters – readonly has little applicability, when the new method is parameter-less.

So why do we prefer parameter-less new methods?

  1. It enables serialization of classes using the pack/unpack pattern – all classes extending RunBase are subject to this.
  2. It enables the extension framework and smart customizations.
Once X++ supports getters/setters and method overloading (at least of the new method) – then readonly will become handy.

If you have a good use scenario for readonly - please share in the comments section below.



THIS POST APPLIES TO MICROSOFT DYNAMICS AX7 TECHNICAL PREVIEW; IS PROVIDED AS-IS AND CONFERS NO RIGHTS.




==============
Источник: http://blogs.msdn.com/b/mfp/archive/...y-keyword.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 15.12.2015, 14:07   #2  
mazzy is offline
mazzy
Участник
Аватар для mazzy
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
29,472 / 4494 (208) ++++++++++
Регистрация: 29.11.2001
Адрес: Москва
Записей в блоге: 10
вот, блин... лучше бы геттеры и сеттеры сделали, как у нормальных людей.
За это сообщение автора поблагодарили: Logger (2).
Старый 15.12.2015, 14:52   #3  
Logger is offline
Logger
Участник
Лучший по профессии 2015
Лучший по профессии 2014
 
3,874 / 3123 (112) ++++++++++
Регистрация: 12.10.2004
Адрес: Москва
Записей в блоге: 2
Именно что.
Параметрические методы еще удобнее тем что с их помощью проще поймать то место которое меняет значение параметра на нежелательное. Ставишь точку останова и если надо, дописываешь пару строк кода для ловли нужного значения. Отладка ускоряется радикально.
Старый 15.12.2015, 18:22   #4  
belugin is offline
belugin
Участник
Аватар для belugin
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,622 / 2925 (107) +++++++++
Регистрация: 16.01.2004
Записей в блоге: 5
Цитата:
Сообщение от mazzy Посмотреть сообщение
вот, блин... лучше бы геттеры и сеттеры сделали, как у нормальных людей.
Конечно про проперти знают. Возможно, трудоемкость их добавления просто выше чем для readonly.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
mfp: X++ in AX7: Internal keyword Blog bot DAX Blogs 25 20.12.2015 19:36
mfp: X++ in AX7: Reals are decimals Blog bot DAX Blogs 0 14.12.2015 22:11
mfp: X++ in AX7: Static event subscription Blog bot DAX Blogs 0 11.12.2015 11:11
mfp: X++ in AX7: The var keyword Blog bot DAX Blogs 43 04.12.2015 10:19
mfp: X++ in AX7 Blog bot DAX Blogs 0 02.12.2015 22:13

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

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

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