Skip to content

Upgrading from 4.x to 5.x

Andreas Gullberg Larsen edited this page Nov 29, 2022 · 12 revisions

⚠️ v5 is still in alpha to finalize some last few minor breaking changes, but it is functional, stable and ready to use.

Most of the removed code was marked as obsolete for a long time in v4 before removed in v5 with details on what to replace the usage with.

💥 Breaking changes

  1. Localization is based on CultureInfo.CurrentCulture instead of CurrentUICulture (#795, #986)
  2. IQuantity returns QuantityValue instead of double (#1074)
  3. Decimal based quantities return decimal instead of double (Power, BitRate and Information) (#1074)

🔥 Removed

  1. Remove targets: net40, net47, Windows Runtime Component. Fix: Use netstandard2.0.
  2. Remove Undefined enum value for all unit enum types. Fix: Use null.
  3. Remove QuantityType enum. Fix: Use strings.
  4. Remove IQuantity.Units and .UnitNames. Fix: Use QuantityInfo.
  5. Remove IEquatable<T> and equality operators/methods. Fix: See TODO below.
  6. Remove GlobalConfiguration. Fix: Change CultureInfo.CurrentCulture.
  7. Remove Molarity ctor and operator overloads. Fix: Use MassConcentration.FromMolarity(), ToMolarity().
  8. Remove MinValue, MaxValue per quantity due to ambiguity. Fix: Define your own min/max quantity values.
  9. Remove string format specifiers: "v", "s". Fix: Use Value property and standard .NET numeric format strings.
  10. json: Remove UnitsNetJsonConverter. Fix: Use UnitsNetIQuantityJsonConverter or AbbreviatedUnitsConverter.

✨ New

  1. QuantityValue: Implement IEquality, IComparable, IFormattable
  2. QuantityValue: 16 bytes instead of 40 bytes (#1084)
  3. Add [DataContract] annotations (#972)

📝 JSON unit definition schema changes

Rename BaseType to ValueType, for values "double" and "decimal". Rename XmlDoc to XmlDocSummary.

TODO

Add back IEquatable<T>, but implement as strict equality with tuple of quantity name + unit + value. https://github.com/angularsen/UnitsNet/issues/1017#issuecomment-1028401955