The best way to explain my problem is with a code snippet:
enum Resource { ..., Size }
class ResourceVector
{
int[] values = new int[(int)Resource.Size];
public static ResourceVector operator + (ResourceVector a, ResourceVector b)
{...}
...
}
We are using this type everywhere as though it were a value type. I.e. we are making the assumption that:
ResourceVector b = a;
b += c;
will not affect a
, because that is how we are used to talking about vectors (and that is how a vector with a fixed number of fields does behave, if implemented as a struct).
However since that assumption is wrong, it has led to some extremely subtle bugs.
I am wondering if there is a way to make this behave as a value type, other than just expanding the members of Resource
each into their own members in a struct ResourceVector
(which requires touching every member of ResourceVector
if we wish to add another Resource
).
Oh, just in case, we are working with C# 2.0. So no fancy-pants features :-)
Thanks.