May 2017 - Posts

CodeRush for Roslyn: Webinar links

Following our recent 17.1 webinar on CodeRush for Roslyn, I wanted to follow up with a summary of the links posted in the chat during the Webinar.


CodeRush Setup Wizard

Previous CodeRush Features of the Week

T is for Test
Tab To Next Reference
Debug Visualizer

Our "Coding at the Speed of Thought" series

Introduction - CodeRush at the Speed of Thought
Declaring Types with Templates (CodeRush at the Speed of Thought)
Template Type Shortcuts (CodeRush at the Speed of Thought)
Declaring Properties (CodeRush at the Speed of thought)
Declaring Methods (CodeRush at the Speed of thought)
Inside Methods (CodeRush at the Speed of Thought)
Declaring Events (CodeRush at the Speed of Thought)
Declare from Usage (CodeRush at the Speed of Thought)

Feature callouts

Declare Menu – Overview - Documentation
Symbol Naming Assistant – Overview - Documentation
Clipboard History – OverviewDocumentation
Code Metrics – OverviewDocumentation
Smart Duplicate Line – OverviewDocumentation
Drop Marker before Jump - Overview - Documentation

Misc Links
Extract Interface – Documentation
Widen Scope – Documentation 
Widen Scope (Promote to field) – Documentation
Move Type to Namespace – Documentation
Reorder Parameters – Documentation

CodeRush for Roslyn: XAML support

XAML is an XML-based language developed by Microsoft, which is widely used in WPF and UWP applications. Visual Studio 2017 helps a lot with editing XAML: features like IntelliSense, tag auto-close and code fold are very useful and increase productivity, but what if your IDE could help you even more?

With the help of CodeRush for Roslyn, Visual Studio will better understand the relationship between the markup and the code. This will help you in many aspects, especially, navigation.

Let’s take a look at the most useful CodeRush for Roslyn features for XAML. Most examples are shown using the source code of the Material Design In XAML Toolkit.

Find References

You can use the References window in XAML. It will search for references in code and markup files across the solution.

Tab to Next Reference

What’s the fastest way to find symbol references within a file? You can use search, but it’s not very smart and may find too much. We invented the fastest way to find symbol references in a file. Just hit Tab while you are on an identifier and you will immediately jump to the next reference to it. Keep hitting tab and jumping to successive references. If you accidentally overshoot the reference you’re looking for, don’t panic. Just use Shift+Tab to move back through the references already seen. All references are highlighted for you to have a clear vision of your code while moving among symbol usages.

Jump to Resource

Seeing an image or resource dictionary in your code and wondering what is it? With CodeRush for Roslyn, you can press F12 to instantly open it.

Jump to Symbol Declaration

Navigates to the declaration of an identifier (in markup or Code Behind) from any reference in XAML file: tag, markup extension, templated parent, etc.


The whole power of CodeRush Templates is available in XAML! You can use templates from the template library and even create your own to maximize your productivity.

Let’s see some examples in action.

XAML Markup Formatting

Format XAML Document

XAML markup often has deep and complex structure, and if, while editing, the formatting is less than optimal, you may experience difficulties understanding its structure. You can fix it manually, but that can take a lot of work. You could use an online XML formatter, but that would involve copy/pasting and switching out to a browser. Now there’s a better option: you can format any XAML document right from the Visual Studio in a single click.


Of course, the formatting style is configurable, you can easily tweak it according to your own preference.


Break Apart/LineUp Attributes

One of the most useful XAML Formatting features allowing you to break apart or line-up attributes is available separately.



Import Type/All Types

From time to time we all need to reuse some code or markup from the Internet or from older projects. With the CodeRush for Roslyn, you can paste a piece of markup into your file and make it work with a single call to Import All Types refactoring.

Optimize Namespace References

The best code not only works flawlessly, but also looks great. Namespace References is the very first section in every code file and often it leaves space for improvement. The Optimize Namespace References refactoring can make it perfect in a single click: it automatically sorts references and removes the unused ones.

