Skip to content

Commit 4a075d0

Browse files
committed
Fix NRE and bad ToString() result in UWP
1 parent 19071ff commit 4a075d0

36 files changed

+246
-246
lines changed

UnitsNet/GeneratedCode/UnitClasses/Acceleration.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ public static Acceleration Parse(string str, [CanBeNull] Culture culture)
614614
if (str == null) throw new ArgumentNullException("str");
615615

616616
#if WINDOWS_UWP
617-
IFormatProvider formatProvider = new CultureInfo(culture);
617+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
618618
#else
619619
IFormatProvider formatProvider = culture;
620620
#endif
@@ -705,7 +705,7 @@ private static List<Acceleration> ParseWithRegex(string regexString, string str,
705705
/// <exception cref="UnitsNetException">Error parsing string.</exception>
706706
public static AccelerationUnit ParseUnit(string str)
707707
{
708-
return ParseUnit(str, (CultureInfo)null);
708+
return ParseUnit(str, (IFormatProvider)null);
709709
}
710710

711711
/// <summary>
@@ -718,7 +718,7 @@ public static AccelerationUnit ParseUnit(string str)
718718
/// <exception cref="UnitsNetException">Error parsing string.</exception>
719719
public static AccelerationUnit ParseUnit(string str, [CanBeNull] string cultureName)
720720
{
721-
return ParseUnit(str, new CultureInfo(cultureName));
721+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
722722
}
723723

724724
/// <summary>
@@ -820,13 +820,13 @@ public string ToString(AccelerationUnit unit, [CanBeNull] Culture culture, [NotN
820820
if (args == null) throw new ArgumentNullException(nameof(args));
821821

822822
#if WINDOWS_UWP
823-
var cultureInfo = new CultureInfo(culture);
823+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
824824
#else
825-
IFormatProvider cultureInfo = culture;
825+
IFormatProvider formatProvider = culture;
826826
#endif
827827
double value = As(unit);
828-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
829-
return string.Format(culture, format, formatArgs);
828+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
829+
return string.Format(formatProvider, format, formatArgs);
830830
}
831831
}
832832
}

UnitsNet/GeneratedCode/UnitClasses/AmplitudeRatio.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public static AmplitudeRatio Parse(string str, [CanBeNull] Culture culture)
474474
if (str == null) throw new ArgumentNullException("str");
475475

476476
#if WINDOWS_UWP
477-
IFormatProvider formatProvider = new CultureInfo(culture);
477+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
478478
#else
479479
IFormatProvider formatProvider = culture;
480480
#endif
@@ -565,7 +565,7 @@ private static List<AmplitudeRatio> ParseWithRegex(string regexString, string st
565565
/// <exception cref="UnitsNetException">Error parsing string.</exception>
566566
public static AmplitudeRatioUnit ParseUnit(string str)
567567
{
568-
return ParseUnit(str, (CultureInfo)null);
568+
return ParseUnit(str, (IFormatProvider)null);
569569
}
570570

571571
/// <summary>
@@ -578,7 +578,7 @@ public static AmplitudeRatioUnit ParseUnit(string str)
578578
/// <exception cref="UnitsNetException">Error parsing string.</exception>
579579
public static AmplitudeRatioUnit ParseUnit(string str, [CanBeNull] string cultureName)
580580
{
581-
return ParseUnit(str, new CultureInfo(cultureName));
581+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
582582
}
583583

584584
/// <summary>
@@ -680,13 +680,13 @@ public string ToString(AmplitudeRatioUnit unit, [CanBeNull] Culture culture, [No
680680
if (args == null) throw new ArgumentNullException(nameof(args));
681681

682682
#if WINDOWS_UWP
683-
var cultureInfo = new CultureInfo(culture);
683+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
684684
#else
685-
IFormatProvider cultureInfo = culture;
685+
IFormatProvider formatProvider = culture;
686686
#endif
687687
double value = As(unit);
688-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
689-
return string.Format(culture, format, formatArgs);
688+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
689+
return string.Format(formatProvider, format, formatArgs);
690690
}
691691
}
692692
}

UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ public static Angle Parse(string str, [CanBeNull] Culture culture)
836836
if (str == null) throw new ArgumentNullException("str");
837837

838838
#if WINDOWS_UWP
839-
IFormatProvider formatProvider = new CultureInfo(culture);
839+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
840840
#else
841841
IFormatProvider formatProvider = culture;
842842
#endif
@@ -927,7 +927,7 @@ private static List<Angle> ParseWithRegex(string regexString, string str, IForma
927927
/// <exception cref="UnitsNetException">Error parsing string.</exception>
928928
public static AngleUnit ParseUnit(string str)
929929
{
930-
return ParseUnit(str, (CultureInfo)null);
930+
return ParseUnit(str, (IFormatProvider)null);
931931
}
932932

933933
/// <summary>
@@ -940,7 +940,7 @@ public static AngleUnit ParseUnit(string str)
940940
/// <exception cref="UnitsNetException">Error parsing string.</exception>
941941
public static AngleUnit ParseUnit(string str, [CanBeNull] string cultureName)
942942
{
943-
return ParseUnit(str, new CultureInfo(cultureName));
943+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
944944
}
945945

946946
/// <summary>
@@ -1042,13 +1042,13 @@ public string ToString(AngleUnit unit, [CanBeNull] Culture culture, [NotNull] st
10421042
if (args == null) throw new ArgumentNullException(nameof(args));
10431043

10441044
#if WINDOWS_UWP
1045-
var cultureInfo = new CultureInfo(culture);
1045+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
10461046
#else
1047-
IFormatProvider cultureInfo = culture;
1047+
IFormatProvider formatProvider = culture;
10481048
#endif
10491049
double value = As(unit);
1050-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
1051-
return string.Format(culture, format, formatArgs);
1050+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
1051+
return string.Format(formatProvider, format, formatArgs);
10521052
}
10531053
}
10541054
}

UnitsNet/GeneratedCode/UnitClasses/Area.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ public static Area Parse(string str, [CanBeNull] Culture culture)
725725
if (str == null) throw new ArgumentNullException("str");
726726

727727
#if WINDOWS_UWP
728-
IFormatProvider formatProvider = new CultureInfo(culture);
728+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
729729
#else
730730
IFormatProvider formatProvider = culture;
731731
#endif
@@ -816,7 +816,7 @@ private static List<Area> ParseWithRegex(string regexString, string str, IFormat
816816
/// <exception cref="UnitsNetException">Error parsing string.</exception>
817817
public static AreaUnit ParseUnit(string str)
818818
{
819-
return ParseUnit(str, (CultureInfo)null);
819+
return ParseUnit(str, (IFormatProvider)null);
820820
}
821821

822822
/// <summary>
@@ -829,7 +829,7 @@ public static AreaUnit ParseUnit(string str)
829829
/// <exception cref="UnitsNetException">Error parsing string.</exception>
830830
public static AreaUnit ParseUnit(string str, [CanBeNull] string cultureName)
831831
{
832-
return ParseUnit(str, new CultureInfo(cultureName));
832+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
833833
}
834834

835835
/// <summary>
@@ -931,13 +931,13 @@ public string ToString(AreaUnit unit, [CanBeNull] Culture culture, [NotNull] str
931931
if (args == null) throw new ArgumentNullException(nameof(args));
932932

933933
#if WINDOWS_UWP
934-
var cultureInfo = new CultureInfo(culture);
934+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
935935
#else
936-
IFormatProvider cultureInfo = culture;
936+
IFormatProvider formatProvider = culture;
937937
#endif
938938
double value = As(unit);
939-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
940-
return string.Format(culture, format, formatArgs);
939+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
940+
return string.Format(formatProvider, format, formatArgs);
941941
}
942942
}
943943
}

