Skip to main content
GameDev.net gamedev.net
🔒 Locked

VS2005 (C#) Property code generation?

Started by smitty1276 Aug 27, 2006 at 10:21 AM 7 replies 3k views
Original Post
smitty1276
smitty1276
Does anyone know if it is possible to tell VS2005 to automatically generate properties for member data in VS2005, similar to the way Eclipse will autogenerate getters/setters for you? Surely there is at least a plugin? My dev time would be cut in half if I had this. [grin]
Conner McCloud
Conner McCloud
The shortcut you are looking for is prop and propg. And if it would cut your development time in half then you are doing something horribly wrong.

CM
Rob Loach
Rob Loach
To my knowledge, the is a class wizard somewhere in Visual Studio where you'll tell the wizard the properties and functions, and then it'll generate the skeleton for you.
Rob Loach [Website] [Projects] [
smitty1276
smitty1276
Quote:
Original post by Conner McCloud
The shortcut you are looking for is prop and propg. And if it would cut your development time in half then you are doing something horribly wrong.


Nonsense. [grin]

If you have potentially hundreds of structures providing an API agnostic interface to various components of an engine, and their primary purpose is to hold and validate data, 75% of your time is spent writing getters and setters. Doing web development with java involves a lot of that getter/setter crap too... eclipse was a godsend when I did that kind of work for a while.

You know, there is a reason that Eclipse and a zillion other tools provide that sort of simple code-generation, and it isn't just because they were bored one day. And it turns out that VS even provides it, as you have been kind enough to point out. Thanks! r++
jfclavette
jfclavette
You can also select a private/public member and use right-click->Refactor->Encapsulate field. It'll make the member private and generate a getter and a setter for you.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
smitty1276
smitty1276
Quote:
Original post by jfclavette
You can also select a private/public member and use right-click->Refactor->Encapsulate field. It'll make the member private and generate a getter and a setter for you.


Man, that's almost cool... it's almost like what eclipse does. But why on earth do they make it private? If you have a protected member and use that feature, it makes the property protected and makes the member private.

I don't like that. Thanks for the tip though. (I noticed the prop and propg features do the same thing, BTW.)
sjelkjd
sjelkjd
Quote:
Original post by smitty1276
Quote:
Original post by jfclavette
You can also select a private/public member and use right-click->Refactor->Encapsulate field. It'll make the member private and generate a getter and a setter for you.

But why on earth do they make it private? If you have a protected member and use that feature, it makes the property protected and makes the member private.


Because you shouldn't expose both the property and the field. The whole point of the property is to keep the field inaccessible.
smitty1276
smitty1276
Quote:
Original post by sjelkjd
Quote:
Original post by smitty1276
Quote:
Original post by jfclavette
You can also select a private/public member and use right-click->Refactor->Encapsulate field. It'll make the member private and generate a getter and a setter for you.

But why on earth do they make it private? If you have a protected member and use that feature, it makes the property protected and makes the member private.


Because you shouldn't expose both the property and the field. The whole point of the property is to keep the field inaccessible.


Um... a protected field isn't exposed.
Arild Fines
Arild Fines
Quote:
Original post by smitty1276
Um... a protected field isn't exposed.

Of course it is. Unless the class is sealed (in which case protected is meaningless) or internal (in which case you could just as well make the field internal as well), anyone can write a class to derive from your class and access that field with impunity.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.