I'm venturing into new territory as far as my normal coding habits; I'm creating structs to handle some of my applications basic data types.
I have a struct for JoyAxis which contains info for a single axis, then a struct for XYJoy which contains info for several JoyAxis(s), I want to be able to define values for JoyAxis inside XYJoy without having to reconstruct the entire axis.
For example if JoyAxis has values for current, min, and max; assuming X is JoyAxis inside MyJoy which is XYJoy, I want to be able to set the (current) value by MyJoy.X = 23 but still maintain MyJoy.X.min and other struct info.
It occurs to me I could override get /set of a field that points to it (again new territory for me so i'm not sure that terminology is correct) but being so new to this I wanted to know if there is a more common way to do this.
public struct JoyAxis
{
int Value { get; set; }
int max_Value { get; set; }
int min_Value { get; set; }
int center_Value
{
get
{
return (int)Math.Ceiling((double)(this.max_Value - this.min_Value) / 2d);
}
}
public JoyAxis(int value)
{
this.Value = value;
}
public JoyAxis(int value, int min_value, int max_value)
{
this.Value = value;
this.min_Value = min_value;
this.max_Value = max_value;
}
static public implicit operator JoyAxis(int value)
{
return new JoyAxis(value);
}
}
public struct XYJoy
{
JoyAxis X { get; set; }
JoyAxis Y { get; set; }
}