UnitsNet/GeneratedCode/UnitClasses/Density.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ public static Density Parse(string str, [CanBeNull] Culture culture)
725725
if (str == null) throw new ArgumentNullException("str");
726726

727727
#if WINDOWS_UWP
728-
IFormatProvider formatProvider = new CultureInfo(culture);
728+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
729729
#else
730730
IFormatProvider formatProvider = culture;
731731
#endif
@@ -816,7 +816,7 @@ private static List<Density> ParseWithRegex(string regexString, string str, IFor
816816
/// <exception cref="UnitsNetException">Error parsing string.</exception>
817817
public static DensityUnit ParseUnit(string str)
818818
{
819-
return ParseUnit(str, (CultureInfo)null);
819+
return ParseUnit(str, (IFormatProvider)null);
820820
}
821821

822822
/// <summary>
@@ -829,7 +829,7 @@ public static DensityUnit ParseUnit(string str)
829829
/// <exception cref="UnitsNetException">Error parsing string.</exception>
830830
public static DensityUnit ParseUnit(string str, [CanBeNull] string cultureName)
831831
{
832-
return ParseUnit(str, new CultureInfo(cultureName));
832+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
833833
}
834834

835835
/// <summary>
@@ -931,13 +931,13 @@ public string ToString(DensityUnit unit, [CanBeNull] Culture culture, [NotNull]
931931
if (args == null) throw new ArgumentNullException(nameof(args));
932932

933933
#if WINDOWS_UWP
934-
var cultureInfo = new CultureInfo(culture);
934+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
935935
#else
936-
IFormatProvider cultureInfo = culture;
936+
IFormatProvider formatProvider = culture;
937937
#endif
938938
double value = As(unit);
939-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
940-
return string.Format(culture, format, formatArgs);
939+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
940+
return string.Format(formatProvider, format, formatArgs);
941941
}
942942
}
943943
}

UnitsNet/GeneratedCode/UnitClasses/Duration.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ public static Duration Parse(string str, [CanBeNull] Culture culture)
725725
if (str == null) throw new ArgumentNullException("str");
726726

727727
#if WINDOWS_UWP
728-
IFormatProvider formatProvider = new CultureInfo(culture);
728+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
729729
#else
730730
IFormatProvider formatProvider = culture;
731731
#endif
@@ -816,7 +816,7 @@ private static List<Duration> ParseWithRegex(string regexString, string str, IFo
816816
/// <exception cref="UnitsNetException">Error parsing string.</exception>
817817
public static DurationUnit ParseUnit(string str)
818818
{
819-
return ParseUnit(str, (CultureInfo)null);
819+
return ParseUnit(str, (IFormatProvider)null);
820820
}
821821

822822
/// <summary>
@@ -829,7 +829,7 @@ public static DurationUnit ParseUnit(string str)
829829
/// <exception cref="UnitsNetException">Error parsing string.</exception>
830830
public static DurationUnit ParseUnit(string str, [CanBeNull] string cultureName)
831831
{
832-
return ParseUnit(str, new CultureInfo(cultureName));
832+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
833833
}
834834

835835
/// <summary>
@@ -931,13 +931,13 @@ public string ToString(DurationUnit unit, [CanBeNull] Culture culture, [NotNull]
931931
if (args == null) throw new ArgumentNullException(nameof(args));
932932

933933
#if WINDOWS_UWP
934-
var cultureInfo = new CultureInfo(culture);
934+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
935935
#else
936-
IFormatProvider cultureInfo = culture;
936+
IFormatProvider formatProvider = culture;
937937
#endif
938938
double value = As(unit);
939-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
940-
return string.Format(culture, format, formatArgs);
939+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
940+
return string.Format(formatProvider, format, formatArgs);
941941
}
942942
}
943943
}

UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ public static DynamicViscosity Parse(string str, [CanBeNull] Culture culture)
540540
if (str == null) throw new ArgumentNullException("str");
541541

542542
#if WINDOWS_UWP
543-
IFormatProvider formatProvider = new CultureInfo(culture);
543+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
544544
#else
545545
IFormatProvider formatProvider = culture;
546546
#endif
@@ -631,7 +631,7 @@ private static List<DynamicViscosity> ParseWithRegex(string regexString, string
631631
/// <exception cref="UnitsNetException">Error parsing string.</exception>
632632
public static DynamicViscosityUnit ParseUnit(string str)
633633
{
634-
return ParseUnit(str, (CultureInfo)null);
634+
return ParseUnit(str, (IFormatProvider)null);
635635
}
636636

637637
/// <summary>
@@ -644,7 +644,7 @@ public static DynamicViscosityUnit ParseUnit(string str)
644644
/// <exception cref="UnitsNetException">Error parsing string.</exception>
645645
public static DynamicViscosityUnit ParseUnit(string str, [CanBeNull] string cultureName)
646646
{
647-
return ParseUnit(str, new CultureInfo(cultureName));
647+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
648648
}
649649

650650
/// <summary>
@@ -746,13 +746,13 @@ public string ToString(DynamicViscosityUnit unit, [CanBeNull] Culture culture, [
746746
if (args == null) throw new ArgumentNullException(nameof(args));
747747

748748
#if WINDOWS_UWP
749-
var cultureInfo = new CultureInfo(culture);
749+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
750750
#else
751-
IFormatProvider cultureInfo = culture;
751+
IFormatProvider formatProvider = culture;
752752
#endif
753753
double value = As(unit);
754-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
755-
return string.Format(culture, format, formatArgs);
754+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
755+
return string.Format(formatProvider, format, formatArgs);
756756
}
757757
}
758758
}

UnitsNet/GeneratedCode/UnitClasses/ElectricCurrent.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public static ElectricCurrent Parse(string str, [CanBeNull] Culture culture)
577577
if (str == null) throw new ArgumentNullException("str");
578578

579579
#if WINDOWS_UWP
580-
IFormatProvider formatProvider = new CultureInfo(culture);
580+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
581581
#else
582582
IFormatProvider formatProvider = culture;
583583
#endif
@@ -668,7 +668,7 @@ private static List<ElectricCurrent> ParseWithRegex(string regexString, string s
668668
/// <exception cref="UnitsNetException">Error parsing string.</exception>
669669
public static ElectricCurrentUnit ParseUnit(string str)
670670
{
671-
return ParseUnit(str, (CultureInfo)null);
671+
return ParseUnit(str, (IFormatProvider)null);
672672
}
673673

674674
/// <summary>
@@ -681,7 +681,7 @@ public static ElectricCurrentUnit ParseUnit(string str)
681681
/// <exception cref="UnitsNetException">Error parsing string.</exception>
682682
public static ElectricCurrentUnit ParseUnit(string str, [CanBeNull] string cultureName)
683683
{
684-
return ParseUnit(str, new CultureInfo(cultureName));
684+
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
685685
}
686686

687687
/// <summary>
@@ -783,13 +783,13 @@ public string ToString(ElectricCurrentUnit unit, [CanBeNull] Culture culture, [N
783783
if (args == null) throw new ArgumentNullException(nameof(args));
784784

785785
#if WINDOWS_UWP
786-
var cultureInfo = new CultureInfo(culture);
786+
IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
787787
#else
788-
IFormatProvider cultureInfo = culture;
788+
IFormatProvider formatProvider = culture;
789789
#endif
790790
double value = As(unit);
791-
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, cultureInfo, args);
792-
return string.Format(culture, format, formatArgs);
791+
object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
792+
return string.Format(formatProvider, format, formatArgs);
793793
}
794794
}
795795
}

0 commit comments

Comments
 (0)