473,671 Members | 2,578 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 5705
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 "refactorin g".
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...@new sgroup.nospamwr ote:
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 "refactorin g".

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/dxcorecommunity plugins/


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
1644
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 a fault in my code which is exposed by the improved CSS standards support in v7.5p1. The top margin on the <h1> collapses with the zero margin on the <body> element to form a single margin equal to the margin specified on the <h1>.
6
1857
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
2403
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. What impact do access modifiers have on the order? Also, does anyone use standardised region names?
6
7372
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. Thanks in advance! Jack
7
2728
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
863
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
897
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 or a feature, this was very handy.... In VS2005, this "feature" appears to be gone. Is there a new manner of achieving the same function?
8
1747
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 (blah, blah). Anyone have any suggestions for having regions and their comments show up in XML comments...
5
1958
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, functions, etc, while in vb.net 2005 those parts after the name (arguments, etc) are missing. Is there an option to show them as well, or this is the only working method of the collapsing? What amazed me that the collapsing in the vC.net 2005 shows the...
0
8481
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8823
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6234
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4412
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1814
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.