An Idea can change your life.....

Monday, March 23, 2009

CodeRush Xpress for C#


Here's a sampling of what you get:

Find any File or Symbol...

Go to any file or symbol in the solution efficiently.


Type in a few letters of the name to filter...


Or hold down the SHIFT key to filter only on uppercase letters...


Uppercase characters can appear anywhere. Any uppercase characters not specified in the filter are highlighted in blue...


The uppercase letters need not be sequential. Notice how "RD" in the screen shot below matches both "ResolveDelegate.cs" and "ResolveCallbackDelegate.cs".

Tab to Next Reference

This is a really cool navigation feature that takes you to the next (and previous) reference just by pressing the TAB key (or SHIFT+TAB to go backwards) when the caret is inside an identifier, member, or a type. For example, in the following code, the caret was inside the last Person type reference (in the "newPerson()" instantiation call) when the TAB key was pressed, causing the Person reference at the top of the file to become highlighted.

Expand/Shrink Selection

This feature allows you to increase a selection by logical blocks, or decrease an expanded selection by the same logical blocks. This feature is perfect when refactoring, since many refactorings work on a contiguous selection of code (e.g., extract method, introduce local, etc.).

TDD-Style Intelligent Declaration Based on Usage

Place the caret on any undeclared element in your code and press the Refactor/Code key (CTRL+`) to see a list of intelligent suggestions for the type of the new variable. For example, in the screen shot below two appropriate types are suggested, even though Console.WriteLine has many overloads that accept a wide variety of types.


You can even turn a function call or property access into a variable declaration.


This makes writing code with Visual Studio's Intellisense really fast. Just use Intellisense to produce the property reference or function call, and then press the Refactor/Code key to declare a new local variable of the appropriate type. Here's an example with a function call—notice the caret can be just about anywhere on the function call, even at the end of the line.


You can even declare a local from a simple instantiation, like this:


And it's worth noting you can declare all kinds of elements based on usage, not just locals. Anything you need types, members, fields—the full list of elements that can be declared appears below.

Professional Grade Refactorings

CodeRush Xpress includes many powerful refactorings to help improve the quality of your code. For example, consider the following:

private static void ShowInt(int n)
{
Console.WriteLine(n);
}
private static void ShowEntries(List<int> entries)
{
entries.ForEach((
Action<int>)ShowInt);
}

With the caret on the ShowInt method reference, you can press the Refactor! key...

and then select Inline Delegate. This will produce the following code:

private static void ShowEntries(List<int> entries)
{
entries.ForEach(
delegate(int n)
{
Console.WriteLine(n);
});
}

Notice the caret is on the delegate keyword. You can immediately press the Refactor! key again...


Note that we can go in two directions now. We can either convert the anonymous method to a named method (in essence reversing the Inline Delegate refactoring we just performed), or we can take it a step further and compress the anonymous method into a lambda expression. Choosing Compress to Lambda Expression, we get the following:

private static void ShowEntries(List<int> entries)
{
entries.ForEach(n =>
Console.WriteLine(n));
}

CodeRush Xpress is loaded with powerful refactorings taken from Refactor! Pro. One of our favorites, Extract Method to Type, allows you to extract a method from one type into another, updating both the calling code and the extracted method appropriately. For an example, consider the following code:

class Person
{
public string Name { get; set; }
public bool IsAnOrphan { get; set; }
public Person Mother { get; set; }
public Person Father { get; set; }
}
// ...
class BabyMaker
{
public Person MakeOne(Person mother, Person father, string name)
{
Person newBaby = new Person();
newBaby.Name = name;
newBaby.Mother = mother;
newBaby.Father = father;
newBaby.IsAnOrphan = newBaby.Mother == null && newBaby.Father == null;
return newBaby;
}
}

Notice that the code in the MakeOne method contains a local variable that's an instance of type Person, and that code sets the IsAnOrphan property. There is some logic in this method that pertains to Person, but it feels like it's in the wrong class!

We already have the class Person in our solution, so it makes sense to move some of this code to the proper class. With CoderRush Xpress installed, all we need to do is select the code we want to move....


Press the Refactor key...


And choose "Extract Method to Person". CodeRush Xpress analyzes the selection and determines there's at least one local variable of a type you have declared elsewhere in the solution. Now let's apply this refactoring...


Press the UP and/or DOWN ARROW keys to select a location for this new method, and press ENTER to commit. Give the method a meaningful name...

Cool. Now we have the logic (that should have been inside Person to start with) right where it belongs. Notice how the new SetParents instance method works on the instance itself (compare that code with the original code that operated on the newBaby local). The code is easier to read and cleaner in both locations.

Notice also that tiny dark blue triangle, in the code above. That's a stack-based marker, and CodeRush Xpress drops markers automatically whenever you apply a refactoring or TDD-style declaration that takes you away from the original location. You can jump back at any time to the top marker on the stack by pressing ESCAPE.

There are many more refactorings and cool features in CodeRush Xpress. This is just a preview. Here's the full list of what you get:

Editor Features

  • Duplicate Line
  • Highlight Usages
  • Clipboard Features
    • Smart Cut/Copy
    • Paste Replace
  • Enhanced Selection Abilities
    • Extend/reduce selection
    • Camel-case selection

Navigation Features

  • Camel-case Navigation
  • Tab to Next Reference
  • Go to File
  • Go to Symbol (QuickNav)

TDD - Declaration from Usage

  • Types
    • Declare Class
    • Declare Delegate
    • Declare Enum
    • Declare Enum Element
    • Declare Interface
    • Declare Struct
  • Members
    • Declare Constructor
    • Declare Event Handler
    • Declare Getter
    • Declare Method
    • Declare Property
    • Declare Property (auto-implemented)
    • Declare Property (with backing field)
    • Declare Setter
  • Variables
    • Declare Field
    • Declare Local
    • Declare Local (implicit)

Refactorings

  • Add/Remove Block Delimiters
  • Combine Conditionals (merge nested "If" statements)
  • Compress to Lambda Expression
  • Compress to Ternary Expression
  • Convert to Auto-implemented Property
  • Convert to Initializer (use object/collection initialize when possible)
  • Create Backing Store (converts Auto-implemented Property to standard Property with get and set)
  • Decompose Initializer
  • Decompose Parameter
  • Expand Lambda Expression
  • Expand Ternary Expression
  • Extract Method to Type
  • Flatten Conditional
  • Introduce Local (introduce variable)
  • Inline Delegate
  • Inline Temp (inline variable)
  • Make Explicit
  • Make Implicit
  • Move Type to File
  • Name Anonymous Method
  • Name Anonymous Type
  • Reverse Conditional (invert "if")
  • Split Conditional (split complex "If" statements)
  • Use StringBuilder
  • Use String.Format

No comments: