Skip to main content

Widen Scope (promote constant)

Moves the local constant declaration out of the member and up to the type, replacing all matching values in the type with a reference to the constant. Activates Linked Identifiers for the constant references and drops a marker onto the initial code line.

#Availability

Available from the context menu or via shortcuts:

  • when the caret is on a constant declared within a class member (for instance, within a method). This constant is moved out of the member, so it’s available from all members within the current type.

#Example

private string TestMethod(string param1)
{
    const string MyString = "My string";
    return MyString + param1;
}
Private Function TestMethod(ByVal param1 As String) As String
    Const MyString As String = "My string"
    Return MyString + param1
End Function

Result:

private const string MyString = "My string";
private string TestMethod(string param1)
{
    return MyString + param1;
}
Private Const MyString As String = "My string"
Private Function TestMethod(ByVal param1 As String) As String
    Return MyString + param1
End Function

#Animation

rsWidenScopePromoteConstant

See Also