While implementing a custom settings provider I noticed that accessing a setting property's value changes its IsDirty
flag to true
.
// Arrange
var property = new SettingsProperty("property1")
{
PropertyType = typeof(Color),
DefaultValue = "Green"
};
// Act
var result = new SettingsPropertyValue(property);
// Assert
Assert.That(result.IsDirty, Is.False);
Assert.That(result.PropertyValue, Is.EqualTo(Color.Green));
Assert.That(result.IsDirty, Is.False); // <-- Assertion fails
Reflector gives me an answer to the question why the PropertyValue
getter is behaving like this - it contains a statement like the following:
if (_Value != null && !Property.PropertyType.IsPrimitive && !(_Value is string) && !(_Value is DateTime))
{
_UsingDefaultValue = false;
_ChangedSinceLastSerialized = true;
_IsDirty = true;
}
Can anybody shed some light on this at first glance strange behavior?