views:

323

answers:

6

I know VS code folding issues are an old chestnut, but I haven't been able to find this in all the other discussions I have browsed through:

We have a team of C# guys, some love regions and others hate them and we don't seem to have much middle ground to work with.

Is there a plug- or add-in for VS that will just 'hide' the regions? So that those that want them will see them as normal, but the people that install the add-in and view a .cs file the regions just aren't there, as if they don't exist.

I can see this might be an issue when moving code around that it might cause issues of certain methods being in or outside of the wrong region, but that might be a tradeoff the team is happy with...

+1  A: 

I don't know of any plugin like that, honestly. However, with VSTO, it's very easy to write one yourself.

Mike Caron
+2  A: 

Personally, I write a VS macro (Tools > Macro) to expand all regions on file open.

(Heh, second VS macro question in two minutes).

-Oisin

x0n
Could you please post your macro here? Have no idea how to write them but regions drive me crazy already.
User
A: 

I used to like and use regions, but now I've seen the light!

If you find yourself wanting to hide code, then surely it belongs in another class, or needs reorganising in some way?

Mitch Wheat
Quite often, yes, but this doesn't answer the OP's question, which is that given people who DO use regions, how do you view their code in Visual Studio as if regions didn't exist, without having to always go and expand all regions every time you open a file. Is there a plug-in that will do this for them.
Jeff Yates
@Jeff Yates : Yes, I understand that jeff. I am making the point that they really serve no useful purpose.
Mitch Wheat
Yes, I know. But as it doesn't answer the question posted, you might want to consider putting it as a comment on the question rather than an answer. I totally agree with your sentiment but you're expressing it in the incorrect place. That's all. If you add an actual answer to the question into your post, it would be okay, of course.
Jeff Yates
A: 

This is somewhat... sleazy, and may have side-effects but:

Tools-->Options-->Environment-->Fonts and Colors-->Preprocessor Keyword Change the foreground and background colours to white (or whatever your default background is).

You wont see other preprocessor keywords though.

BrianH
This doesn't help if the region is collapsed - in fact, it could make it worse.
Jeff Yates
+2  A: 

There are shortcut keys to deal with them:

Ctrl+M, Ctrl+M  Collapse or expand the block you're currently in.
Ctrl+M, Ctrl+O  Collapse all blocks in the file
Ctrl+M, Ctrl+L  Expand all blocks in the file
Ctrl+M, Ctrl+P  Stop outlining mode. (Ctrl+M, Ctrl+O resumes) 

See http://www.codinghorror.com/blog/archives/001147.html

Justin Ethier
A: 

I just wanted to write the same question!

We have regions everywhere in the code and I absolutely hate them.

You know why? You are somewhere in the code, you click F12 (go to definition), VS opens the file, points the cursor to the right place and the next second collapses the file. Terrific. So I have to click "Stop outlining", return to the original file, point to the object and make it "Go to definition" again. Why do I have to do it twice?

It's unbelievably annoying to always have to de-outline every single file every time you open it.

Who needs these regions actually? You have to be able to find what you need in file without regions, just use your dropdown lists with types and members.

if it's difficult to navigate, maybe you have too much in one file? What about restructuring stuff and splitting in in maybe ten files? Or is it a company style to develop the software in one single file? LOL

Just say No! to C# Regions

User