tags:

views:

740

answers:

3

How can I set Resharper to wrap, say, the generated equality members with regions when selected from the Alt+Insert menu?

Thanks

+2  A: 

Hi, it doesn't really answer your question, but I just can't resist to try to convince you NOT to use regions. Why would you want to do it? The obvious disadvantages of regions are:

  • they don't compile, so you can never know if the name of the region really describes what is inside
  • regions are often used to hide rubbish code. The thinking here is: you can't see the rubbish bits, so it is as if they didn't exist. But guess what, they still exist...
  • regions are just textual, they don't have any semantic meaning. That means that the code inside the region can change the state of another region - which doesn't help to figure out what is happening in the class at all
  • if you structure your code correctly, it should be obvious what it is doing anyway

I believe using regions makes sense pretty much only for automatically generated parts, e.g. WinForms designer stuff. In most (all?) other cases it is much better to refactor the code, extract some extra classes or methods, etc. to make it clear.

Grzenio
+1 the time spent 'neatly' arranging your code into region blocks could better be spent neatly arranging your code into proper classes
dss539
Your argument is based on the fact that regions will likely be used incorrectly and that region-less code will be laid out correctly. While I disagree with improper region use I don't think that makes them evil. It is just as egregious as improper code layout. Regions can be immensely helpful in partitioning a file to hide the things that you generally don't need (say like properties pre c# 3.0). Like any tool, used correctly they can be quite helpful. And in the hands of a madman lack of regions will still result horrible, horrible code.
vfilby
+2  A: 

there is usually a "wrap in regions" option towards the bottom of the dialog box, but not for this one. I would submit that to JetBrains as a request. For the time being, you'll have to select the generated methods and use the ctrl->E,U,5 (surroundwith shortcut) to get the expected result.

Bless Yahu
+2  A: 

You can highlight the text you are interested in wrapping and use the Visual Studio key shortcut of CTRL + k, s selecting #region from the menu.

Brawndo