Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Limit to #region nesting?
Message
De
12/09/2011 08:40:16
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01523118
Message ID:
01523212
Vues:
38
In my opinion the #region is goog organization of code and I use much the same as Viv. Using ReSharper helps navigate code but sometimes for instance if I have many properties in a class, collapsing the region around the properties makes the file more manageable to wonder through. I don't view it as hiding code, but rather just part of organizing.
Just another view point.
Timothy

>Not to take this off course, but are you a fan of #region or not? Or does it depend?
>
>Based on far less experience with .NET than you, I am ambivalent. If it's standard .NET emitted code like the kind that is generated for every form, sure, hide it. If it's code I wrote myself, eh, I'm not so sure. Maybe irrelevant stuff that would interfere with reading the code would be put off in a corner where it belongs. OTOH if there is something fishy in the hidden code, maybe something that was applicable when it was written and no longer is, regions increase its likelihood of remaining uncaught. If you don't see it you can't fix it.
>
>Let me put it another way. Are there certain types of code that we write ourselves that are candidates for #region and types that are not?
>
>>VS2010 is less restrictive in this respect. In fact I don't think there are any restrictions - even defining regions that would make no sense in real coding are allowed. e.g.: This will work in 2008 and 2010:
#region A
>>    public class C1
>>    {
>>    #endregion
>>    }
wheras this will fail in 2008:
public class C2
>>    {
>>             #region B
>>    }
>>#endregion
In 2010 even something like this will work:
public class C2
>>    {
>>        public void Foo()
>>        {
>>            #region B
>>        }
>>    }
>>#endregion
But, bottom line, you usually need a region to contain only complete code blocks and 2008 handles that OK. Arguably, 2010 is worse since it's possible to define regions that work as specified but are actually conffusing since they expand/collapse arbitrary code selections...
>>
>>>A little futzing revealed the answer:
>>>
>>>When I put all of the child #endregions within the curly brace that teminates the class, alll was well.
>>>
>>>>>I have a large class with a lot of methods (I probably will break it up the next time I add to it) and I have used #region foomethods / #endregion pairs to make it more readable.
>>>When I nest more than 4 pairs in a parent pair, the class compiles OK but the - and + marks don't appear on the 5th region and I can't expand or collapse it.
>>>Is that a limit or am I doing something odd again?
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform