Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any .NET '#region directive' convention ideas? [closed]

I really appreciate the possibility to define regions in your code, as it improves the readability insanely.

Anyways, I'd like to have everyone using the same convention in all classes (with the predefined order of all regions) like:

  • Private Fields
  • Constructors
  • Class Properties
  • Event Handlers
  • etc...

Do you have any proposition how this division could look like (What regions have sense and what names should they have) and in which order should they be defined ?

like image 762
theSpyCry Avatar asked Apr 06 '10 08:04

theSpyCry


1 Answers

Someone once said that having a convention like the one above:

  • Private Fields
  • Constructors
  • Class Properties
  • Event Handlers
  • etc...

is like setting a table where all the plates are together, all the spoons are together, all the knives are together and all the forks are together.

My take on the #region issue is to put related methods, event definitions, and properties together in one region. However, having to do this at all would indicate a code smell (either your class is too big or does too many things) but this is a good first step into refactoring it into a better class.

like image 197
Jon Limjap Avatar answered Sep 21 '22 11:09

Jon Limjap