Hi. I have an object with more the 100 fields.
I wonder if there is a method to automate the process of encapsulating those fields.
I'm just too lazy to do "Right-Click -> Refactor -> Encapsulate Field" for 100 times ![]()
if i select all the fields and do "Encapsulate" then only last selected field is encapsulated.
Any suggestions on this
Thanks.

Refactor Encapsulate field repeatedly
anjanesh
Hi,
This is not supported in the shipped code of Class Designer. However, you can easily add this feature by creating a command yourself through an add-in. You can install the CD Power Toys add-in, create a command and insert the following code in your command handler.
foreach (ClrField field in Selection.Filter<ClrField>()){
field.Language.RefactorEncapsulateField(field);
}
Hope this helps.
Ramesh Rajagopal.
oer
If you installed the powertoys, you should have a "Class Designer Command" project in your New Project dialog - create that project, code your command, build and deploy it as you would with a regular Visual Studio add-in.
There's a short help doc coming with the PowerToys which contains some more info.
Hope this helps
/Dmitriy
Priya Lakshminarayanan
This so didn't work.
After getting the Power Toys add-in installed properly and building a simple project with the above code, I found that it doesn't work.
I dropped a test class onto the diagram and added 3 fields to it. Then I selected the 3 fields and invoked the add-in. It did pop up the Encapsulate Field and Preview Reference Changes dialogs, but after it ran on the 3 fields, nothing changed.
Is there something else to this
ngrebowiec
VuDZ
oh. thanks for your reply.
i've downloaded and installed those power toys and now i can see that Class Designer Enhancements in the Add-in Manager, but how do I create a command
Eran Alshech
well i don't have a "Class designer command" in there. but i have a "Class designer add-in" instead. and when i create a new project and build it a get an error message
"Error 1 The type or namespace name 'ModelingAddIns' could not be found (are you missing a using directive or an assembly reference ) E:\Documents and Settings\xxxxxx\My Documents\Visual Studio 2005\Projects\MyEncapsulateField\MyEncapsulateField\Connect.cs 6 7 MyEncapsulateField
"
any suggestions