Property Manager AddIn for Visual Studio 2005
posted on Sunday, December 11, 2005 by bobby @ 1:49 am
Visual Studio 2005 added refactoring to it's list of new features. Included in the refactoring list is the Encapsulate Field attribute - which is designed to create a public property that references a local variable.

So...
Copy code to clipboard in IE or select code for Firefox
private string firstName


would be
Copy code to clipboard in IE or select code for Firefox
private string firstName

public string FirstName
{
    get
    {
        return firstName;
    }
    set
    {
        firstName = value;
    }
}


While I really like the fact that Microsoft took the initiative to incorporate refactoring techniques like this, there are a few things that bother me about this.

  1. You can only encapsulate 1 field at a time. Super weak.
  2. You have no option of where the generated code is placed in your code. It defaults to just below the field being encapsulated.
  3. You don't have the option to NOT update references. This one is really lame because on slower machines, it takes quite a bit of time for VS to parse all your possibly affected code.


These 3 issues bother me so much, it's faster and less cumbersome for me to manually type out my properties. I finally hit the threshold of time wasted doing this tedious task today, so I decided to write an AddIn that will do it for me. Enter Property Manager - get it??

You can select as many local fields as you'd like - right click > Create Property (or ctrl + alt + p)



That's it - your new properties are now copied to your clipboard. You can paste them where ever you see fit. For me, it's inside my Properties region.

The property names are automatically generated for you based on the name of the field. The first letter is capatilized and any starting underscores are removed.

So firstName and _firstName become FirstName

At this point, all properties that are created have a public modifier. Check the Code Editor status bar to make sure your properties were created and copied to the clipboard.

Click here to download Property Manager, then go give someone a hug.

You must be using v2.0.50727 of the .NET Framework

CommentsComments
posted on Sunday, December 11, 2005  by Blogus Maximus @ 11:34 PM

very cool!! Thanks for this.
posted on Monday, January 16, 2006  by Bernardo Heynemann @ 9:53 PM

Can I have the source code?
I need to do the exact same thing, but I use an ORM framework that requires that I put a Changed("NameOfProperty,value) on every single set { }.
I really wish that I could change this.

My contact e-mail is heynemann@gmail.com
posted on Wednesday, January 18, 2006  by Nerd from Oz @ 1:34 PM

Nice work Bobby, thanks mate!
posted on Wednesday, January 18, 2006  by bobby @ 1:36 PM

Any day man.
posted on Thursday, February 02, 2006  by cheapcallguide.co.uk @ 1:10 AM

I've been wanting something like this for the last three years.

You rock.
posted on Friday, May 26, 2006  by iucon @ 9:12 PM

Hi,

really nice one. Extremly helpful!!
But you addin contains al little but.
Field that starts with an underscore are not transformed correctly to properties.
An example:

private string _test;

will produce

Copy code to clipboard in IE or select code for Firefox
public string Test
{
  get {  return test; }
  ...
}


So the underscore gets lost in the properties. I hope, jou can fix this small bug.
posted on Saturday, May 27, 2006  by bobby @ 2:46 AM

Yeah, I'll definitely take a look at that. Check back in a few days for an updated version.

Cheers
posted on Saturday, May 27, 2006  by bobby @ 6:00 AM

I've updated the latest version [1.0.0.3] which includes a fix regarding the local fields beginning w/ an underscore.

The latest version post can be found here.
posted on Friday, June 30, 2006  by Phosphora @ 5:54 AM

Very nice! I'm used to work with Eclipse (while coding Java) and when I'm now working with C# and I found that there is no way to generate properties I was really disappointed. Thanks for filling that gap.
posted on Friday, September 22, 2006  by Jason @ 9:52 AM

Very cool add-in. Is there any thought to a template type system that will allow the programmer to control the output of each property? I need to be able to decorate my properties with several attributes and/or raise an event when a property is changed.

Maybe even allow for multiple templates so you can select the Business Entity property template or the Data Layer property template depending on where you are working in the code. To do this you could have a sub menu under Create Property for each of the different templates you have added.
posted on Friday, September 22, 2006  by bobby @ 11:58 AM

Haven't really put that much thought into it, but those are good ideas. I've got to make some minor updates to it sometime soon so I'll play around with the templating thing a bit.
posted on Wednesday, December 13, 2006  by Anonymous @ 2:44 PM

Is there way to generate a constructor in the similar fashion
posted on Tuesday, May 15, 2007  by eelledge @ 9:22 AM

Great utility. Thank You
posted on Wednesday, August 22, 2007  by Fabio - Olinda, Brazil @ 12:05 PM

Thank you very much, Bobby. You saved me hundreds of typing hours.
posted on Tuesday, August 28, 2007  by MIV @ 8:49 AM

Thank you so much! Realy good idea.
posted on Monday, October 29, 2007  by Sebastian @ 9:47 AM

I
LOVE
YOU
posted on Wednesday, December 05, 2007  by Anonymous @ 8:12 PM

How do I install in VS2008? I ran the PropertyManagerAddInSetup.exe, it installed the add-in in VS2005 but not 2008.
posted on Thursday, December 06, 2007  by bobby @ 9:59 AM

That is because that version is for VS2005. Try using the version built for VS2008 over here
posted on Thursday, March 13, 2008  by Long @ 6:06 AM

Tuyet voi == Greate
I'm Vietnamese.
posted on Tuesday, March 25, 2008  by Zulfi @ 7:29 AM

You're the best !!!
posted on Tuesday, June 03, 2008  by Anonymous @ 8:29 AM

Great tool! Thank you very much.

It seems to have an issue with generics though. I tried it with a list properties.
posted on Tuesday, June 03, 2008  by Anonymous @ 8:33 AM

I take back what I said above (about the problem)

Specifically if I instantiate my generic object on the same line as the declaration, it confuses the tool.
posted on Saturday, June 21, 2008  by ABC @ 5:04 AM

Lovely! This just saved me a hell lot of tedious work!
Thanks man, well done
posted on Monday, August 25, 2008  by Anonymous @ 4:35 AM

I love you!
posted on Friday, October 17, 2008  by Matt @ 12:11 PM

At first try, this appeared to do absolutely nothing. But now I've realized that it does generate code, but unfortunately not in the page - into the clipboard. So I have to right-click, select Create Property, then hit Ctrl-V. But the real down side is that when I have something on my clipboard that I want, too bad - it's gone after using this. Uninstalled for now...
posted on Friday, October 17, 2008  by Matt @ 12:13 PM

^ Oops, forgot to mention that it's the 2008 version
posted on Thursday, November 13, 2008  by Dennis @ 4:25 PM

Can you release the source for this add-in? I would like to extend it so it you can select template to use e.g. change formatting, add attributes etc. Would be happy to re-post the changes back for everyone's benefit.
posted on Wednesday, April 08, 2009  by Kirsty @ 3:43 AM

First of all EXCELLENT tool!

Got a very slight issue with the formatting - Tools, Options, TextEditor, C#, Newlines doesn't have an option for properties. So I am stuck with the property get, set etc. all on the one line. I am using VS2005 SP1.

What have I missed???


New Post Notification

Search Posts

Recent Posts


About Meeself
People call me Bobby DeRosa
I live somewhere in San Diego, CA
MCSD, MCAD, MCP

This theme was adapted from fUnique by fahlstad        Icons by FamFamFam        XHTML 1.0 Strict; tuned for Mozilla-powered browsers

Admin Login Administrator Login
Invalid login attempts are logged.
  Username:
  Password: