Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp_Prog_Guide.doc
Скачиваний:
16
Добавлен:
16.11.2019
Размер:
6.22 Mб
Скачать

Операции переименования

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

Символ кода

Операция переименования

Поле

Изменяет объявление и случаи использования имени поля на новое имя.

Локальная переменная

Изменяет объявление и случаи использования имени переменной на новое имя.

Метод

Изменяет имя метода и все ссылки на этот метод на новое имя.

Примечание.

При переименовании метода расширения операция переименования распространяется на все экземпляры этого метода, находящиеся в области действия, независимо от того, используется этот метод расширения как статический метод или метод экземпляра.

Пространство имен

Изменяет имя пространства имен на новое в его объявлении, во всех операторах using и во всех полных именах.

Примечание.

При переименовании пространства имен Visual Studio также обновляет свойство Пространство имен по умолчанию на странице Приложение Конструктора проектов. Это свойство невозможно сбросить, выбрав команду Отменить в меню Правка. Для сброса значения свойства Пространство имен по умолчанию необходимо изменить это свойство в Конструкторе проектов.

Свойство

Изменяет объявление и случаи использования свойства на новое имя.

Тип

Изменяет все объявления и все случаи использования типа на новое имя, включая конструкторы и деструкторы. Для разделяемых типов операция переименования распространяется на все части.

How to: Rename Identifiers

The following procedure describes how to rename an identifier in your code. Use this procedure to perform the Rename refactoring operation.

To rename an identifier

  1. Create a console application as described in the following Example section.

For more information, see Console Application.

  1. Place the cursor on MethodB, either in the method declaration or the method call.

  2. From the Refactor menu, select Rename. The Rename Dialog Box appears.

You can also type the keyboard shortcut F2 to display the Rename Dialog Box.

You can also right-click the cursor, point to Refactor on the context menu, and then click Rename to display the Rename Dialog Box.

  1. In the New Name field, type MethodC.

  2. Select the Search in Comments check box.

  3. Click OK.

  4. In the Preview Changes dialog box, click Apply.

Promote Local Variable to Parameter

Promote Local Variable to Parameter is a Visual C# refactoring operation that provides an easy way to move a variable from a local usage to a method, indexer, or constructor parameter while updating the call sites correctly.

Perform the Promote Local Variable to Parameter operation by first positioning the cursor on the variable you wish to promote. The statement declaring the variable must also assign a value or expression to the variable. When the cursor is in position, invoke the Promote Local Variable to Parameter operation by typing the keyboard shortcut, or by selecting the command from the shortcut menu.

When you invoke the Promote Local Variable to Parameter operation, the variable is added to the end of the parameter list for the member. Any calls to the modified member are immediately updated with the new parameter as the expression originally assigned to the variable, leaving the code so that it functions the same as before the variable promotion.