Inline Method refactoring
ReSharper | Refactor | Inline | Inline…
Ctrl0R,0I (ReSharper_InlineVariable
)
This refactoring helps you replace usages of a static, instance, and extension method with its body, and optionally remove the original method declaration.
You can also apply this refactoring to a property with a backing field. In this case, read usages are replaced with the getter body and write usages are replaced with the setter body.
In the example below, we use this refactoring to inline the LogError
method:
Before refactoring
abstract class Shape{ public void Draw() { try { /*draw*/ } catch (Exception e) { LogError(e); } } private static void LogError(Exception e) { File.WriteAllText(@"c:\Errors\Exception.txt", e.ToString()); }}
After refactoring
abstract class Shape{ public void Draw() { try { /*draw*/ } catch (Exception e) { File.WriteAllText(@"c:\Errors\Exception.txt", e.ToString()); } }}
tip
The reverse functionality is available with the Extract Method refactoring refactoring.
Place the caret at the declaration or a usage of a method in the editor, or select it in the File Structure window window.
Do one of the following:
Press Ctrl0R,0I and then choose Inline Method
Press CtrlShift0R and then choose Inline Method.
Right-click and choose Refactor | Inline Method from the context menu.
Choose ReSharper | Refactor | Inline | Inline… from the main menu.
The Inline Method dialog will open.
If you have invoked the refactoring at a method usage, you can clear the Inline all usages checkbox to inline only the current usage.
Optionally, clear the Remove inlined method declaration checkbox to preserve the original method declaration.
To apply the refactoring, click Next.
If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
This feature is supported in the following languages and technologies:
The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the Languages and frameworks section.