logo search
CSharp_Prog_Guide

Чтобы воспользоваться операцией "извлечение метода"

  1. Создайте консольное приложение.

Дополнительные сведения см. в разделе Создание консольных приложений (Visual C#).

  1. В окнередактора кода выберите фрагмент кода, который нужно извлечь:

    double area = PI * radius * radius.

  2. В меню Оптимизация выберите пункт Извлечение метода.

Откроется диалоговое окно Извлечение метода.

В качестве альтернативы, диалоговое окно Извлечение метода можно открыть нажатием на клавиатуре сочетания клавиш CTRL+R, M.

Кроме того, можно щелкнуть правой кнопкой мыши выделенный код, навести курсор на пункт меню Оптимизация и затем выбрать пункт Извлечение метода, после чего откроется диалоговое окно Извлечение метода.

  1. Укажите имя нового метода, например CircleArea, в поле Имя нового метода.

Предварительный просмотр сигнатуры нового метода отображается в области Предварительный просмотр сигнатуры метода.

  1. Нажмите кнопку ОК.

Пример

Для подготовки этого примера создайте консольное приложение с именем ExtractMethod и затем замените Program следующим кодом.

----------

Rename

Rename is a refactoring feature in the Visual Studio integrated development environment (IDE) that provides an easy way to rename identifiers for code symbols such as fields, local variables, methods, namespaces, properties, and types. Rename can be used to change the names in comments and in strings and to change the declarations and calls of an identifier.

Note:

When using Source Control for Visual Studio, get the latest version of sources before you try to perform rename refactoring.

Rename refactoring is available from the following Visual Studio features:

Feature

Behavior of Refactoring in the IDE

Code Editor

In the Code Editor, rename refactoring is available when you position the cursor on the code symbol declaration. When the cursor is in this position, you can invoke the Rename command by typing the keyboard shortcut (CTRL + R, R), or by selecting the Rename command from a smart tag, shortcut menu, or the Refactor menu. When you select the Rename command, the Rename dialog box appears.

Class View

When you select an identifier in Class View, rename refactoring is available from the shortcut menu and Refactor menu.

Object Browser

When you select an identifier in Object Browser, rename refactoring is only available from the Refactor menu.