473,511 Members | 14,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Collapsing regions of code within a function

I'm trying to organize some code I've written and was wondering if
anyone can provide any suggestions on an equivalent to #Region that
can be used within a function to collapse sections of code within the
visual studio editor. In essence I have a program where several
different calculations occur when a user clicks a button on the form.
Since some of these sections are rather lengthy, I'd like to better
organize them by being able to collapse sections individually. I like
using the #Region code to collapse sections, but it can't be used
within a function. I really appreciate any suggestions.

Thanks,
Matthew
Jun 27 '08 #1
3 5699
I'm trying to organize some code I've written and was wondering if
anyone can provide any suggestions on an equivalent to #Region that
can be used within a function to collapse sections of code within the
visual studio editor. In essence I have a program where several
different calculations occur when a user clicks a button on the form.
Since some of these sections are rather lengthy, I'd like to better
organize them by being able to collapse sections individually. I like
using the #Region code to collapse sections, but it can't be used
within a function. I really appreciate any suggestions.
The #Region directive does not work within methods in VB.NEt (apparently
it does in C#)

I would suggest that if you feel the need to reorganise your method, then
perhaps you should carve it into several smaller ones.

This process is one of a number of similar concepts refered to as "refactoring".
Refactoring is the process of altering your code for better design/readability/speed
without (in the strictest interretation) changing the effect of said code.

You can look this term up online for a better definition.

The refactoring I suggest here is sometimes called "Extract Method"

There are a number of tools which can help to automate this process.

2 examples would be RefactorPro (www.Devexpress.com/Refactor) and Resharper
(www.Jetbrains.com)

I personally use RefactorPro and have found it to be very useful. I have
no particular opinion of resharper but those that use it say it is also very
good and I have no reason to doubt them. Often the choice between these 2
tools is one of style and taste and therefore very hard to justify.

If you would like further information please ask.

My apologies if anyone finds this reply too commercial, I did try to present
both sides but I'm obviously quite biased :)

--
Rory
Plugins for RefactorPro/Coderush/DXCore :- http://code.google.com/p/dxcorecommunityplugins/
Jun 27 '08 #2
Thanks for the reply. I imagined there was probably a better way to
organize my code and refactoring seems to be the way to go. Thanks
for the advice.
On May 19, 3:55 pm, Rory Becker <rorybec...@newsgroup.nospamwrote:
I'm trying to organize some code I've written and was wondering if
anyone can provide any suggestions on an equivalent to #Region that
can be used within a function to collapse sections of code within the
visual studio editor. In essence I have a program where several
different calculations occur when a user clicks a button on the form.
Since some of these sections are rather lengthy, I'd like to better
organize them by being able to collapse sections individually. I like
using the #Region code to collapse sections, but it can't be used
within a function. I really appreciate any suggestions.

The #Region directive does not work within methods in VB.NEt (apparently
it does in C#)

I would suggest that if you feel the need to reorganise your method, then
perhaps you should carve it into several smaller ones.

This process is one of a number of similar concepts refered to as "refactoring".

Refactoring is the process of altering your code for better design/readability/speed
without (in the strictest interretation) changing the effect of said code.

You can look this term up online for a better definition.

The refactoring I suggest here is sometimes called "Extract Method"

There are a number of tools which can help to automate this process.

2 examples would be RefactorPro (www.Devexpress.com/Refactor) and Resharper
(www.Jetbrains.com)

I personally use RefactorPro and have found it to be very useful. I have
no particular opinion of resharper but those that use it say it is also very
good and I have no reason to doubt them. Often the choice between these 2
tools is one of style and taste and therefore very hard to justify.

If you would like further information please ask.

My apologies if anyone finds this reply too commercial, I did try to present
both sides but I'm obviously quite biased :)

--
Rory
Plugins for RefactorPro/Coderush/DXCore :-http://code.google.com/p/dxcorecommunityplugins/


Jun 27 '08 #3
<mp******@gmail.comschrieb
I'm trying to organize some code I've written and was wondering if
anyone can provide any suggestions on an equivalent to #Region that
can be used within a function to collapse sections of code within
the visual studio editor. In essence I have a program where several
different calculations occur when a user clicks a button on the
form. Since some of these sections are rather lengthy, I'd like to
better organize them by being able to collapse sections
individually. I like using the #Region code to collapse sections,
but it can't be used within a function. I really appreciate any
suggestions.
Sometimes adding obvious comments is sufficient, however not what you
are looking for.
Armin

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1623
by: Spartanicus | last post by:
I've been caught out by what I thought was an Opera 7.5p1 issue: http://www.spartanicus.utvinternet.ie/test/opera7.5p1_css_background_image_issue.htm but as was pointed out to me this is actually...
6
1848
by: C# Learner | last post by:
1) How often do you put regions into your code? a) very often b) occasionally c) infrequently d) never 2) If you didn't answer (d), what do you use regions for? a) hiding ugly code
4
2397
by: Simon | last post by:
Just starting on C# and would like to know what suggestions there are for the order in which declarations, event handlers, properties, private code, nested classes, etc, etc appear in your files....
6
7333
by: Jack | last post by:
Hello, I would like some advice on how to disable the behavior of treeviews to expand and collapse when double clicked upon, but still allow the user to use the plus and minus on each node. ...
7
2722
by: gaidar | last post by:
Hi, everybody, I'm just wondering if someone really need stuff like this: http://msdn2.microsoft.com/library/ms123401.aspx. If you answer yes than explain, please. Thanks! Gaidar
0
856
by: guy | last post by:
wouldnt it be nice if you could collapse regions, methods etc when looking at a read-only file? I can see why you cant but...
0
890
by: Sam Marrocco | last post by:
In VS2003, one could instantly close all the #Regions in a code document by clicking the Splitter button in the IDE. It left all the code expanded, but closed only the #Regions areas. Whether a bug...
8
1731
by: Spleenwort | last post by:
With regard to XML comments in c#. I think that #regions should be self-documenting relative to XML comments or that a <region> tag should be defined and auto-inserted when you type #region...
5
1947
by: SlowArrow | last post by:
Here collapsing seems to work differently in vb.net 2005 from that I use to see in vb.net 2003: Using the collapsing in vb.net 2003 shows the whole interface of the methods, subroutines,...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.