Is there any way in C# to be able to do this:
map.player.x = 5;
while keeping player of type Point (or silently convertible to one) and still be able to check the value for correctness when doing the assignment?
To be clearer:
Pointis a struct defined by the C#/.net standard libraries and is passed by value.- Making a wrapper class and implementing all of
Point‘s methods as call-throughs toPointis long and tedious. - Having a wrapper class with nothing but an implicit coversion to/from
Pointwill not allow the above. It would have to be written as(Point)(map.player).x, which is clumsy.
If I understand you right, you seem to want to get some flexibility by defining type-conversions. That won’t go very far.
Avoid mutable structs (value types).
struct Pointis an unfortunate leftover from the old Win32 API.So aim for
map.player = new Point(5, map.player.y);