The new Convert To Point refactoring converts a pair of numeric values into a single point value. As you might expect, it also adjusts the call site, method signature and usages to conform with the new point value.

The new Convert To Tuple refactoring can be applied to 2 or more parameters of a method.

As it’s name suggests, it replaces the parameters in question with a suitable Tuple. It further ensures that calls to the method as well, as internal references to the parameters, are updated appropriately.

How many times have you hit Ctrl+Home or Ctrl+End (to navigate to the start or end of a file), only to realize mere seconds later, that you forgot to copy something to the clipboard before you left.

Now you have to find where you were, copy the code you were after, and then jump back.

There are several ways to get back to where you were:

Remember some snippet of code in the vicinity of where you want to be, and use VS’s find window.

Remember the name of the method you were in, and navigate to it using Quick Navigation, then locate the code within the method.

Page Up or Down to the location of your code. Scanning whole pages of code as you go in case you miss it.

Reach for the mouse and use the vertical scrollbar. While many people don’t like the mouse, this does give finer grain control than Page Up and Down.

Remember the exact line you were on and use Goto line (Ctrl+G)

View.NavigateBackward (See alternatives section after summary)

Wouldn’t it be great if you’d already dropped a CodeRush Marker before you left. That way you could just hit Esc and CodeRush would bring you back to where you were. It would even arrange the view the way it was before you left and restore the selection. Then you could copy the value you needed and return to whichever end of the file you wanted to.

Check the checkbox that says “after executing this command, pass shortcut to IDE for default handling”

Set context to Focus\Documents\Source\Code Editor

Right Click this new shortcut

Select Duplicate Shortcut

Select the Duplicate

Change key 1 to Ctrl+End

Click Ok.

…and you’re done.

Summary

All you really need to understand having done this is that you can now visit the top or bottom of a file (via Ctrl+Home or Ctrl+End) and then easily revisit the location you came from, by hitting Esc.

Alternatives

There are those that will point to the built in visual studio View.NavigateBackward (Alt+Left) function. However this command is for me, somewhat less useful. It does not restore my view to how it was before. It does not restore the selection and it does not provide any kind of locator beacon to help me focus on where I was.

The p?Type? template now emits any backing fields together in a single region. This renders the code easier to read, making it simpler to understand and maintain.

Consider the code expansion generated with the previous version of the p?Type? template…

As you can see, each field generated for backing store is placed next to the property that accesses it. This can be useful for grouping by function, but it can lead to code which is harder to read. Fields that are distributed in this way can be harder to locate are easily skipped over when scanning through code. We’ve long been asked for a way to group all te generated fields together in one place.

The new implementation of the p?Type? does exactly that, navigating to the first field in the type, injecting the field in this location and then returning to finish emitting the property at the location originally picked by the user.

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.

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.

As some of you might recall, several new pieces of functionality have arisen out of our weekly webinars. We have regularly implemented functionality on the spot simply to demonstrate the ease of doing so.

Since then it has obviously been optimized and put through quality control etc., to emerge the other side as the «?MemberHeader» and «?MemberFooter» StringProviders.

These each take a single parameter (one of Fields, Methods, Properties, or Constructors) and use this (together with the current language) to look up a suitable string (customizable via the options) which is then returned in the usual way.

For example the default expansion for «?MemberHeader(Fields)» under C# is:

// Fields …

…and in VB.Net the same value would be …

‘ Fields …

These are currently used in updates to p?Type? template, but can be used in your own templates as easily as any StringProviders

All these strings can be altered as usual via the appropriate options page (Editor\Code Style\ Member Sections) which as mentioned is language sensitive.

An noted in previous posts, contexts are one of the corner stones of the DXCore, that help make your user experience as natural as possible. More contexts allow features a finer granularity with which to test if circumstances should allow them to function.

For example: Templates intended to produce member code, should only be allowed to expand if the caret is within a type and also is not within another member. The p?Type? template is a good example of this. When activated from within a type (rather than from within a member), it produces a property of the correct type. Outside of this situation, it produces nothing.

CodeRush 11.1 adds 4 additional contexts which will return if the current type has any of each of the 4 named items within it.

HasConstructors

HasFields

HasMethods

HasProperties

These contexts can be found in the Editor\Code node within any context picker.

As ever, each of these contexts can have any one of 3 states

Tick – I require tis context to be explicitly true in order for the specified functionality to be considered valid.

Cross - I require this context to be explicitly false in order for the specified functionality to be considered valid.

Blank – The value of this context is not important to this function. Don’t test it.

Some of these contexts are used by new CodeRush 11.1 functionality, but all are available to be used by you if you feel the need. Consider these as 4 extra tools in your toolbox.

Feel free to contact me if you feel you need contexts beyond those provided out of the box, and I’ll be happy to show you how they are created. You never know… I might even send you a fully functional example.

Navigational TextCommands are those which pertain to the movement of the current text insertion point. The insertion point is the point at which text will be emitted during the execution of a template or other TextDocument manipulation.

Some example Navigational TextCommands are «GotoFileTop» and «GotoFileBottom» which, as you might guess, move the insertion point to the top and bottom of the current file respectively.

But what if you want to jump to one of these locations, emit some text and the jump back to where you started?

Well this has also been thought of.

The «StoreInsertionPoint» and «GotoInsertionPoint» TextCommands are for exactly this purpose. The «StoreInsertionPoint» will store the current location of the insertion point, using a lookup key passed to the command as its first parameter. The «GotoInsertionPoint» will retrieve a previously stored location likewise using a lookup key passed to it as a first parameter.