CodeRush Xpress

Refactoring - Changing Signatures

 

Add Parameter

Adds a new parameter to a method declaration and updates all calls accordingly.

Add Parameter Refactoring

Create Overload

Creates an overloaded method similar to the one at the caret, with fewer parameters. Applying this refactoring leads to an interactive phase where you can select which parameters to exclude from the new overload. XML doc comments are updated appropriately. You can even create overloads of constructors, as shown in the screen shot below:

Create Overload Refactoring

Decompose Parameter

Replaces a single parameter with one or more new parameters, each standing in for a property access on the original parameter. For example, consider the code below:

In the first constructor, only a single property of the parentGrid parameter, Children, is accessed inside the code (and aside from this property reference, parentGrid is never referenced or assigned to directly in the code). So we can replace this parameter with a parameter of the same type as the property. The preview hint for Decompose Parameter shows the impact of this change:

After applying this refactoring, all calls to the method are updated. The final code looks like this:

Promote to Parameter

Removes all references to the local declaration or field from the method, replacing it with a parameter. Calling code is adjusted to pass in the promoted field or expression.

In C#, CodeRush Xpress simply adds a preview hint wrapper around the existing refactoring.

Refactoring - Promote to Parameter in C#

In Visual Basic the refactoring is available as well, however in this case CodeRush Xpress actually implements the refactoring instead of handing off to the language service:

Refactoring - Promote to Parameter in C#

Remove Unused Parameter

Removes an unused parameter from a method declaration and updates all calls accordingly.

In Visual Basic this refactoring is only available on parameters that are not referenced within the method:

Refactoring - Remove Unused Parameter in VB

In C# the Remove Unused Parameter refactoring is not available, however there is a wrapper for the built-in C# refactoring Remove Parameters, and that wrapper is available when the caret is on any parameter:

Refactoring - Remove Unused Parameter in C#

When you select the Remove Parameters, CodeRush Xpress calls the built-in C# refactoring, which allows you to select the parameters to remove:

Refactoring - Remove Unused Parameter - Visual Studio UI

Note: The image above is a dialog from Visual Studio and is not part of CodeRush Xpress.

Reorder Parameters

Reorders parameters in the current method, and then updates calling code to reflect the new order.

In C#, this refactoring hands control over to the existing C# implementation of Reorder Parameters:

Refactoring - Reorder Parameters in C#

Note: The image above is a dialog from Visual Studio and is not part of CodeRush Xpress.

In Visual Basic, the application of this refactoring leads to an interactive phase where parameters can be rearranged using the CodeRush Xpress in-source UI. A hint appears revealing available shortcuts in the interactive mode.

Refactoring - Reorder Parameters in VB

Safe Rename

Safely renames non-private methods and properties by creating a duplicate member to preserve the old signature, calling the renamed member from the old member. The old member is hidden from Intellisense and marked "Obsolete". References to the old member will generate compiler warnings directing developers to the new renamed member.

Refactoring - Safe Rename

After applying this refactoring, CodeRush Xpress selects and links the method name for an easy rename.

Refactoring - Safe Rename - Result

Safe rename is useful if you want to change the signature of a public or protected method referenced by code outside of your solution (e.g., on a developer's machine in another part of the world making calls to your API). For example, after performing the Safe Rename on the code shown above, we can next apply Remove Parameter to the unused deprecatedData in the FindPlayers method, cleaning up its signature without breaking any code that calls the now-obsolete FindAllThePlayers method.

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.