Geeks With Blogs
Brian Schroer Don't Call Me Mort!

When a free download of Refactor!™ for ASP.NET 2.2 was announced in May by Developer Express, I bookmarked it for future reference because I wasn't working on an ASP project at the time.

When I took another look, I realized that the download includes 19 C#/VB code refactorings that work in any project, ASP.NET or not. They work in Visual Studio 2003, VS2005, and "Orcas".

Included are Refactor! versions (with much nicer user interfaces) of four of the seven built-in VS2005 C# refactorings:

  • Rename
  • Extract Method
  • Encapsulate Field
  • Reorder Parameters

  • Create Overload:
    Creates an overload to an existing method, with fewer parameters.
  • Extract Property:
    Creates a new property from the selected code block. The selection is replaced with appropriate code to reference the newly-declared property.
  • Flatten Conditional:
    Unindents the If or Else statement for a conditional and applies one of the following refactorings: Replace Nested Conditional with Guard Clause, Remove Redundant Else, or Reverse Conditional followed by Remove Redundant Else.
  • Inline Temp:
    Replaces all references to a local variable with its initial value.
  • Introduce Constant:
    Declares a new constant, initialized to the value of the selected string or number.
  • Introduce Local:
    Creates a new local variable initialized to the selected expression. Replaces the selection with the new variable.
  • Move Declaration Near Reference:
    Moves the declaration statement for a local variable near its first reference.
  • Move Initialization to Declaration:
    Combines a local variable's declaration with its first initialization.
  • Replace Temp with Query:
    Replaces each reference to the active local variable with a call to an extracted method, which returns the initial value assigned to the local.
  • Reverse Conditional:
    Inverts the logic in a conditional statement and swaps the If and Else blocks.
  • 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.
  • Simplify Expression:
    Resolves an expression to its simplest form.
  • Split Initialization from Declaration:
    Breaks an initialized declaration for a local variable into a declaration and a separate initialization statement.
  • Split Temporary Variable:
    Splits a local variable which has too many assignments, declaring a new local at the first new assignment following the first reference.

...and the 10 ASP.NET 2.0 refactorings:

  • Add Validator:
    Adds one or more selected Validators to the active input control.
  • Extract ContentPlaceHolder:
    Moves the selected content from a .master page to a new .aspx file, placing it inside <asp:content> tags, and inserts a new <asp:contentplaceholder> tag at the extraction point inside the master page.
  • Extract ContentPlaceHolder (and create master page):
    Moves the content that is *outside* of the selection (in the active .aspx page) to a new master page, inserting a <asp:contentplaceholder> tag to reference the extracted content, and then wraps the selection in the aspx page with <asp:content> tags and adds a MasterPageFile attribute to link to the new master page.
  • Extract Style (Class):
    Converts an inline style to a named class style.
  • Extract Style (id):
    Converts an inline style to a named id style.
  • Extract to UserControl:
    Creates a UserControl for the selected block including content and dependent code.
  • Move Style Attributes to CSS:
    Moves styling attributes from the active control to a new CSS class and applies the class to the control.
  • Move to Code-behind:
    Moves code located in <script> tags to the code-behind file.
  • Rename Style:
    Renames the active CSS style and updates all references to that style.
  • Surround with Update Panel:
    Surrounds a contiguous block of text in the source view with <asp:UpdatePanel …> and <ContentTemplate> tags.

Here's a link to a post by Mark Miller, mad genius of Developer Express, showing examples of all of the refactorings.

Posted on Wednesday, July 4, 2007 8:51 AM .NET , freetools | Back to top

Comments on this post: Free "Mini-Refactor!" From Developer Express

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Brian Schroer | Powered by: