Update 3.10.2017: Regionizer 2.3 - Regionizer now runs on Visual Studio 2017 and Visual Studio 2015.

More updates are coming soon.

Update 5.11.2014: Regionizer 2.1.4

It is no longer required to run Visual Studio as an administrator to update the registry when setting up the comment dictionaries. I was schooled by the folks on Reddit for this, so I am now using Registry.CurrentUser to store the registry values, instead of Registry.LocalMachine.

I guess you can teach an old dog new tricks.

Update April 24, 2014: Regionizer 2.1 Now includes an auto commenting system that uses regular expressions and two dictionary files to allow you to create your own 'Comment Items'.

April 27, 2014: Regionizer 2.1 C# Auto Commenting System Video:

https://www.youtube.com/watch?v=lB86fBS0fZg

Contest: There is currently a contest for the first person to submit a working comment item; read the comment on the YouTube video, no one has entered as of 5/1/2014 10:30 PM.

Note: remove any previous versions of Regionizer before installing.

Install Regionizer 2.1 for Visual Studio 2012 or 2013.

Select a folder to hold the comment dictionary.

Click the 'Check For Update' button; this will let you know if there is an update available.

If an update is available, the 'Download Button' will become enabled.

If an update is found, the latest Comment Dictionary will be downloaded from www.datajuggler.com.

After you are shown a message that the file has been downloaded, click the 'Update Registry' button, this will update your system.

To view the Comment Dictionary click the 'View Comment Dictionary' button in the Regionizer Tool Window.

Regionizer allows you to set two comment dictionaries:

CommentDictionary.xml - The base dictionary xml file, this file must be named CommentDictionary.xml
It is recommended you do not modify this file, as the next time you download an updated version your customizations would be lost.

The custom dictionary can be named any name you choose, although it must be end in the .xml extension.

To create a custom dictionary file, remove all but one of the comment items from CommentDictionary.xml file. Modify the remaining Comment Items to suit your needs and save the file as 'CustomDictionary.xml' (or whatever name you choose).

Click the 'Setup Comment Dictionary' button and then browse for the custom dictionary file.

After selecting the file this should enable the 'Update Registry' button.

For Windows 8, or 8.1 you must be an administrator to update the registry so you will need to run Visual Studio as an administrator to register a custom dictionary.

To test the auto commenting system:

1. Check the Auto Comment check box on the Regionizer Tool Window (dock Regionizer in the same area as the Solution Explorer or Properties Window).

2. Open any C# project, copy and paste the following code snippet:

// locals for test
object securityObject = null;
int userID = 0;


if ((securityObject != null) && (userID > 0))
{

}

Place your mouse directly over the word 'if' and hold the Control key down and press Shift (Control + Shift).

Regionizer will insert the following comment:

// If the securityObject object exists and the userID is set

Creating Comment Items:

The following comment item
<CommentItem>
<Comment>The Text Of The Comment (Use * for Target Pattern wildcard and % for TargetPattern2 wildcard.)</Comment>
<Name>The name of your comment</Name>
<Pattern>The Regular Expression To Match</Pattern>
<TargetPattern>The Pattern To Match the wildcard *</TargetPattern> (optional)
<TargetPattern2>The Pattern To Match the wildcard %</TargetPattern2> (optional)
<Type>IfStatement</Type>
</CommentItem>

If you edit the Comment Dictionary or the Custom Dictionary, uncheck and recheck the Auto Comment check box, and this will reload the Comment Dictionaries.

There are four reserved characters that cannot be placed directly in an xml file; You can now launch the Xml Reserved Character Helper from the Regionizer Menu. There is also a stand alone copy of this program located in the Tools directory of the download if you prefer to run this tool outside of Visual Studio.

Once you build your regular expression for a pattern, target pattern or target pattern 2 use this tool to encode the characters '> < & or %'. You only need to use this tool if your comment item's pattern, target pattern or target pattern 2 contains any of these characters.

As of now there are text replacements that are made automatically to remove any open and closing parenthesis ( ) or < > characters that end up being part of the Target or Target2.

If more replacements are ever needed in the future I am toying with a 'Replacements' section for each target item (Target 1 and Target 2).

To create your regular expressions, I highly recommend using 'RegEx Hero' located at:

www.regexhero.com.

This website allows you to visually parse a regular expression.

The following websites helped me learn regular expressions in the last couple of weeks:

