setPropertyUnsafeIfNotDefault<T> method

void setPropertyUnsafeIfNotDefault<T>(
  1. String property,
  2. T? defaultValue,
  3. T? value
)

Set property if not equal to the default value.

  • This is useful for preventing default state from bloating saved JSON models.
  • Object must implement == as value equality.

Implementation

void setPropertyUnsafeIfNotDefault<T>(String property, T? defaultValue, T? value)
{
  if (value != null &&
      value != defaultValue) {
    setPropertyUnsafe(property, value);
  }
  else {
    removeProperty(property);
  }
}