Back to Devexpress

Widen Scope (Promote to Field)

coderushforroslyn-117649-refactoring-assistance-widen-scope-promote-to-field.md

latest1.4 KB
Original Source

Widen Scope (Promote to Field)

  • Mar 29, 2021

Purpose

Converts a variable declared within a method to a private field.

Availability

Available in a variable declaration within a method.

Usage

  1. Place the caret in a variable declaration.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Widen Scope (promote to field) from the menu.

After execution, this refactoring moves the variable declaration out of the current methods and converts it to a field.

csharp
class TestClass {
    string completeUrl;
    private void SetUrl(string url) {
        completeUrl = string.Format("http://{0}", url);
    }
}
vb
Public Class TestClass
  Dim _completeUrl As String
  Private Sub SetUrl(url As String)
    _completeUrl = String.Format("http://{0}", url)
  End Sub
End Class

Note

The default visibility modifier of the generated member is configured on the Editor | <Language> | Scope Options options page. Refer to the Scope topic for details.

See Also

Widen Scope

Promote to Parameter