1

I got more than 13000 lines of codes which are divided in more than 30 regions in my C# application.

Is there a way to sort the regions by their names so that I could easily find the codes I want?

Update

In my defense: It's my winform class which contains many controls and many user controls, which each one does something big which are depended to other controls. and there are many other codes in other classes which I managed to make some classes for them.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
  • 1
    13000 lines in 30 regions in one class? One file? – shree.pat18 Nov 23 '15 at 05:41
  • @shree.pat18 Yes. It's a really big project – Ghasem Nov 23 '15 at 05:42
  • 10
    @AlexJolig It is not a "really big project". It is a "really bad architecture". – Yeldar Kurmangaliyev Nov 23 '15 at 05:43
  • I would strongly recommend trying to refactor and split up the giant class into multiple classes with limited functions. That should help you not only to manage this complexity, but make any changes easier! – shree.pat18 Nov 23 '15 at 05:43
  • That is a very big smell in code. Start by turning regions into methods, then group methods and fields into classes and finally split the classes across files – Emond Nov 23 '15 at 05:44
  • @YeldarKurmangaliyev So is there any way to sort regions in a bad architecture project? – Ghasem Nov 23 '15 at 05:44
  • If your *one* class has 13000 lines :o then you must have a look at better designing approach or at least split it into multiple *cs* files using `partial` class. – Nikhil Vartak Nov 23 '15 at 05:45
  • @AlexJolig It is highly dependend on your code, its usage etc. Paste your code somewhere and we will try to do something. – Yeldar Kurmangaliyev Nov 23 '15 at 05:46
  • `Region` was intended to seperate user and auto generated code, use `search` instead of maintain the sorting of those legacy regions. http://stackoverflow.com/questions/2430198/stylecop-sa1124-donotuseregions-is-reasonable – Eric Nov 23 '15 at 05:49
  • @AlexJolig: There is a way to do it. First understand all the processes/ activities that 13,000 lines do. Divide them in to meaningful entities. For an example 13,000 lines can be your "school management system". In that you will have student, teacher, class, course, exam, question, answer etc. Each one of them should be a class in your system. – Kosala W Nov 23 '15 at 05:52
  • Sorting regions by their name - will that actually help you anyway? (Better options are already being discussed in the comments) – Arghya C Nov 23 '15 at 06:00
  • This may be relevant _[Why do we need separate “.swift” files for each class?](http://stackoverflow.com/questions/26942173/why-do-we-need-separate-swift-files-for-each-class/26942671#26942671)_. Though it mentions Swift the concept may apply –  Nov 23 '15 at 06:00
  • Are those `region`s nested? or is there only one level? – nozzleman Nov 23 '15 at 06:52
  • @nozzleman They are at the same level – Ghasem Nov 23 '15 at 06:58
  • Maybe NArrange can do that, otherwise, you could write a little app using a regex to match regions like `/^#region.*#endregion$/s` and sort them your self.... – nozzleman Nov 23 '15 at 08:25

0 Answers0