http://en.wikipedia.org/wiki/Regular_expression
http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet

If you try and apply a comment (Control Shift) and the comment is not found, Regionizer will highlight the line of code that a match could not be found for.

If you want to create a comment item for that line of code, copy the code and go to RegEx Hero (www.regexhero.com) and click the Try It Now button, and paste the source code in the bottom section.

Then apply a regular expression until you sufficiently match the line you are looking for.

Here is a simple tutorial:

source code: if (x > 5)

The pattern needed to match the above source code is as follows:

if\s?\(\w*\s?>\s?\d\)

I will explain the break down of this pattern as I understand it (if a regular expression guru can shed more light on any of my documentation please leave me a note on the discussions tab and I will update the documentation).

if

if matches the word if.

\s?

Matches the space after the if. The ? after the \s is because the space is optional:

if(x>5) is perfectly legal C# syntax, so the spaces need to be optional.

\(

The parentheses is used for grouping in regular expressions, so to match an open parentheses (
you must add a preceding \ .

\w*

\w matches any text pattern, or the same as azAZ09 and the * after the \w means the match extends for one or more characters.

\s?

This is another optional space between the target, and the > (Greater than Symbol)

>

The greater than symbol is matched

\s?

This is another optional space between the > (Greater than Symbol) and the target 2

\d

Represents a a digit (numerical value)

\)

The closing parenthesis ) must be preceded by a \

Now for the target pattern:

The target pattern in this case is:

\(\w*

That will end up with a match of: (x

Since an automatic replacement is performed for open and closing parenthesis ( ) are removed, so the target becomes x.

The Target Pattern 2 is:

\d\)

This evaluates to : 5)

And since the open and closing parenthesis are automatically removed, the 5) becomes 5.

Thus the comment:

if the value for * is greater than %

becomes:

if the value for x is greater than 5

One very useful regex pattern that I just learned is how to do look a heads and look behinds.

Source code: if (!allowAccess)

Pattern: if\s?\(\!\w*\)

Target Pattern: (?<=\!).*

The Target Pattern in this case is a positive look ahead

The target pattern will match whatever directly follows the ! (not operator) and the result will be:

allowAccess)

The closing parenthesis will be automatically removed so the target becomes allowAccess.

The comment in this case:

f the value for * is false evaluates to:

if the value for allowAccess if false.

It is really quite simple to create new comment items.

It is recommended you add new comment items to the bottom of your comment dictionary as to not interfere with other working comments, but sometimes the order matters and a simpler match must be moved down to match a more specific comment.

I will try and make a test library this weekend to ensure new comments do not break existing ones.

If you create any useful comment items and think they are worthy of being in the comment dictionary, please email support@datajuggler.com or leave a message here in the discussions tab.

If anyone knows a way to bi pass running Visual Studio as an administrator to be able to update the registry, that is something I would like to be able to solve.

That is my biggest gripe with Microsoft for Windows 8 (8.1) in addition to the fact I cannot stand the tiles layout for apps, but I want to be an Administrator on my own machine, and Microsoft doesn't allow me to.

I will make a new video later this weekend.

Update April 29, 2013: Watch the Regionizer Intro Movie on YouTube: http://youtu.be/dtHtVAT_xW0

Format Document - This tool is used to arrange your C# code file into seperate regions for:

Using Statements

Private Variables

Constructors

Methods

Events

Properties

The Methods, Properties and Events are surrounded by regions, and sorted alphabetically to make your code easy to navigate.

The main advantage of Regionizer is that no matter what coding style each developer on a team uses, the code will be formatted the same regardless of individual style. This consistency helps when multiple team members all code the same way.

Although we successfully parse multiple classes per file, Regionizer works best with a single class per file at the time of this writing.

Format Selection - When you use the Visual Studio tools for Generate Method Stub, or if you create an Event Stub by using the Properties Window, Visual Studio creates a method stub such as the following:

private void Test()
{
throw new NotImplementedException();
}

Visual Studio places this stub whereever it feels like it.

Take your mouse and select the the method stub, as well as any blank lines above it you want to remove, and click the Format Selection button.

