As of right now, when someone wants to create a setter that updates two properties simultaneously on ImmutableBase<TImmutable>, they have to create their own setter that manually invokes the constructor or invokes SetPropertyValueImpl twice. This is because SetPropertyValueImpl only allows one property to be set at a time.
This is problematic for two reasons:
It is an unnecessary performance hit because you have to create two instances even though you knew the value of each property before the operation began.
If two properties are coupled and have argument validation perform in the constructor, you cannot update them both simultaneously so they avoid a conflicting state.
The latter is particularly frustrating. Consider that you have, for example, aMinimum and Maximum property on the immutable class. In your constructor, you throw an ArgumentException if Minimum is greater than Maximum. This means if you want to change the range of Minimum and Maximum from 1 to 5, to 6 to 10, or -5 to -1, you have to know which order to set the values in, adding complexity to what should be a simple setter.
Adding the ability to set both of these properties at the same time removes this complexity.
Task
Add a SetPropertyValuesImpl implementation that takes in a IDictionary<string, object> that maps property names to property values so they can be assigned simultaneously, like so:
Background
As of right now, when someone wants to create a setter that updates two properties simultaneously on
ImmutableBase<TImmutable>
, they have to create their own setter that manually invokes the constructor or invokesSetPropertyValueImpl
twice. This is becauseSetPropertyValueImpl
only allows one property to be set at a time.This is problematic for two reasons:
The latter is particularly frustrating. Consider that you have, for example, a
Minimum
andMaximum
property on the immutable class. In your constructor, you throw anArgumentException
ifMinimum
is greater thanMaximum
. This means if you want to change the range ofMinimum
andMaximum
from 1 to 5, to 6 to 10, or -5 to -1, you have to know which order to set the values in, adding complexity to what should be a simple setter.Adding the ability to set both of these properties at the same time removes this complexity.
Task
Add a
SetPropertyValuesImpl
implementation that takes in aIDictionary<string, object>
that maps property names to property values so they can be assigned simultaneously, like so:Caveats: