Skip to content

Commit 3a67edc

Browse files
committed
WIP: Use UnitSystem.DefaultCulture in ToString()
As fallback if no culture was specified, instead of 'null' that falls back to the system default, which may be different if someone explicitly set a different value in UnitSystem.DefaultCulture. Expose DefaultCulture to WinRTC target as internal so we can apply same behavior there (can't be public in WinRTC).
1 parent 08abf98 commit 3a67edc

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

UnitsNet/CustomCode/UnitSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public UnitSystem() : this(DefaultCulture)
141141
/// </summary>
142142
#if WINDOWS_UWP
143143
// Windows Runtime Component does not support exposing the IFormatProvider type in public API
144-
private
144+
internal
145145
#else
146146
public
147147
#endif

UnitsNet/GeneratedCode/Quantities/Mass.g.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,11 +1326,11 @@ public string ToString(MassUnit unit, [CanBeNull] Culture culture, [NotNull] str
13261326
if (format == null) throw new ArgumentNullException(nameof(format));
13271327
if (args == null) throw new ArgumentNullException(nameof(args));
13281328

1329-
// Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
1329+
// Windows Runtime Component does not support CultureInfo or IFormatProvider types, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
13301330
#if WINDOWS_UWP
1331-
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
1331+
IFormatProvider formatProvider = culture == null ? UnitSystem.DefaultCulture : new CultureInfo(culture);
13321332
#else
1333-
IFormatProvider formatProvider = culture;
1333+
IFormatProvider formatProvider = culture ?? UnitSystem.DefaultCulture;
13341334
#endif
13351335
double value = As(unit);
13361336
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);

0 commit comments

Comments
 (0)