Any tool in VS to make property and fiels at same time?

  • Thread starter Thread starter James Maeding
  • Start date Start date
J

James Maeding

In VS 2008, C#, I typically make a field:
private double _myDbl = 0.0;

then highlight _myDbl and refactor to encapsulate field as property "MyDbl".
I wish I could do some kind of snippet that would let me give field name and it would give property code automatically.

The other thing is the refactor step always throws code right under field code.
It would be nice if i could have it put the code down in my Properties region of code.
This might be handled better by a class wizard dialog of some kind. The ones in VS do not seem to help in these areas.

I'm looking for free built-in solutions first, then pay apps if that is only way. I'm new enough to C# that I don't
know what seasoned programmers look to. Any advice appreciated.
 
James said:
In VS 2008, C#, I typically make a field:
private double _myDbl = 0.0;

then highlight _myDbl and refactor to encapsulate field as property "MyDbl".
I wish I could do some kind of snippet that would let me give field name and it would give property code automatically.

The other thing is the refactor step always throws code right under field code.
It would be nice if i could have it put the code down in my Properties region of code.
This might be handled better by a class wizard dialog of some kind. The ones in VS do not seem to help in these areas.

I'm looking for free built-in solutions first, then pay apps if that is only way. I'm new enough to C# that I don't
know what seasoned programmers look to. Any advice appreciated.

Have you looked at automatic properties? Very often the backing field
is not needed. For example:

public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
 
I had been using private vars and properties because a few tools i had would not recognize the public fields as
properties.
So i got in the habit of always doing the member and prop.

I guess i could just "risk it" and stop that double defining.
I need to make sure reflection treats the public members the same as props.
If any issue comes up, I could just add back private vars.

Christian Treffler <[email protected]>
|>James Maeding schrieb:
|>
|>> I wish I could do some kind of snippet that would let me give field
|>> name and it would give property code automatically.
|>
|>Try the following:
|>Write "prop" and hit the tabulator key twice.
|>
|>HTH,
|>Christian
 
Back
Top