Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper refactoring to remove magic strings

Is there such a thing? Either as a part of the product or a plugin? I can't see to find it.

I want to go from:

public DataTable Fetch() {
    return ExecuteDataTable(_ConnectionString, "pr_DetectAffectedOrderLines");
}

to:

private const string SP_DETECT_AFFECTED_ORDER_LINES="pr_DetectAffectedOrderLines";

public DataTable Fetch() {
    return ExecuteDataTable(_ConnectionString, SP_DETECT_AFFECTED_ORDER_LINES);
}
like image 859
AngryHacker Avatar asked Mar 09 '11 22:03

AngryHacker


2 Answers

ReSharper | Refactor This (Ctrl-Shift-R) | Introduce field, then select to introduce constant.

like image 136
Ilya Ryzhenkov Avatar answered Sep 24 '22 10:09

Ilya Ryzhenkov


There is a direct shortcut to refactor: Ctrl+R, Ctrl+F.

There are 3 of them:

menu screenshot

Demo with the "Introduce Variable" as example:

demon as gif

like image 38
aloisdg Avatar answered Sep 22 '22 10:09

aloisdg