One imortant thing to note is if you are formatting a Method, the Methods region must exist (A region with the name #region Methods) and the same is true if you are formatting an Enent or Property, the Events region must exist or the Properties region must exist or else you will get a not very informativce message.

If FormatSelection doesn't work, this is most likely the cause (a missing region for the type of object being formatted).

One more thing on my list for version 2.0 is if you have a read only property and you use format selection, the method description still states 'This property gets or sets the value for 'xxx' where I should change it to 'This proprety returns the value for 'xxx'.

Add Method, Event, Private Variable. - The Add Method and Add Event are the most useful, the Add Private Variable I left in as that was the first text I created as a test, but it works if you want to use it.

Add Method does not handle Parameters at this time, as that is on my 2.0 list of enhancements.

Make sure the Return Type is the type of object you wish to return when you click this as this will be used to create the variable and return type and comments for Initial Value and Return Value.

Add Event switches to the return type of void and the parameters created are (object sender, EventArgs e) so you will have to wait for Version 2.0 for custom parameters for events also.

Create Properties - This is my favorite feature in Regionizer. Select one or more private variables, and click the Create properties button, and all of the properties are created in Alphabetical Order.

Create Has Property - This is another feature I like. If you have a property, and you want to test if it exists, select the Proprety Name (by double clicking or using your keyboard) and click the 'Create Has Propery' button.

You will get a property such as this;


#region HasLoggedInUser
/// <summary>
/// This property returns true if this object has a 'LoggedInUser'.
/// </summary>
public bool HasLoggedInUser
{
get
{
// initial value
bool hasLoggedInUser = (this.LoggedInUser != null);

// return value
return hasLoggedInUser;
}
}
#endregion

Also, Create HasProperty works on Strings and Numeric Values:

#region HasName
/// <summary>
/// This property returns true if the 'Name' exists.
/// </summary>
public bool HasName
{
get
{
// initial value
bool hasName = (!String.IsNullOrEmpty(this.Name));

// return value
return hasName;
}
}
#endregion

Or for a numeric value:

#region HasCountryID
/// <summary>
/// This property returns true if the 'CountryID' is set.
/// </summary>
public bool HasCountryID
{
get
{
// initial value
bool hasCountryID = (this.CountryID > 0);

// return value
return hasCountryID;
}
}
#endregion

The biggest advantage of using HasProperties are:
1. You can use intellisense for HasName instead of (!String.IsNullOrEmpty(this.Name)) takes much longer to type.
2. Compound If Statements are easier when you can type:

((this.HasUser) && (this.User.HasStreedAddress))

versus: ((user != null) && (!String.IsNullOrEmpty(user.StreetAddress)))
  • The New Buttons For Version 1.5 ** (Updated in version 1.6)

Initial Value Button - This button is used to write out the stub of the return type of the method:

To use the Initial Value Button, set the Return Type to the data type returned, and set the Target to be the variable name.

Example: Return Type: double
Target: total;

// initial value
double total = 0;

// return value
return total;

This works best for objects, strings and numeric values (ints or doubles).

If Exists Button This event writes out an If Block and a comment above it.

To use the If Exists Button, set the Return Type to the data type of the variable, and set the Target to be the variable, as shown below:

Example:
Return Type: double
Target: total

// If the 'total' is set.
if (total > 0)
{

}

For Each Button (4 Each) - This button is used to create a For Each Loop to iterate a list or collection.

To use the If Exists Button, set the Return Type to the data type of the variable, and set the Target to be the collection name, as shown below:

Example:
Return Type: Contact
Target: contacts

The variable name is created from a lower case copy of the ReturnType, so this will not work for iterateing strings or ints in a list, as the name would be (foreach int int in CollectionName) and this will blow up;

I should probably use a temp name now that I thought about it, but I wrote this just to have an update as I haven't done an update on Regionizer in six months so at least a few new features made it in.

It takes one second to rename a variable so having the foreach loop stubbed out is still faster than writing it form scratch.

// Iterate the items in the collection
foreach (Contact contact in contacts)
{

}

One minor bug that I wish I knew how to fix was the indent s sometimes wrong with this feature, but that is an easy fix to increase or decrease the indent.

These new features save me a lot of time, so hopefully you will find them beneficial also.

I know the Smart Descriptions are not perfect, but I hope to improve upon them, and I would even like to research an auto commenter for Visual Studio, but that is probably a long term project.

If you have any ideas or suggestions please email me at corby@datajuggler.com and put Regionizer in the subject so I make sure to read it.

Thank you,

Corby Nichols
Regionaholic.

Last edited Mar 10 at 4:14 PM by Corby, version 20

Comments

No comments yet.