Convert Nested Element to Attribute/Attribute to Nested Element

Using these refactorings, you can extract an attribute from a XAML tag and make it a child element. You can also perform the reverse operation — inline a child element as an attribute of the parent tag. This refactoring can increase XAML readability when there are excessive attributes or when the nesting level gets too deep.


Visualization Features

Show Color

Computers and humans understand colors differently and in most cases a computer can show colors the way we used to them. But in software development we still have to speak with the computer in its language.

To change this state of affairs, we have the Show Color feature that adds a color preview to all colors you use in code.


You can even edit a color visually by clicking any preview stripe.


Structural Highlighting

Structure is an essential part of all XML-based languages, and sometimes the formatting is not enough to see the structure clearly. Structural highlighting draws lines to aid visualization of this hierarchy.


Region Painting

And we make regions look awesome!


Markup Creation Assistance

Selection Embedding

Surround something with a tag or region in a single click. You can even use Ctrl+W (Selection Expand) to select the whole block from its opening or closing tag.


Paste Vector Drawing as XAML

Imagine you have a vector drawing which you want to use in your app. For instance, you have it in Adobe® Illustrator®. With CodeRush for Roslyn, you can copy the drawing (or part of it) and paste it right into a XAML file.

Select the required pieces and copy them to the clipboard.


Then switch to Visual Studio and paste the clipboard contents into a XAML file. The drawing will be pasted in a vector format ready for you to scale and modify it as you need.


We support Microsoft® Visio®, Microsoft® PowerPoint® and Adobe® Illustrator®, but other vector editors also have a good chance to work.

Smart Duplicate Line

Use Shift+Enter to duplicate the current line. The Smart Duplicate Line feature watches and learns from your changes to improve the duplicate line experience, creating text fields for the parts of the line we expect you to change, and automatically incrementing numeric values if we detect an incrementing pattern.


CodeRush for Roslyn: ForEach to Linq

One really useful Refactoring provided by CodeRush for Roslyn is “ForEach to Linq

This refactoring is available whenever you have a ForEach that is iterating over a master list and attempting to select either a subset, or a single item, from that list.

Consider this legacy code example, where we have a list of orders and we want to extract a list of those orders which need Next-Day delivery.


Obviously that is fairly excessive. It’s also fairly complex to read.

  • There is a result set being prepared.
  • There is iteration over an incoming source set.
  • There is a condition being evaluated for each item in the source set.
  • There is the fact that passing items are being added to this result set.
  • Finally there is the returning of this result set at the end of the method.

So naturally we want to make this easier for you.

ForEach To Linq

So if you position your caret immediately left of the foreach, you will be able to select ForEach to Linq (Preview below)


Once selected, this refactoring will reduce your unsightly loop to a simple LINQ Query.


After this it’s pretty simple to reduce this to a single simple call.


I think we can all agree that this is much easier on the eyes and on the brain as well.

Everything has been reduced to a simple LINQ query.

Depending on your needs you could change this function to return an IEnumerable<Order> and strip the ToList() off the end of the expression.
At that point you may even decide that the function, which previously hid your complexity, is now no longer necessary at all, and you can Inline and Delete this method.

Another example is with the following type of legacy search code:
Here we iterate over a list searching for the first item to match, in this case, on the basis of a name.


The ForEach to Linq refactoring is again available from the foreach keyword.


Acceptance quickly removes the complexity of the original loop, replacing it with a simple Linq query.


A quick Inline Temp later and the previously overly complex iteration and select, together with it’s Result variable has been completely eliminated in favour of a single statement which


In both of these examples, CodeRush has reduced the complexity of your code, helping you to replace old world manual loops with a concise expression of the results you want.

These are just a few of the ways that CodeRush for Roslyn can simplify your life.

If you don’t already have your copy of CodeRush for Roslyn, hop along to and pick up your free 30 day trial.
The paid version of CodeRush for Roslyn can be had for as little as $49. That is amazing value.

