C# Property Generator

Description
When I first started using C# (almost 3 years ago since the original posting of this) my first task was to take a whole bunch of existing classes that only had private variables using old style get/set to access them. Of course, C# has properties that are much nicer to use. So after realizing it would take me way too long to do them by hand I wrote a program to do it for me. The problem was that for some variables you might only want to have a getter and for some you might want to both or some other combination. So, C# property generator was born. I originally wrote it a long time ago but I updated it since I started my blog so that it was a bit nicer to look at.

How To
Hopefully this program is easy enough to use but just in case here is a quick how to. Say you have the following code:

/// 
/// My summary for var one
/// 
private int myVarOne;

/// 
/// Summary for var two
/// 
private string myVarTwo;

/// 
/// Summary for var three
/// 
private int myVarThree;

public string myVarFour;
So now paste the code into the big text area on the left hand side.

Now pretend that you don't want a property for myVarThree and you only want the setter for myVarTwo. So uncheck myVarThree in the variable list and select myVarTwo and uncheck the get property. As you can tell myVarFour doesn't show up in the list because it is public already (why would you want a property for a public variable?)

It should look like this now

Almost done. Click the "Copy result to clipboard" and then paste the code back into the class file that you want. It should look like this:

#region Properties
/// 
/// My summary for var one
/// 
public int MyVarOne
{
	get
	{
		return myVarOne;
	}
	set
	{
		myVarOne = value;
	}
}

/// 
/// Summary for var two
/// 
public string MyVarTwo
{
	set
	{
		myVarTwo = value;
	}
}

#endregion

That's pretty much it. Hope it's useful to you. If you have any suggestions/comments please let me know.

Change Log

Version 1.0

  • Initial Release