Consider following piece of code:
public class Foo
{
private float propA = 1.0f;
public float PropA
{
get { return propA; }
set { if (value != propA) { propA = value; DoBar(); } }
}
private int propB = 2;
public int PropB
{
get { return propB; }
set { if (value != propB) { propB = value; DoBar(); } }
}
private double propC = -1.0;
public double PropB
{
get { return propC; }
set { if (value != propC) { propC = value; DoBar(); } }
}
void DoBar()
{
//...Something is going on here
}
}
I was wondering, if someone could recommend a nicer way for creating properties in C# lang?
For instance in C++ i would use MACRO
for this purpose, since it will allow me not only do some action when property has changed, but also reduce the repetition of boilerplate code.
Thank you in advance.