CodeRush for Roslyn – Writing Tests Fast

So we’ve proved that CodeRush has the fastest .Net Test runner.

Next up I’m going to show you that CodeRush is also the quickest way to write tests.

Note: For the purposes of this post I’m going to assume that you’ve enabled Templates, and that you are using the Spacebar to trigger their expansion.
If you have not enabled Templates, you can use the setup wizard to do so now.

Writing Tests using CodeRush Templates

So how simple could it possibly be to start writing a new test?

How about t<space> ?

That’s only 2 keys!

Don’t believe me? Ok try this

  • Create a class library and add a reference to your favourite testing framework. I’m going to use NUnit which I’ve added via nuget.
  • Create a new class file and delete everything in it (Keep the namespace if you want.)
  • Choose an empty line and type the letter ‘t’ and then press the spacebar.

You’ll be presented with a new test fixture with the skeleton of a new test.
The name of the Test Fixture is already selected.

  • Change the name of the fixture to whatever you like.
  • Hit [enter] to confirm when you’re happy.

Your selection moves to the name of the test.

  • Change that to whatever makes the most sense to you.
  • Hit [Enter] to confirm once again.

Your caret is repositioned once again within the body of the test that you’ve just created.

This is roughly what you can expect this experience to be like.



If you count the characters I typed (t, [space], M, y, T, e, s, t, S, u, i, t, e, [Enter], M, y, F, i, r, s, t, T, e, s, t, [Enter]) You’ll come to 26 characters.

However 22 of those were the names of my fixture and test, (which we’d have to type no matter what) so really we’re only talking about 4 characters. 2 to generate the frame of the test (and the fixture) and another 2 to confirm we’re happy with what we’ve typed and to move on to the next bit of defining our test.

Whichever way you look at it…. That’s not a lot of effort.


How easy or hard was that? Could you do it again? What do we have to remember?

Well we have to remember that the test template is triggered with t and then [space] (or tab if you’ve got your preferences set that way).

That’s literally it.


Things get even simpler when you realise that you don’t always have to learn new template shortcuts for new purposes. CodeRush’s templates are context-sensitive. Which means that the same trigger can yield different expansions under different circumstances giving you even less to learn.

For example, if you invoke the t<space> template from within a test fixture, CodeRush spots that you already have the fixture and only generates a new test.



Ok well that was simple. What else can we do?

Well what do you need to do in a test when you get right down to it?

  • You setup a scenario.
  • You assert something about the scenario.

Well your setup will be specific to your needs, but assertions are mostly the same.

So does CodeRush have some tricks to help us assert a little quicker? …  Of course it does Smile

So what sort of things do we typically assert?

Well assertions (and therefore Tests) are all about checking something that should a certain way, and failing  (ie getting the developer’s attention) if that turns out not to be the case.

We assert equality and inequality

You Want To Template You Use Result
Assert Equality ae<space>
Assert Same as<space>
Assert Not Same ans<space>

…we assert that things are true and false

You Want To Template You Use Result
Assert True at<space>
Assert False af<space>

…and we compare with null

You Want To Template You Use Result
Assert Null an<space>
Assert Not Null ann<space>

As you can see CodeRush has you covered and always with a template that is intuitive and easy to remember.

I’m sure you’re starting to see the benefits of CodeRush templates. I’ll leave you there for now, and let these templates soak in. Just know that no CodeRush templates are hard wired. They can all be altered or tweaked to your needs, and you can even create your own… We’ll explore how to do that in a future post.

Get CodeRush for Roslyn Today

If you’d like to try out CodeRush for Roslyn, a 30 day trial can be found here on the Visual Studio Gallery.

CodeRush for Roslyn can be yours for as little as $49

CodeRush for Roslyn – Setup Wizard

Everyone is different. Everyone has their own preferences and their own approach.

If you’ve never used CodeRush before (or even if you have) its a good idea to use our new setup wizard to configure things at a high level, before diving into your next coding session.

The wizard will give you the chance to set base settings for several of our main features, so that they behave the way you’d like them to. There is no requirement to use the wizard, but we feel that doing so will improve your CodeRush experience greatly.

So what can you configure using the wizard?

Structural Highlighting

CRRSetupWizardStructuralHighlightingWhat is it?
Structural highlighting is where CodeRush lines are drawn between the start and end of various different types of block. This helps make sense of what is commonly called arrow code (Code which is heavily nested in successive blocks of different type). By using different colors to show the the blocks of ‘properties’, ‘accessors’, ‘foreach loops’, ‘conditional blocks’, ‘switch statements’ and ‘exception handling blocks’, CodeRush makes it much easier to determine very quickly where each of these start and end.

What can I configure?
The wizard options here are simple: Would you like Structural highlighting on, or off?

What if I need more?
The ‘Editor\Painting\Structural Highlighting’ section of our options screen (Ctrl+Alt+Shift+O) will let you change which block types are linked, their color and style.

Numeric Keypad Bindings

CRRSetupWizardNumericKeypadWhat is it?
Put simply this option causes CodeRush to assign a few additional shortcuts to the keys of your numeric keypad. This keypad goes unused by the majority of people and this option will reclaim several of it’s keys for quick access to some of our more popular functions.

Which shortcuts will be added?
Num-Plus - Selection Increase - Increase your code selection in logical block rather than character by character.
Num-Minus - Selection Decrease - Reverse the effects of ‘Selection Increase’ by similar logical blocks.
Num-Period – Jump to Menu –  Our general purpose go-to navigation menu (Full details here)
Num-Enter – Jump to Symbol – Our Symbol-specific navigation menu (Full details here)
Num-Zero – Code / Refactor Menu – The ever popular CodeRush/Refactor key. Quick access to all the Refactorings and CodeProviders suited to your current context.

These shortcuts involve fewer keystrokes than their default equivalents. They are also typically easier to hit given their increased size and useful location.

Spell Checker

CRRSetupWizardSpellCheckerWhat is it?
As you might expect, CodeRush’s Spell Checker is the simple ability to check the spelling of certain specified parts of your document. It is disabled by default but can be enabled from the wizard in any of 3 ways.

What can be checked?
This screen lets you enable spell checking for 3 distinct parts of your code: Comments, Strings and API-level Members and Identifiers.
(For our purposes, API-Level members and identifiers are those that are public, protected or internal )

What if I need more?
These settings can be tweaked and fine-tuned on our options screen (Ctrl+Alt+Shift+O) within the ‘Editor\Spell Checker’ page.
From here you can specify more locations to check, filter others out and specify the dictionary you’d like to use.

Tab to Next Reference

CRRSetupWizardTabToNextReferenceWhat is it?
Tab to Next Reference is the ability to place your caret within an identifier (method, variable, method) and hit Tab to initiate navigation between all the references to that identifier. I find this one as least as useful as the built in Go To Definition (F12)

Any other associated shortcuts?
Yes. Shift+Tab will carry you back through your references in the reverse direction, and once you are finished navigating through the references, you can hit Esc (or Alt+End) to return directly to your start point via a hidden marker.

This has to be one of the the easiest way to navigate through your code.

Smart Semi-Colon

CRRSetupWizardSmartSemiColonWhat is it?
Intelligently repositions your caret when you hit the semi-colon key, so that the semi-colon is emitted in the most sensible location.

Why would I need that though?
Consider features like the auto-completion of braces and parenthesis. These features are great because they finish what you start, so that you don’t have to. They leave your caret where it is, enabling you to continue working on your inner code.
A few method calls later, and you are potentially buried in parenthesis. Smart semi-colon is a simple but effective feature which allows you to hit the semi-colon without digging yourself out from under the parenthesis mountain first.

CodeRush will determine where the semi-colon should go, and position your caret there first before emitting the character.

One Key Selection Embeddings

