Thursday, July 30, 2009

CodeRush vs CodeRush Xpress?

So what’s the difference?

Well CodeRush Xpress is what it sounds like. It’s a lite version of CodeRush which is FREE to all users of VS2008.

I’ll say that again …IT’s FREE……

It is not a trial.

It does not time out.
It does not have nag screens.

Here is a woefully inadequate Summary:

CodeRush Xpress:

  • > 50 Refactorings
  • Camel Case Navigation
  • Smart Cut/Copy
  • Tab To Next Reference ***
  • Highlight All References***
  • Quick Navigation ***
  • …Lots more I’m sure I haven’t remembered


  • Everything from CodeRush Xpress (Above)
  • 57 Code Providers*
  • 168 Refactorings*
  • 122 Code Issues* (Code Analysis)
  • 25 Categories** of Templates (Insanely useful)
  • Intelligent Paste
  • Clipboard History
  • Selection Embedding
  • Selection Inversion
  • Code Metrics
  • Flow Break Evaluation / Region Painting.
  • References Window
  • “Jump to” menu (Navigation)
  • …and again many more I can’t even remember at the current time.

* Figures based on the pre-release copy of CodeRush 9.2 in front of me :)
** I’ve counted Top level Categories only, because to count the templates themselves, would take forever. There are way to many, and several of them take params based on a really cunning, and easy to learn system of Mnemonics. The number of potential outputs from these templates is quite frankly scary-cool.
*** Update: In version 10.1 of CodeRush Xpress MS has asked DevExpress to remove certain features whilst running under VS2010 for more details see my more recent post –> CodeRush 10.1 hits RTM

A few links for anyone looking to find out more about CodeRush or CodeRush Xpress

CodeRush Xpress:

Introduction and Download: Official Homepage of CodeRush Xpress
Walkthrough of many Xpress features: CodeRush Xpress for C# and Visual Basic inside Visual Studio 2008 - by Mark Miller
CodeRush Xpress Videos: Training Videos

Note: Something about the deal with MS involved the removal of the DevExpress Menu from the Xpress Edition.
The options, however can be reached through the use of CTRL+ALT+SHIFT+O.

You may also consider following the steps in this blog post by Nick Berardi, which instruct how to reintroduce the DevExpress menu. (Please note that the steps are intended for version 9.2.x of CodeRush Xpress)


CodeRush is a superset of CodeRush Xpress. Which means that CodeRush includes everything already mentioned plus a whole lot more

CodeRush Homepage: Introduction and links
CodeRush Trial: Trial Download and Cheatsheets
General Feature Overview: Categorised List of Features
Feature Comparison CR vs CRx :  Moving up from CodeRush Xpress to CodeRush – A little old but still valid.
CodeRush Videos: CodeRush Training
RefactorPro Videos: RefactorPro Training


There are also some 3rd party plugins available:
[Most work with CRx, but occasionally some might require CodeRush(Full)]

Community written Plugins: Community Site Home Page
Help with writing your own plugins: Plugin Resources

Hopefully that should be enough to get you going…

I will try to keep this post up to date as things change, but it’s hard… both CodeRush and CRx continue to get better all the time.

[P.S If you have any (CodeRush related) questions you’d like me to try to answer, you can find me on twitter @]

Thursday, July 09, 2009

HowTo: Write a header plugin for Coderush

I was asked recently if I knew of any plugins for Coderush which would allow one to hit a key and inject a header into the current file.

The idea was that the header would be injected in a location within the existing file but not necessarily where the caret was currently residing.

My initial idea of “use a template” scuppered by this idea, as templates typically expand where your caret is.

But perhaps not.

I quickly rerouted my thinking an  came up with the following idea.

What about a new Action (what is an action?) which would take a parameter of which template to expand. It could drop a marker at the current location… Jump to the top of the current file, Expand the template there, and then collect it’s marker… Perfect right ? :D

So how does one do that then…

See my previous Tutorials for how to create a simple action plugin.

The Action Properties

In this case we will simply set the properties differently….

…add some Parameters (via the Parameters property)….

… flesh out a few of their details…

…and write some different code in the execute routine of the Action.

As usual, the code is really what it’s all about:

The Code

What we need to do here is to drop a marker, Go inject the template text and then collect the marker.

The Main event looks like this:

Private Sub actExpandHeader_Execute(ByVal ea As DevExpress.CodeRush.Core.ExecuteEventArgs) Handles actExpandHeader.Execute
' Get Params Dim HeaderType As String = ea.Action.Parameters.Item("HeaderType").ValueAsStr
    Dim FullTemplateNameAndPath As String = ea.Action.Parameters.Item("Template").ValueAsStr
    ' Drop Marker
    ' Determine Insert Point
    Dim InsertPoint = GetJumpLocation(HeaderType)
    ' Expand Template
    Call ExpandTemplateAtSourcepoint(FullTemplateNameAndPath, InsertPoint)
    ' Collect Marker
End Sub

Then we’ll need to determine the location at which to insert our header. This is based on a passed parameter.

Private Function GetJumpLocation(ByVal HeaderType As String) As SourcePoint 
    Dim ElementRange As SourceRange
    Select Case HeaderType.ToLower 
        Case "file" ElementRange = CodeRush.Documents.ActiveTextDocument.Range 
        Case "type" ElementRange = CodeRush.Source.ActiveClassInterfaceStructOrModule.Range 
        Case "member", "method" ElementRange = CodeRush.Source.ActiveMember.Range 
        Case Else ElementRange = CodeRush.Documents.ActiveTextDocument.Range 
    End Select Return ElementRange.Start
End Function

…and finally we’ll need to actually inject the Header from the nominated Template…

Private Sub ExpandTemplateAtSourcepoint(ByVal FullTemplateNameAndPath As String, ByVal InsertPoint As SourcePoint)
    Dim TemplateName = FullTemplateNameAndPath.Split("\"c).Last
    Dim TemplateCategory = FullTemplateNameAndPath.Substring(0, FullTemplateNameAndPath.Length - TemplateName.Length - 1)

    Dim Template = CodeRush.Templates.FindTemplate(TemplateName, TemplateCategory, _

    Dim FinalText = CodeRush.Strings.Expand(Template.FirstItemInContext.Expansion)

    ' Again this isn't the best as we loose links etc... But it was a prety quick turnaround right ? :P
    CodeRush.Documents.ActiveTextDocument.InsertText(InsertPoint, FinalText)
End Sub


This last part expands the template into an in memory string which is then injected into the ActiveTextDocument at the previously calculated location. ...and we’re done.