Private Variables to Public Properties - question

  • Thread starter Thread starter t f
  • Start date Start date
T

t f

Hi

I have a class with a bunch of private variables in, is there an easy
way to make these have public properties without having to type it all in?

e.g.

public class Fu
{
private float fBar;

//now instead of having to type this
public float Bar
{
get
{
return fBar;
}

set
{
fBar = value;
}
}
}

thanks
t f
 
Unfortunately, no, there is nothing in the language that will allow you
to do this. You will have to type out all the properties.
 
I have a class with a bunch of private variables in, is there an easy way
to make these have public properties without having to type it all in?

e.g.

public class Fu
{
private float fBar;

//now instead of having to type this
public float Bar
{
get
{
return fBar;
}

set
{
fBar = value;
}
}
}

thanks
t f

If you really have that many then try a recorded macro or even a permanent
one you can assign to a hotkey. I find macros are undervalued (and even
unknown) by many developers but they frequently save a lot of time. It takes
some thinking for more elaborate activities like this but with practice you
can crank out even complicated scenarios quickly.
 
Hi

I have a class with a bunch of private variables in, is there an easy
way to make these have public properties without having to type it all in?

e.g.

public class Fu
{
private float fBar;

//now instead of having to type this
public float Bar
{
get
{
return fBar;
}

set
{
fBar = value;
}
}

}

thanks
t f

If you have VS2005, you can right click the field and open the
refactor menu, and choose encapsulate field.
 
Andy said:
If you have VS2005, you can right click the field and open the
refactor menu, and choose encapsulate field.
lol i didnt even notice that one... cool thanks :-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top