Home > Refactorings > Refactorings – Introduce Alias

Refactorings – Introduce Alias

April 18th, 2011

The Introduce Alias refactoring creates an identifier that serves as an alias for a namespace or type within the active source file. The alias directive can provide much neater and organized code. When several namespaces contain a matching class name, alias can also help to avoid a name conflict (ambiguous reference) without using the fully qualified type names, which improves overall code readability.

The refactoring allows you to choose whether to create a namespace or type alias via a sub menu. There are two variations of this refactoring – a simple Introduce Alias which creates an alias for the current type or namespace reference, and the Introduce Alias (replace all), which replaces all occurrences of the type or namespace reference in the entire source file.

Once refactoring is performed, you can rename the newly created alias, because names of the alias references are linked together. When you are done with renaming, simply press the Enter key to commit your change:


Introduce Alias refactoring result (CS)

Visual Basic:

Introduce Alias refactoring result (VB)

The opposite refactorings are Inline Alias and Replace with Alias.

Products: Refactor! Pro
Versions: 10.2 and up
VS IDEs: any
Updated: Apr/18/2011
ID: R025

Similar Posts: