Encapsulate Fields Dialog Box
See Also
Use this dialog box to specify options for the Encapsulate Fields refactoring command.
You can use the Encapsulate Fields command to create accessor methods for fields
in a class. With the Encapsulate Fields command, you can also have direct references
to those fields replaced with calls to the newly created accessor methods.
Accessor methods are also referred to as getters and setters or read/write
methods.
You can open the Encapsulate Fields
dialog box from the Source Editor, Projects window, or Files window. In one
of these windows, right-click a field (or a reference to the field elsewhere in
your code) and choose Refactor > Encapsulate Fields.
The dialog box has the following fields:
- List of Fields to Encapsulate. Contains a list of fields
in the class. Select the checkbox for each field that you want to
encapsulate.
- Fields' Visibility. Drop-down list containing the four
possible accessibility modifiers (public, protected,
<default>, and private). Select the accessibility
modifier that you want the field or fields to have.
- Accessor's Visibility. Drop-down list containing the four
possible accessibility modifiers (public, protected,
<default>, and private). Select the accessibility
modifier that you want the accessor (getter and setter) methods to have.
- Use Accessors Even When Field Is Accessible. If selected, any
direct references in your code to the field are updated to use the accessor methods instead.
If not selected, any direct references to the fields that you already have in
your code are not replaced.
This option only has an impact if both of the following are true:
- You have direct references to the field in your
code.
- You have set the field's accessor modifier so that the field is visible
to the classes with these references.
- Preview All Changes. If selected, a list of all
parts of your code to be affected by the refactoring is displayed in the
Refactoring window after you click Next. You can then clear any occurrences of
the name that you do not want changed.
If Preview All Changes is not selected, the refactoring is done immediately after you
click Next.
Unless you clear the Preview All Changes checkbox, you need to follow these steps
to complete the refactoring:
- Click Next.
The Refactoring
window opens and displays a tree view of the code to be affected by the refactoring.
- Check the items displayed in the Refactoring window to make sure that you want them
all changed. Clear the checkbox next to any parts of the code that
you do not want changed.
- Click Do Refactoring.
- You should always perform a clean build after completing
any refactoring commands. You can do a clean build by right-clicking the project's
node in the Projects window and choosing Clean and Build Project.
- See Also
- About Refactoring
- Refactoring: Quick Reference
- Undoing Refactoring Changes
Legal Notices