I want to tag the values of variables with a "quality" attribute that can be changed dynamically during my programs execution. My first thought was to abuse the standard attribute functionality by tagging the value with my custom quality attribute. EG
[QualityAttribute(Quality.Bad)]
int value = 0;
...
value = 1;
(** somehow set QualityAttribute of value to Quality.Good **)
But from what I have seen attributes were intended as a static measure and are baked into meta-data, making what I want to do apparently impossible.
An alternative would be to make a struct/class that contains both the variable and the quality. EG
class Value
{
public Quality quality = Quality.Bad;
public int value = 0;
}
...
Value value = new Value();
value.value = 1;
value.quality = Quality.Good;
This will work (and is similar to what is used to support nullable types) but I don't really like the extra layer of indirection to get to the value.
Is there any other way that allows direct access to the value and easily supports tagging value with a custom, dynamically alterable attribute?
class Value
, but with anoperator int
method