Abhishek Srivastava <ab************ *****@nospam.ne t> wrote:
There is a particular feature which I want to have in visual studio .net
suppose I create a class
ClassA
{
private string name;
private int age;
}
Then I right click on my code and say "generate properties".
And a property gets created (with capital for the first character ex.
Name, Age) for each of the private members of my class.
Can I do this is vs.net?
Others have answered the question you've actually asked, but I'd like
to propose a different solution: namely a way of the C# language itself
changing to allow "simple" property definitions. The syntax is up for
grabs, but I'd suggest something like:
<AccessModifier > property <TypeName> <fieldName> [ = <initialValue >]
<PropertyName > {[get;][set;]}
For instance:
public property string name Name { get; }
protected property int height=10 Height {get; set; }
would be exactly equivalent to:
private string name;
public string Name
{
get { return name; }
}
private int height=10;
protected int Height
{
get { return height; }
set { height = value; }
}
XML documentation applied to the short form would either be applied to
the field, the property or both - up for grabs, but I'd favour the
property, with an automatic XML documentation for the field of "Field
backing the simple property <PropertyName >: <XML doc for PropertyName>"
I was seriously anti this a while ago, and argued fairly vehemently
against it - but I now believe it would make a lot of code
significantly simpler, and might persuade people to use properties
where they might otherwise use public fields just for convenience.
Whether or not one could declare the property to be virtual, I don't
know - and likewise exactly how different access modifiers for get/set
would work.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too