4

Anyone know a good way to find out where i have an extra #region or #endregion in my code? I have about 5000 lines of c# code and i'm trying to do it manually right now. Any help is appreciated.

toosweetnitemare
  • 2,226
  • 8
  • 33
  • 44
  • @toosweetnightmare Tejs is correct; the fact that you have a mismatched region is a sign of a larger problem. After you find your issue, I recommend doing what you can to keep each class as small as possible. – George Stocker Jun 02 '11 at 20:31
  • 2
    Partial classes are great for this, or separate classes ;-) – CodeNaked Jun 02 '11 at 20:33
  • 1
    I have it broken into classes and i like to break the code in the classes up into little regions with titles to manage it. It might not be best practice but i'm not a software engineer and it works for me. – toosweetnitemare Jun 02 '11 at 20:35
  • 1
    It sounds kind of like it's not working actually. I think the idea is that your class is too big. – recursive Jun 02 '11 at 20:39
  • I think ill just take Tejs advice and remove all of my #region and #endregion – toosweetnitemare Jun 02 '11 at 20:44

4 Answers4

8

Do CTRL+M CTRL+L - to close up all the regions. Then expand them one at a time on the left (little + sign) until you see #region XXX that doesnt have matching #endregion

Should look like this:

Mismatch

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
1

Just had this issue myself,

easiest way for me to find out where I had deleted an endregion was to do a compare with the last file in source control.

the line was then highlighted and easy to find.

WraithNath
  • 17,658
  • 10
  • 55
  • 82
  • an excellent suggestion. I unfortunately did not have a previous copy to use for source control but i can see how this would have been a very useful. Thank you for adding to my question! – toosweetnitemare Sep 27 '12 at 15:16
1

Click Ctrl+M, M it will collapse all properly matching regions. The one that doesn't match will not be collapsed so you can fix it.

Teoman Soygul
  • 25,584
  • 6
  • 69
  • 80
1

What happens when you use the shortcuts to collapse all?

CTRL+M CTRL+O - Collapse all regions not recursively

It should collapse all but the region that has the mismatch.

George Stocker
  • 57,289
  • 29
  • 176
  • 237