I'm making a game using C# and I've been using A LOT of the following property definition:
private Prop<int> _attack;
public int Attack
{
get { return _attack.Get(); }
set { _attack.Set(value); }
}
The "Prop" class implementation is not relevant, but the "Get" is a simpler way of returning the property, and the "Set" sets the property AND sends an event to however is listening (if the value is different than the previous one)
This way, I can easily change the property and still get a notification of the change.
So far so good. But this way of implementing these "auto event-listener properties" makes a definition be 5~6 lines worth.
-- 10 properties = 50~60 lines of code. There's got to be a better way. --
My question is... Is there a way to generate code during compile time, using Custom Attributes that writes these lines of code for me?
For example:
[AutoProp]
public int Attack;
Turns into...
private Prop<int> _attack;
public int Attack
{
get { return _attack.Get(); }
set { _attack.Set(value); }
}
Is there such a thing?
Thanks