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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 29.06.2016, 23:13   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
goshoom: Code snippets in AX 7 – Introduction
Источник: http://dev.goshoom.net/en/2016/06/co...-introduction/
==============

Code snippets, in general, are small pieces of code that often can’t be used separately, but they’re rather intended to be integrated in a larger solution. Visual Studio offers several features for working with snippets, and because Dynamics AX development is now done completely in Visual Studio, X++ developers can use them too.

Let’s start with something trivial. Open X++ code editor (e.g. create a runnable class), open context menu (right click) there and select Insert Snippet. Notice the keyboard shortcut (Ctrl+K and then X); it’s very handy if you use snippets more often.



You’ll get a list of available snippets. Choose ctor (constructor) for now:



This inserts source code for a constructor at current cursor position.



Although pasting a static piece of code can be useful, it’s not very exciting. Let’s look at the For snippet instead:



For now, put the snippet directly to the class definition, not inside a method. There is a certain problem that could lead to incorrect behavior – I’ll explain it in detail in a separate post.

This will create a for loop, but that’s not all. Notice that there is i variable, used at three places, and that the first occurrence is selected:



You can immediately start typing and change the name; press Tab when you’re done. All three occurrences of i change to the new name and the cursor moves to the next place that you likely want to change – the condition.



This is really helpful – you don’t have to manually change the same thing several times and you’re navigated directly to those places you should change, ignoring static parts. Also don’t forget that this is just a simple demonstration – you can use the same approach for much more complex scenarios.

Another thing you can do is to put a snippet “around” a selected piece of code. For example, let’s say that I’ve just realized that I need exception handling for my code. I select the code and choose Surround With from the context menu:



Then I pick the try snippet, which puts my code into a try block and I can immediately start writing my exception handling logic.



We have editor scripts in MorphX IDE, but they aren’t as easy to use as they should be. Code snippets in Visual Studio are a welcomed, powerful improvement.



Источник: http://dev.goshoom.net/en/2016/06/co...-introduction/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
goshoom: New X++ features in AX 7 Blog bot DAX Blogs 0 19.02.2016 01:13
atinkerersnotebook: Part Two of Introduction To Dynamics AX Now Available As Premium Content On Dynamics AX Companions Blog bot DAX Blogs 0 30.08.2014 19:16
axsa: MDM Adapter - Extending Dynamics AX 2012 R3 Master Data Management Blog bot DAX Blogs 0 22.05.2014 03:28
dynamics-ax: Interview with Microsoft's Lachlan Cash on his new role, AX 2012 and more Blog bot DAX Blogs 6 22.04.2011 14:55
wiki.dynamicsbook: Changes Made in Navision Attain 3.60 Blog bot Dynamics CRM: Blogs 0 02.09.2008 13:23

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

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

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