内联方法

此重构适用于:

  • C#

  • Visual Basic

功能: 内联方法重构。

使用时机: 要将单个语句中对静态、实例和扩展方法的使用替换为删除原始方法声明的选项。

操作原因:此重构会提供更清晰的语法。

操作说明

  1. 将脱字号放在方法使用上。

  2. 按 (Ctrl+.) 触发“快速操作和重构”菜单。

  3. 选择以下选项之一:

    选择“内联 <QualifiedMethodName>”,删除内联方法声明:

    Screenshot of the Quick Actions and Refactorings menu in Visual Studio with Convert 'Inline 'CreateWidget()' selected and C# code changes shown.

    选择“内联并保留 <QualifiedMethodName>”,保留原始方法声明:

    Screenshot of the Quick Actions and Refactorings menu in Visual Studio with Convert 'Inline and keep 'CreateWidget()' selected and C# code changes shown.

另请参阅