Blogs

Rory Becker - DevExpress CodeRush Blog

New “Goto” TextCommand in CodeRush 11.1

     

You will recall from our previous discussion, that Navigational TextCommands allow a template author, to inject different pieces of themselves into different parts of the TextDocument.

The newest addition to this group of TextCommands is «GoTo». It takes a single parameter (Constructors, Fields, Methods or Properties) used to indicate the type of code to locate.

During execution, «GoTo» will move the insertion point immediately prior to the first LanguageElement of the indicated type. This allows templates to navigate to the first of any of these items within the current type, inject some text and then return to the origin. The effect of this can be to group elements of a given type together and promote more readable code.

As we will see later, the p?type? template has been upgraded under 11.1, and uses this technique to separate backing store from property where appropriate.

Note: The «GoTo» TextCommand does not move the insertion point, if the item being searched for does not exist. Therefore it is advisable to create duplicate templates to handle each of these cases. In the case where the case where the target item does exist, you can simply use «GoTo» as advised. In the case of it not existing, you can choose to locate your new item elsewhere. Of course the best way of doing this is through the use of the New Contexts also provided in CodeRush 11.1

So the next time you’re creating a template which emits a field, consider creating a parallel version of it that tests Editor\Code\HasFields  and wraps the field itself in «StoreInsertionPoint(MyField)»«GoTo(Fields)» and «GotoInsertionPoint(MyField)» to ensure your new fields is placed alongside others in the same type.

Published Jun 06 2011, 03:22 PM by Rory Becker - DevExpress
Bookmark and Share

Comments

No Comments
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.