Refactoring: Encapsulate field.

Hi All,

Just started to look at VS2005 beta 2 - I don't seem to be able to use the encapsulate field refactoring function. 

I select a private class level variable and click encapsulate field. 

The IDE then prompts for the property name and displays a code preview window which has the original field renamed to that of the property (highlighted) and no get/set type code. 

Am I doing something wrong here

Cheers,

JW.


Answer this question

Refactoring: Encapsulate field.

  • Steve1031

    Unfortunately I get a rather crude message box that simply states "Field Ecapsulation Failed" or similar.  The code certainly doesn't get generated.
  • Puttoju

    If you are still running into this issue, you can you please report it on

    http://lab.msdn.microsoft.com/productfeedback/default.aspx

    and include an example of the code you are trying to encapsulate Thanks!

    Ben

  • yuvald

    Simple types - I've tried int and string without any success.


  • WernerF

    Thanks Anson.  That was spot on!  Out of curiousity there is also a folder 'Expansions' listed in the tools that is currently missing - what would that be for

    JW.

  • shongalolo

    Hi,

    What is the datatype of this variable you are trying to encapsulate Have you tried for something simple like a string or int

    Regards,
    Vikram

  • Chike_

    I guess not supporting most of the refactoring options in Express is by design, It's one way to add value to Visual Studio.

    In VS2003 I used a plug-in that provided code generation/refactoring support. Where's a good place to start learning about creating my own plug-ins to write code like this


  • Nate Heaton

    I've installed the Visual Web Developer 2005 Express Edition and it doesn't appear that this functionality is enabled. I don't get an option to encapsulate fields at all. The code snippet is in the directory and is registered with the manager. Should this functionality work in this version of the product
  • SpinWebs

    Go ahead and click apply, or if you'd like, uncheck the preview box.  The get/set code will be added even though it doesn't show up in the preview.  At least it does for me...

    dave

  • Pointblank

    OK - perhaps I'll try cleaning up and installing again or use a virtual PC - interestingly every other refactor function works exactly as expected so this is a fairly limited issue.


  • Ramskar

    JW,

    The most likely reason that the Encapsulate Field refactoring is failing is that it is unable to find the Code Snippet that it needs to use in order to generate the actual property.  This wouldn't effect the preview functionality, as you've noticed, because the preview only shows the references that would be updated and not the actual property insertion.  There are 3 .snippet files that the feature relies on, EncapsulateField.snippet, EncapsulateFieldGet.snippet, and EncapsulateFieldSet.snippet.  These are located in the %program files%\Microsoft Visual Studio 8\VC#\Snippets\1033\Refactoring directory.  If those files exist then it's possible that the registration of that directory is incorrect.  If you go to Tools menu there is an option for Code Snippets Manager.  Check to see if that directory is listed in the left hand pane.  If it's not, add it via the add... button at the bottom of that dialog, and then try the feature again.

    Hope that helps!
    Anson Horton
    C# IDE PM

  • lumbus

    RickC2003 --

    Encapsulate field refactoring is not supported in VWD Express. In fact, C# express only supports two refactorings -- rename and extract method. The snippets are dropped in the location, but it isn't used.

    HTH,

    Karen



  • DoerakNL

    Hi,

    Looks like one of those Beta installation issues to me and the only option I can think of is re-install...

    Regards,
    Vikram



  • Refactoring: Encapsulate field.