Tuesday, April 5, 2011

Remove the automatic #region/#endregion tags when implementing an interface in Visual Studio 2005/2008

When user the "Implement Inteface X" context menu feature, the inserted code gets surrounded by a

#region [interfacename] Members
#endregion

pair. I always end up deleting this, is there a way I can permanently turn it off? I had a quick search through the snippets directory, but wasn't sure if this was the right place. There's pp_region.snippet that I guess I could modify, but I got the feeling that would turn off the #region/#endregion completely. I thought I'd ask here before I go doing things that will have me re-installing VS...

From stackoverflow
  • You can turn it off via Tools / Options

    Then, in the option-window, you select 'Text Editor', then the language of your choice (C# for ex). Then, you select 'Advanced', and then, you have a checkbox which says: 'Surround generated code with #region'

    Brian Rasmussen : Good one, thanks!
    Dmitri Nesteruk : Thank you, thank you, thank you! Can't tell you how annoying this is!
    Andrei Rinea : Excellent answer!
    DrJokepu : +1 this thing has been annoying me for ages!
  • Also, if you're using Resharper you can fully configure the layout of your classes so they'll look exactly the way you want. One of the options is to completely remove the region tags whenever it finds any. It's awesome to open any c# project and have it reformatted just by doing [CTRL+E, C]

    endian : Sorry, but I cannot bear Resharper. One day I'll be able to install it and it won't: remap all my keybindings and refuse to set them back; screw up all the Intellisense and refuse to change it back; make my machine run like a dog and refuse to uninstall. I'm not a fan :-)

0 comments:

Post a Comment