CRRSetupWizardOneKeySelectionEmbeddingWhat is it?
Selection Embeddings are best described as CodeRush Templates that envelop your selected code.
A One-Key Selection Embedding is one which is triggered by the pressing of a single key. You select your code and then hit a trigger key. Instead of replacing the selected code with the key, the code is wrapped in text according to which embedding was invoked.

CodeRush provides several out of the box.

C – Wrap code in Try..Catch
F – Wrap code in Try…Finally
T – Wrap code in Try…Catch…Finally
– Wrap code in a set of braces. { … }

 Code Template Expansion

CRRSetupWizardTemplateExpansionWhat are CodeRush Templates?
Often described as VS snippets on steroids, CodeRush Templates are short sequences of characters which generate more verbose text within the editor. Templates can be used to create methods, classes enumerations, block constructs, unit tests, test assertions and much more.

What can I configure?
On this page of the wizard, you’ll decide how Templates will be triggered.

Personally I like to pick the Space key for maximum speed and ease of activation (After all that space bar is nice and big and easy to hit). Others pick the Tab key in order to reduce the risk of accidental template expansion. You can also elect to disable the template system from this page.



CRRSetupWizardMarkersWhat are Markers?
Markers are your virtual breadcrumbs. They are like stack based transient bookmarks in your code.

Why would I need another kind of bookmark?
So your coding along. Everything is going well, when you realise that you need to check something. Drop a marker. (Alt+Home) to mark your place and go investigate whatever you feel like. When your done, hit a single key (Esc or Alt+End) and return not just to when you were previously, but to the exact frame of reference you had before.

Markers stack, which means you can drop as many as you like digging deeper and deeper into your code. When you’re ready, you collect them in reverse order (just like virtual breadcrumbs) leading you back to where you started.

CodeRush will drop additional markers when you navigate away from where you are. Go To Definition (F12), Go To Symbol (Ctrl+Shift+Q or Num+Enter) or Jump To (Ctrl+Alt+N) will all drop markers allowing you to navigate away to investigate something and then hit Esc to return once you’re done.

What can I configure?
On this page you can decide if you’re like to enable Markers and further which shortcut you’d like to use to collect them.

Note: Since VS2013, Visual Studio has altered it’s behaviour when navigating. Following jumping to an identifier’s declaration (F12), Visual studio selects the name at that declaration assuming that you want to do something with its name. This means that those have grown used to using Esc to collect markers have had to press Esc once to remove the selection and once more to collect the marker. You can opt to let CodeRush work around this behaviour by choosing the last option on this page of the wizard. 

We highly recommend choosing the final option for your marker configuration in order to make your navigation experience as smooth as possible.


CRRSetupWizardIntelliRushWhat is it?
IntelliRush is the CodeRush version of IntelliSense.
It does every thing normal intellisense does, and more.

What extras do I get with IntelliRush?
You can Resize IntelliRush. Just grab the edge and expand your view.

You can filter content by member type: Restrict content to only Events, Properties or Extension methods (or something else) to quickly find the exact member you’re after.

You can filter content by hierarchy: Restrict content to a specific level of the hierarchy. Show only members declared on the class of the object being inspected, or choose another ancestor and show only members declared on that ancestor.

All filtering achievable using simple on-screen keystrokes whilst losing none of the power of intellisense.



The preferences you set in the Setup wizard are not permanent. You can return to the Wizard and change any of your choices at any time. Just open the ‘CodeRush’ menu and choose the ‘Setup Wizard’ option to begin amending your choices.

The choices you make within the wizard have been chosen to get you up and running as quickly as possible. However there is a lot more customization available via our main Options screen also available from the ‘CodeRush’ menu or via the Ctrl+Shift+Alt+O shortcut.




Everyone is different and we all have our own preferences and approach. It is our hope that the minimal amount of configuration requested by our Setup Wizard, will greatly improve your CodeRush experience.

CodeRush for Roslyn is now available for as little as $50 a seat and a 30 day trial can be found in the Visual Studio Gallery.

More Posts