visual studio .net comes with the #region and #endregion directives to be able to collapse code sections using the IDE. by default, the generated code (i.e. InitializeComponent method block) which is used by winform and webform designer to recreate the forms at design time are enclosed in this block since developers should not manipulate it and it is rare for developers to view them at the code editor. it's primary purpose is code readability when used properly.
i have seen developers abusing this feature. There are some who wants to segregate properties, constructors, eventhandlers and methods using this feature up to the worst scenario where each routine is enclosed in a region block (no offense but for pete's sake, you can use the class view to see an outline of the interface of your classes with a number of grouping options and you can even double click on the signature and the editor brings you to the code declaration)
although there is an option to collapse region blocks when a code sheet is opened (Tools->Options->Text Editor->C#->Outlining->Collapse #region blocks when files open.), you can only choose between collapsing them all or expand them all when a code sheet is opened. the primary purpose of selective code view of the #region block is sometimes defeated. i'm a very O-C coder and every misused feature like this eats my time.
below are the ideal things (in my opinion) that need to be enclosed in a #region block
- designer generated code
- interface implementation
Posted
Nov 30 2005, 12:28 PM
by
jokiz