Skip to content

Commit c2881b4

Browse files
authored
Merge pull request #511 from tmilnthorp/UnitSystemSplit
Splitting UnitSystem class into more focused classes
2 parents 463c63c + b7523d2 commit c2881b4

File tree

381 files changed

+6260
-8928
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

381 files changed

+6260
-8928
lines changed

Common/GeneratedCode/Quantities/Acceleration.Common.g.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public static bool TryParseUnit(string str, out AccelerationUnit unit)
654654
/// Parse a string with one or two quantities of the format "<quantity> <unit>".
655655
/// </summary>
656656
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
657-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
657+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
658658
/// <example>
659659
/// Length.Parse("5.5 m", new CultureInfo("en-US"));
660660
/// </example>
@@ -677,17 +677,17 @@ private static Acceleration ParseInternal(string str, [CanBeNull] IFormatProvide
677677
{
678678
if (str == null) throw new ArgumentNullException(nameof(str));
679679

680-
provider = provider ?? UnitSystem.DefaultCulture;
680+
provider = provider ?? GlobalConfiguration.DefaultCulture;
681681

682-
return QuantityParser.Parse<Acceleration, AccelerationUnit>(str, provider, ParseUnitInternal, From,
682+
return QuantityParser.Default.Parse<Acceleration, AccelerationUnit>(str, provider, ParseUnitInternal, From,
683683
(x, y) => From(x.MetersPerSecondSquared + y.MetersPerSecondSquared, BaseUnit));
684684
}
685685

686686
/// <summary>
687687
/// Try to parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
688688
/// </summary>
689689
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
690-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
690+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
691691
/// <param name="result">Resulting unit quantity if successful.</param>
692692
/// <returns>True if successful, otherwise false.</returns>
693693
/// <example>
@@ -700,17 +700,17 @@ private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormat
700700
if(string.IsNullOrWhiteSpace(str))
701701
return false;
702702

703-
provider = provider ?? UnitSystem.DefaultCulture;
703+
provider = provider ?? GlobalConfiguration.DefaultCulture;
704704

705-
return QuantityParser.TryParse<Acceleration, AccelerationUnit>(str, provider, TryParseUnitInternal, From,
705+
return QuantityParser.Default.TryParse<Acceleration, AccelerationUnit>(str, provider, TryParseUnitInternal, From,
706706
(x, y) => From(x.MetersPerSecondSquared + y.MetersPerSecondSquared, BaseUnit), out result);
707707
}
708708

709709
/// <summary>
710710
/// Parse a unit string.
711711
/// </summary>
712712
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
713-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
713+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
714714
/// <example>
715715
/// Length.ParseUnit("m", new CultureInfo("en-US"));
716716
/// </example>
@@ -720,8 +720,7 @@ private static AccelerationUnit ParseUnitInternal(string str, IFormatProvider pr
720720
{
721721
if (str == null) throw new ArgumentNullException(nameof(str));
722722

723-
var unitSystem = UnitSystem.GetCached(provider);
724-
var unit = unitSystem.Parse<AccelerationUnit>(str.Trim());
723+
var unit = UnitParser.Default.Parse<AccelerationUnit>(str.Trim(), provider);
725724

726725
if (unit == AccelerationUnit.Undefined)
727726
{
@@ -738,7 +737,7 @@ private static AccelerationUnit ParseUnitInternal(string str, IFormatProvider pr
738737
/// Parse a unit string.
739738
/// </summary>
740739
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
741-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
740+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
742741
/// <param name="unit">The parsed unit if successful.</param>
743742
/// <returns>True if successful, otherwise false.</returns>
744743
/// <example>
@@ -751,8 +750,7 @@ private static bool TryParseUnitInternal(string str, IFormatProvider provider, o
751750
if(string.IsNullOrWhiteSpace(str))
752751
return false;
753752

754-
var unitSystem = UnitSystem.GetCached(provider);
755-
if(!unitSystem.TryParse<AccelerationUnit>(str.Trim(), out unit))
753+
if(!UnitParser.Default.TryParse<AccelerationUnit>(str.Trim(), provider, out unit))
756754
return false;
757755

758756
if(unit == AccelerationUnit.Undefined)

Common/GeneratedCode/Quantities/AmountOfSubstance.Common.g.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ public static bool TryParseUnit(string str, out AmountOfSubstanceUnit unit)
676676
/// Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
677677
/// </summary>
678678
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
679-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
679+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
680680
/// <example>
681681
/// Length.Parse("5.5 m", new CultureInfo("en-US"));
682682
/// </example>
@@ -699,17 +699,17 @@ private static AmountOfSubstance ParseInternal(string str, [CanBeNull] IFormatPr
699699
{
700700
if (str == null) throw new ArgumentNullException(nameof(str));
701701

702-
provider = provider ?? UnitSystem.DefaultCulture;
702+
provider = provider ?? GlobalConfiguration.DefaultCulture;
703703

704-
return QuantityParser.Parse<AmountOfSubstance, AmountOfSubstanceUnit>(str, provider, ParseUnitInternal, From,
704+
return QuantityParser.Default.Parse<AmountOfSubstance, AmountOfSubstanceUnit>(str, provider, ParseUnitInternal, From,
705705
(x, y) => From(x.Moles + y.Moles, BaseUnit));
706706
}
707707

708708
/// <summary>
709709
/// Try to parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
710710
/// </summary>
711711
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
712-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
712+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
713713
/// <param name="result">Resulting unit quantity if successful.</param>
714714
/// <returns>True if successful, otherwise false.</returns>
715715
/// <example>
@@ -722,17 +722,17 @@ private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormat
722722
if(string.IsNullOrWhiteSpace(str))
723723
return false;
724724

725-
provider = provider ?? UnitSystem.DefaultCulture;
725+
provider = provider ?? GlobalConfiguration.DefaultCulture;
726726

727-
return QuantityParser.TryParse<AmountOfSubstance, AmountOfSubstanceUnit>(str, provider, TryParseUnitInternal, From,
727+
return QuantityParser.Default.TryParse<AmountOfSubstance, AmountOfSubstanceUnit>(str, provider, TryParseUnitInternal, From,
728728
(x, y) => From(x.Moles + y.Moles, BaseUnit), out result);
729729
}
730730

731731
/// <summary>
732732
/// Parse a unit string.
733733
/// </summary>
734734
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
735-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
735+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
736736
/// <example>
737737
/// Length.ParseUnit("m", new CultureInfo("en-US"));
738738
/// </example>
@@ -742,8 +742,7 @@ private static AmountOfSubstanceUnit ParseUnitInternal(string str, IFormatProvid
742742
{
743743
if (str == null) throw new ArgumentNullException(nameof(str));
744744

745-
var unitSystem = UnitSystem.GetCached(provider);
746-
var unit = unitSystem.Parse<AmountOfSubstanceUnit>(str.Trim());
745+
var unit = UnitParser.Default.Parse<AmountOfSubstanceUnit>(str.Trim(), provider);
747746

748747
if (unit == AmountOfSubstanceUnit.Undefined)
749748
{
@@ -760,7 +759,7 @@ private static AmountOfSubstanceUnit ParseUnitInternal(string str, IFormatProvid
760759
/// Parse a unit string.
761760
/// </summary>
762761
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
763-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
762+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
764763
/// <param name="unit">The parsed unit if successful.</param>
765764
/// <returns>True if successful, otherwise false.</returns>
766765
/// <example>
@@ -773,8 +772,7 @@ private static bool TryParseUnitInternal(string str, IFormatProvider provider, o
773772
if(string.IsNullOrWhiteSpace(str))
774773
return false;
775774

776-
var unitSystem = UnitSystem.GetCached(provider);
777-
if(!unitSystem.TryParse<AmountOfSubstanceUnit>(str.Trim(), out unit))
775+
if(!UnitParser.Default.TryParse<AmountOfSubstanceUnit>(str.Trim(), provider, out unit))
778776
return false;
779777

780778
if(unit == AmountOfSubstanceUnit.Undefined)

Common/GeneratedCode/Quantities/AmplitudeRatio.Common.g.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public static bool TryParseUnit(string str, out AmplitudeRatioUnit unit)
455455
/// Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
456456
/// </summary>
457457
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
458-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
458+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
459459
/// <example>
460460
/// Length.Parse("5.5 m", new CultureInfo("en-US"));
461461
/// </example>
@@ -478,17 +478,17 @@ private static AmplitudeRatio ParseInternal(string str, [CanBeNull] IFormatProvi
478478
{
479479
if (str == null) throw new ArgumentNullException(nameof(str));
480480

481-
provider = provider ?? UnitSystem.DefaultCulture;
481+
provider = provider ?? GlobalConfiguration.DefaultCulture;
482482

483-
return QuantityParser.Parse<AmplitudeRatio, AmplitudeRatioUnit>(str, provider, ParseUnitInternal, From,
483+
return QuantityParser.Default.Parse<AmplitudeRatio, AmplitudeRatioUnit>(str, provider, ParseUnitInternal, From,
484484
(x, y) => From(x.DecibelVolts + y.DecibelVolts, BaseUnit));
485485
}
486486

487487
/// <summary>
488488
/// Try to parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
489489
/// </summary>
490490
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
491-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
491+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
492492
/// <param name="result">Resulting unit quantity if successful.</param>
493493
/// <returns>True if successful, otherwise false.</returns>
494494
/// <example>
@@ -501,17 +501,17 @@ private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormat
501501
if(string.IsNullOrWhiteSpace(str))
502502
return false;
503503

504-
provider = provider ?? UnitSystem.DefaultCulture;
504+
provider = provider ?? GlobalConfiguration.DefaultCulture;
505505

506-
return QuantityParser.TryParse<AmplitudeRatio, AmplitudeRatioUnit>(str, provider, TryParseUnitInternal, From,
506+
return QuantityParser.Default.TryParse<AmplitudeRatio, AmplitudeRatioUnit>(str, provider, TryParseUnitInternal, From,
507507
(x, y) => From(x.DecibelVolts + y.DecibelVolts, BaseUnit), out result);
508508
}
509509

510510
/// <summary>
511511
/// Parse a unit string.
512512
/// </summary>
513513
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
514-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
514+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
515515
/// <example>
516516
/// Length.ParseUnit("m", new CultureInfo("en-US"));
517517
/// </example>
@@ -521,8 +521,7 @@ private static AmplitudeRatioUnit ParseUnitInternal(string str, IFormatProvider
521521
{
522522
if (str == null) throw new ArgumentNullException(nameof(str));
523523

524-
var unitSystem = UnitSystem.GetCached(provider);
525-
var unit = unitSystem.Parse<AmplitudeRatioUnit>(str.Trim());
524+
var unit = UnitParser.Default.Parse<AmplitudeRatioUnit>(str.Trim(), provider);
526525

527526
if (unit == AmplitudeRatioUnit.Undefined)
528527
{
@@ -539,7 +538,7 @@ private static AmplitudeRatioUnit ParseUnitInternal(string str, IFormatProvider
539538
/// Parse a unit string.
540539
/// </summary>
541540
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
542-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
541+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
543542
/// <param name="unit">The parsed unit if successful.</param>
544543
/// <returns>True if successful, otherwise false.</returns>
545544
/// <example>
@@ -552,8 +551,7 @@ private static bool TryParseUnitInternal(string str, IFormatProvider provider, o
552551
if(string.IsNullOrWhiteSpace(str))
553552
return false;
554553

555-
var unitSystem = UnitSystem.GetCached(provider);
556-
if(!unitSystem.TryParse<AmplitudeRatioUnit>(str.Trim(), out unit))
554+
if(!UnitParser.Default.TryParse<AmplitudeRatioUnit>(str.Trim(), provider, out unit))
557555
return false;
558556

559557
if(unit == AmplitudeRatioUnit.Undefined)

Common/GeneratedCode/Quantities/Angle.Common.g.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public static bool TryParseUnit(string str, out AngleUnit unit)
675675
/// Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
676676
/// </summary>
677677
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
678-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
678+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
679679
/// <example>
680680
/// Length.Parse("5.5 m", new CultureInfo("en-US"));
681681
/// </example>
@@ -698,17 +698,17 @@ private static Angle ParseInternal(string str, [CanBeNull] IFormatProvider provi
698698
{
699699
if (str == null) throw new ArgumentNullException(nameof(str));
700700

701-
provider = provider ?? UnitSystem.DefaultCulture;
701+
provider = provider ?? GlobalConfiguration.DefaultCulture;
702702

703-
return QuantityParser.Parse<Angle, AngleUnit>(str, provider, ParseUnitInternal, From,
703+
return QuantityParser.Default.Parse<Angle, AngleUnit>(str, provider, ParseUnitInternal, From,
704704
(x, y) => From(x.Degrees + y.Degrees, BaseUnit));
705705
}
706706

707707
/// <summary>
708708
/// Try to parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
709709
/// </summary>
710710
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
711-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
711+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
712712
/// <param name="result">Resulting unit quantity if successful.</param>
713713
/// <returns>True if successful, otherwise false.</returns>
714714
/// <example>
@@ -721,17 +721,17 @@ private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormat
721721
if(string.IsNullOrWhiteSpace(str))
722722
return false;
723723

724-
provider = provider ?? UnitSystem.DefaultCulture;
724+
provider = provider ?? GlobalConfiguration.DefaultCulture;
725725

726-
return QuantityParser.TryParse<Angle, AngleUnit>(str, provider, TryParseUnitInternal, From,
726+
return QuantityParser.Default.TryParse<Angle, AngleUnit>(str, provider, TryParseUnitInternal, From,
727727
(x, y) => From(x.Degrees + y.Degrees, BaseUnit), out result);
728728
}
729729

730730
/// <summary>
731731
/// Parse a unit string.
732732
/// </summary>
733733
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
734-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
734+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
735735
/// <example>
736736
/// Length.ParseUnit("m", new CultureInfo("en-US"));
737737
/// </example>
@@ -741,8 +741,7 @@ private static AngleUnit ParseUnitInternal(string str, IFormatProvider provider
741741
{
742742
if (str == null) throw new ArgumentNullException(nameof(str));
743743

744-
var unitSystem = UnitSystem.GetCached(provider);
745-
var unit = unitSystem.Parse<AngleUnit>(str.Trim());
744+
var unit = UnitParser.Default.Parse<AngleUnit>(str.Trim(), provider);
746745

747746
if (unit == AngleUnit.Undefined)
748747
{
@@ -759,7 +758,7 @@ private static AngleUnit ParseUnitInternal(string str, IFormatProvider provider
759758
/// Parse a unit string.
760759
/// </summary>
761760
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
762-
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
761+
/// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" />.</param>
763762
/// <param name="unit">The parsed unit if successful.</param>
764763
/// <returns>True if successful, otherwise false.</returns>
765764
/// <example>
@@ -772,8 +771,7 @@ private static bool TryParseUnitInternal(string str, IFormatProvider provider, o
772771
if(string.IsNullOrWhiteSpace(str))
773772
return false;
774773

775-
var unitSystem = UnitSystem.GetCached(provider);
776-
if(!unitSystem.TryParse<AngleUnit>(str.Trim(), out unit))
774+
if(!UnitParser.Default.TryParse<AngleUnit>(str.Trim(), provider, out unit))
777775
return false;
778776

779777
if(unit == AngleUnit.Undefined)

0 commit comments

Comments
 (0)