From e11ad1b736bb6d34eeb115c1ca2961b8089169fe Mon Sep 17 00:00:00 2001 From: Erik Ovegard Date: Thu, 24 Aug 2017 22:12:08 +0200 Subject: [PATCH 1/3] Proof of concept --- .../OverloadGeneratorTests.cs | 29 +++++++++++ .../QuantityTests.cs | 28 +++++++++++ .../UnitsNet.OperatorOverloads.Tests.csproj | 16 ++++++ UnitsNet.OperatorOverloads/ArrayExtensions.cs | 49 +++++++++++++++++++ .../OverloadGenerator.cs | 35 +++++++++++++ UnitsNet.OperatorOverloads/Quantity.cs | 39 +++++++++++++++ .../UnitsNet.OperatorOverloads.csproj | 8 +++ 7 files changed, 204 insertions(+) create mode 100644 UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs create mode 100644 UnitsNet.OperatorOverloads.Tests/QuantityTests.cs create mode 100644 UnitsNet.OperatorOverloads.Tests/UnitsNet.OperatorOverloads.Tests.csproj create mode 100644 UnitsNet.OperatorOverloads/ArrayExtensions.cs create mode 100644 UnitsNet.OperatorOverloads/OverloadGenerator.cs create mode 100644 UnitsNet.OperatorOverloads/Quantity.cs create mode 100644 UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj diff --git a/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs b/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs new file mode 100644 index 0000000000..7ad36e5cb7 --- /dev/null +++ b/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs @@ -0,0 +1,29 @@ +using System.IO; +using System.Linq; +using Newtonsoft.Json; +using Xunit; + +namespace UnitsNet.OperatorOverloads.Tests +{ + public static class OverloadGeneratorTests + { + [Fact] + public static void ShouldReturnDivisionAndSpeedWhenGivenLength() + { + var lengthQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Length.json")); + lengthQuantity.SiArray = new[] {1, 0, 0, 0, 0, 0, 0}; + var timeQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Duration.json")); + timeQuantity.SiArray = new[] { 0, 0, 1, 0, 0, 0, 0 }; + var speedQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Speed.json")); + speedQuantity.SiArray = new[] { 1, 0, -1, 0, 0, 0, 0 }; + + var overloadGenerator = new OverloadGenerator(new[] {lengthQuantity, timeQuantity, speedQuantity}); + var actualQuantities = overloadGenerator.GetDivisionOverloads(lengthQuantity).ToArray(); + var actualQuantityNames = actualQuantities.Select(x => x.Name).ToArray(); + Assert.Equal(2,actualQuantities.Length); + + Assert.Contains(speedQuantity.Name, actualQuantityNames); + Assert.Contains(timeQuantity.Name, actualQuantityNames); + } + } +} diff --git a/UnitsNet.OperatorOverloads.Tests/QuantityTests.cs b/UnitsNet.OperatorOverloads.Tests/QuantityTests.cs new file mode 100644 index 0000000000..24f36c98ab --- /dev/null +++ b/UnitsNet.OperatorOverloads.Tests/QuantityTests.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; +using Xunit; + +namespace UnitsNet.OperatorOverloads.Tests +{ + public class QuantityTests + { + [Theory] + [MemberData(nameof(GetJsonFiles))] + public static void ShouldNotThrowWhenDeserializingUnits(string filename) + { + var quantity = JsonConvert.DeserializeObject(File.ReadAllText(filename)); + Assert.NotNull(quantity); + } + + public static IEnumerable GetJsonFiles() + { + var files = Directory.EnumerateFiles(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions", "*.json"); + foreach (string file in files) + { + yield return new object[] {file}; + } + } + } +} diff --git a/UnitsNet.OperatorOverloads.Tests/UnitsNet.OperatorOverloads.Tests.csproj b/UnitsNet.OperatorOverloads.Tests/UnitsNet.OperatorOverloads.Tests.csproj new file mode 100644 index 0000000000..4a3fbc0d65 --- /dev/null +++ b/UnitsNet.OperatorOverloads.Tests/UnitsNet.OperatorOverloads.Tests.csproj @@ -0,0 +1,16 @@ + + + net46 + + + + + + + + + + + + + \ No newline at end of file diff --git a/UnitsNet.OperatorOverloads/ArrayExtensions.cs b/UnitsNet.OperatorOverloads/ArrayExtensions.cs new file mode 100644 index 0000000000..17fd834d40 --- /dev/null +++ b/UnitsNet.OperatorOverloads/ArrayExtensions.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UnitsNet.OperatorOverloads +{ + public static class ArrayExtensions + { + public static int[] ElementwiseSubtract(this int[] left, int[] right) + { + if (left.Length != right.Length) + { + throw new ArgumentException("Arrays must have the same length"); + } + var result = new int[left.Length]; + for (int i = 0; i < result.Length; i++) + { + result[i] = left[i] - right[i]; + } + return result; + } + + public static bool EqualContent(this T[] left, T[] right) + { + if (left == default(T[])) + { + throw new ArgumentNullException(nameof(left)); + } + if (right == default(T[])) + { + return false; + } + if (left.Length != right.Length) + { + return false; + } + for (int i = 0; i < left.Length; i++) + { + if (!left[i].Equals(right[i])) + { + return false; + } + } + return true; + } + } +} diff --git a/UnitsNet.OperatorOverloads/OverloadGenerator.cs b/UnitsNet.OperatorOverloads/OverloadGenerator.cs new file mode 100644 index 0000000000..8088d7f7f3 --- /dev/null +++ b/UnitsNet.OperatorOverloads/OverloadGenerator.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UnitsNet.OperatorOverloads +{ + public class OverloadGenerator + { + private readonly Quantity[] _quantities; + + public OverloadGenerator(Quantity[] quantities) + { + _quantities = quantities; + } + + public IEnumerable GetDivisionOverloads(Quantity quantity) + { + foreach (Quantity q in _quantities) + { + if (!quantity.Name.Equals(q.Name,StringComparison.OrdinalIgnoreCase)) + { + var newSiArray = quantity.SiArray.ElementwiseSubtract(q.SiArray); + + Quantity matchingQuantity = _quantities.SingleOrDefault(x => x.SiArray.EqualContent(newSiArray)); + if (matchingQuantity != null) + { + yield return matchingQuantity; + } + } + } + } + } +} diff --git a/UnitsNet.OperatorOverloads/Quantity.cs b/UnitsNet.OperatorOverloads/Quantity.cs new file mode 100644 index 0000000000..38f816cc4d --- /dev/null +++ b/UnitsNet.OperatorOverloads/Quantity.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + + +namespace UnitsNet.OperatorOverloads +{ + public class Localization + { + public string Culture { get; set; } + public List Abbreviations { get; set; } + } + + public class Unit + { + public string SingularName { get; set; } + public string PluralName { get; set; } + public string FromUnitToBaseFunc { get; set; } + public string FromBaseToUnitFunc { get; set; } + public List Localization { get; set; } + } + + public class Quantity + { + public string Name { get; set; } + public string BaseUnit { get; set; } + public string XmlDoc { get; set; } + public List Units { get; set; } + + /// + /// m kg s A K mol cd + /// + public int[] SiArray { get; set; } + + public override string ToString() + { + return Name; + } + } +} diff --git a/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj b/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj new file mode 100644 index 0000000000..9ebbcac719 --- /dev/null +++ b/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj @@ -0,0 +1,8 @@ + + + net46 + + + + + \ No newline at end of file From 9f0407b73e6bc6566068c845ce37e3530d26f2c4 Mon Sep 17 00:00:00 2001 From: Erik Ovegard Date: Thu, 7 Sep 2017 20:31:07 +0200 Subject: [PATCH 2/3] Introduced Overload type and multiplication --- .../OverloadGeneratorTests.cs | 27 +++++++++-- UnitsNet.OperatorOverloads/ArrayExtensions.cs | 15 +++++++ .../OverloadGenerator.cs | 36 ++++++++++++++- UnitsNet.sln | 45 +++++++++++++++++-- 4 files changed, 115 insertions(+), 8 deletions(-) diff --git a/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs b/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs index 7ad36e5cb7..b0b14a04e0 100644 --- a/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs +++ b/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs @@ -8,22 +8,43 @@ namespace UnitsNet.OperatorOverloads.Tests public static class OverloadGeneratorTests { [Fact] - public static void ShouldReturnDivisionAndSpeedWhenGivenLength() + public static void ShouldReturnDurationAndSpeedWhenGivenLength() { var lengthQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Length.json")); lengthQuantity.SiArray = new[] {1, 0, 0, 0, 0, 0, 0}; + string neobj = JsonConvert.SerializeObject(lengthQuantity, new JsonSerializerSettings() + { + Formatting = Formatting.Indented + }); var timeQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Duration.json")); timeQuantity.SiArray = new[] { 0, 0, 1, 0, 0, 0, 0 }; var speedQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Speed.json")); speedQuantity.SiArray = new[] { 1, 0, -1, 0, 0, 0, 0 }; var overloadGenerator = new OverloadGenerator(new[] {lengthQuantity, timeQuantity, speedQuantity}); - var actualQuantities = overloadGenerator.GetDivisionOverloads(lengthQuantity).ToArray(); - var actualQuantityNames = actualQuantities.Select(x => x.Name).ToArray(); + Overload[] actualQuantities = overloadGenerator.GetDivisionOverloads(lengthQuantity).ToArray(); + string[] actualQuantityNames = actualQuantities.Select(x => x.Result.Name).ToArray(); Assert.Equal(2,actualQuantities.Length); Assert.Contains(speedQuantity.Name, actualQuantityNames); Assert.Contains(timeQuantity.Name, actualQuantityNames); } + + [Fact] + public static void ShouldReturnLengthWhenGivenSpeed() + { + var lengthQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Length.json")); + lengthQuantity.SiArray = new[] { 1, 0, 0, 0, 0, 0, 0 }; + var timeQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Duration.json")); + timeQuantity.SiArray = new[] { 0, 0, 1, 0, 0, 0, 0 }; + var speedQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Speed.json")); + speedQuantity.SiArray = new[] { 1, 0, -1, 0, 0, 0, 0 }; + + var overloadGenerator = new OverloadGenerator(new[] { lengthQuantity, timeQuantity, speedQuantity }); + Overload[] actualQuantities = overloadGenerator.GetMultiplicationOverloads(speedQuantity).ToArray(); + var actualQuantityNames = actualQuantities.Select(x => x.Result.Name).ToArray(); + Assert.Equal(1, actualQuantities.Length); + Assert.Contains(lengthQuantity.Name, actualQuantityNames); + } } } diff --git a/UnitsNet.OperatorOverloads/ArrayExtensions.cs b/UnitsNet.OperatorOverloads/ArrayExtensions.cs index 17fd834d40..5cb1b85312 100644 --- a/UnitsNet.OperatorOverloads/ArrayExtensions.cs +++ b/UnitsNet.OperatorOverloads/ArrayExtensions.cs @@ -22,6 +22,21 @@ public static int[] ElementwiseSubtract(this int[] left, int[] right) return result; } + public static int[] ElementwiseAdd(this int[] left, int[] right) + { + if (left.Length != right.Length) + { + throw new ArgumentException("Arrays must have the same length"); + } + var result = new int[left.Length]; + for (int i = 0; i < result.Length; i++) + { + result[i] = left[i] + right[i]; + } + return result; + } + + public static bool EqualContent(this T[] left, T[] right) { if (left == default(T[])) diff --git a/UnitsNet.OperatorOverloads/OverloadGenerator.cs b/UnitsNet.OperatorOverloads/OverloadGenerator.cs index 8088d7f7f3..0b133e6cdd 100644 --- a/UnitsNet.OperatorOverloads/OverloadGenerator.cs +++ b/UnitsNet.OperatorOverloads/OverloadGenerator.cs @@ -15,7 +15,7 @@ public OverloadGenerator(Quantity[] quantities) _quantities = quantities; } - public IEnumerable GetDivisionOverloads(Quantity quantity) + public IEnumerable GetDivisionOverloads(Quantity quantity) { foreach (Quantity q in _quantities) { @@ -26,10 +26,42 @@ public IEnumerable GetDivisionOverloads(Quantity quantity) Quantity matchingQuantity = _quantities.SingleOrDefault(x => x.SiArray.EqualContent(newSiArray)); if (matchingQuantity != null) { - yield return matchingQuantity; + yield return new Overload(matchingQuantity, q, quantity); } } } } + + public IEnumerable GetMultiplicationOverloads(Quantity quantity) + { + foreach (Quantity q in _quantities) + { + if (!quantity.Name.Equals(q.Name, StringComparison.OrdinalIgnoreCase)) + { + var newSiArray = quantity.SiArray.ElementwiseAdd(q.SiArray); + + Quantity matchingQuantity = _quantities.SingleOrDefault(x => x.SiArray.EqualContent(newSiArray)); + if (matchingQuantity != null) + { + yield return new Overload(matchingQuantity, q, quantity); + } + } + } + } + + public IEnumerable GetOverloads(Quantity quantity) + { + var multiplications = GetMultiplicationOverloads(quantity); + foreach (var multiplication in multiplications) + { + yield return multiplication; + yield return new Overload(multiplication.Result, multiplication.Right, multiplication.Left); + } + var divisions = GetDivisionOverloads(quantity); + foreach (var division in divisions) + { + yield return division; + } + } } } diff --git a/UnitsNet.sln b/UnitsNet.sln index 3d39b45b2c..a6d456b661 100644 --- a/UnitsNet.sln +++ b/UnitsNet.sln @@ -1,11 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.13 +VisualStudioVersion = 15.0.26730.10 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitsNet.NetStandard10", "UnitsNet\UnitsNet.NetStandard10.csproj", "{CBEAD842-07BC-4B08-9D9D-D6659813776F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitsNet.NetStandard10", "UnitsNet\UnitsNet.NetStandard10.csproj", "{CBEAD842-07BC-4B08-9D9D-D6659813776F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitsNet.Serialization.JsonNet", "UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.csproj", "{FB696BFE-B303-4EBD-A0E6-4A7B19DE429B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitsNet.Serialization.JsonNet", "UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.csproj", "{FB696BFE-B303-4EBD-A0E6-4A7B19DE429B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitsNet.Serialization.JsonNet.Signed", "UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.Signed.csproj", "{7798DBCF-DD59-4CAD-A754-FB7DCC6BD312}" EndProject @@ -15,6 +15,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitsNet.Serialization.Json EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitsNet.Tests.NetCore", "UnitsNet.Tests\UnitsNet.Tests.NetCore.csproj", "{0E3B7567-5DF2-44BD-88DB-CCF050D3F943}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitsNet.OperatorOverloads", "UnitsNet.OperatorOverloads\UnitsNet.OperatorOverloads.csproj", "{8758EDF0-0965-4928-A5D2-192F4ECD5810}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitsNet.OperatorOverloads.Tests", "UnitsNet.OperatorOverloads.Tests\UnitsNet.OperatorOverloads.Tests.csproj", "{905C728D-7228-4F85-9202-B27006ADC024}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -123,8 +127,43 @@ Global {0E3B7567-5DF2-44BD-88DB-CCF050D3F943}.Release|x64.Build.0 = Release|Any CPU {0E3B7567-5DF2-44BD-88DB-CCF050D3F943}.Release|x86.ActiveCfg = Release|Any CPU {0E3B7567-5DF2-44BD-88DB-CCF050D3F943}.Release|x86.Build.0 = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|ARM.ActiveCfg = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|ARM.Build.0 = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|x64.ActiveCfg = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|x64.Build.0 = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|x86.ActiveCfg = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Debug|x86.Build.0 = Debug|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|Any CPU.Build.0 = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|ARM.ActiveCfg = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|ARM.Build.0 = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|x64.ActiveCfg = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|x64.Build.0 = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|x86.ActiveCfg = Release|Any CPU + {8758EDF0-0965-4928-A5D2-192F4ECD5810}.Release|x86.Build.0 = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|Any CPU.Build.0 = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|ARM.ActiveCfg = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|ARM.Build.0 = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|x64.ActiveCfg = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|x64.Build.0 = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|x86.ActiveCfg = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Debug|x86.Build.0 = Debug|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|Any CPU.ActiveCfg = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|Any CPU.Build.0 = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|ARM.ActiveCfg = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|ARM.Build.0 = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|x64.ActiveCfg = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|x64.Build.0 = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|x86.ActiveCfg = Release|Any CPU + {905C728D-7228-4F85-9202-B27006ADC024}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {154B9C1C-39AA-4A5A-9923-3B575AA6F335} + EndGlobalSection EndGlobal From e46fb5965429844e1c6918c3f0ea188b08a00780 Mon Sep 17 00:00:00 2001 From: Erik Ovegard Date: Thu, 7 Sep 2017 22:07:10 +0200 Subject: [PATCH 3/3] First try at overload generation (doesn't build, duplicate overloads) --- .../OverloadGeneratorTests.cs | 18 +++- UnitsNet.OperatorOverloads/ArrayExtensions.cs | 2 +- UnitsNet.OperatorOverloads/Overload.cs | 27 ++++++ .../OverloadGenerator.cs | 33 ++++++- .../UnitsNet.OperatorOverloads.csproj | 3 + ...itsNet.OperatorOverloads.v3.ncrunchproject | 5 + .../UnitClasses/Acceleration.overloads.g.cs | 71 ++++++++++++++ .../UnitClasses/Area.overloads.g.cs | 75 ++++++++++++++ .../AreaMomentOfInertia.overloads.g.cs | 75 ++++++++++++++ ...rakeSpecificFuelConsumption.overloads.g.cs | 71 ++++++++++++++ .../UnitClasses/Density.overloads.g.cs | 79 +++++++++++++++ .../UnitClasses/Duration.overloads.g.cs | 71 ++++++++++++++ .../DynamicViscosity.overloads.g.cs | 71 ++++++++++++++ .../UnitClasses/Length.overloads.g.cs | 79 +++++++++++++++ .../UnitClasses/Speed.overloads.g.cs | 79 +++++++++++++++ UnitsNet/Scripts/GenerateUnits.ps1 | 22 +++++ ...e-GenerateUnitClassOverloadsSourceCode.ps1 | 97 +++++++++++++++++++ UnitsNet/UnitDefinitions/Acceleration.json | 3 +- UnitsNet/UnitDefinitions/Area.json | 3 +- .../UnitDefinitions/AreaMomentOfInertia.json | 3 +- .../BrakeSpecificFuelConsumption.json | 3 +- UnitsNet/UnitDefinitions/Density.json | 3 +- UnitsNet/UnitDefinitions/Duration.json | 3 +- .../UnitDefinitions/DynamicViscosity.json | 3 +- UnitsNet/UnitDefinitions/Length.json | 3 +- UnitsNet/UnitDefinitions/Speed.json | 3 +- 26 files changed, 891 insertions(+), 14 deletions(-) create mode 100644 UnitsNet.OperatorOverloads/Overload.cs create mode 100644 UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.v3.ncrunchproject create mode 100644 UnitsNet/GeneratedCode/UnitClasses/Acceleration.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/Area.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/AreaMomentOfInertia.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/BrakeSpecificFuelConsumption.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/Density.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/Duration.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/Length.overloads.g.cs create mode 100644 UnitsNet/GeneratedCode/UnitClasses/Speed.overloads.g.cs create mode 100644 UnitsNet/Scripts/Include-GenerateUnitClassOverloadsSourceCode.ps1 diff --git a/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs b/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs index b0b14a04e0..440a5ab30e 100644 --- a/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs +++ b/UnitsNet.OperatorOverloads.Tests/OverloadGeneratorTests.cs @@ -11,15 +11,12 @@ public static class OverloadGeneratorTests public static void ShouldReturnDurationAndSpeedWhenGivenLength() { var lengthQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Length.json")); - lengthQuantity.SiArray = new[] {1, 0, 0, 0, 0, 0, 0}; string neobj = JsonConvert.SerializeObject(lengthQuantity, new JsonSerializerSettings() { Formatting = Formatting.Indented }); var timeQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Duration.json")); - timeQuantity.SiArray = new[] { 0, 0, 1, 0, 0, 0, 0 }; var speedQuantity = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\Speed.json")); - speedQuantity.SiArray = new[] { 1, 0, -1, 0, 0, 0, 0 }; var overloadGenerator = new OverloadGenerator(new[] {lengthQuantity, timeQuantity, speedQuantity}); Overload[] actualQuantities = overloadGenerator.GetDivisionOverloads(lengthQuantity).ToArray(); @@ -46,5 +43,20 @@ public static void ShouldReturnLengthWhenGivenSpeed() Assert.Equal(1, actualQuantities.Length); Assert.Contains(lengthQuantity.Name, actualQuantityNames); } + + [Fact] + public static void RunCodeINSAmeWayAsPowerShell() + { + var overloadGenerator = new OverloadGenerator(@"C:\dev\UnitsNet\UnitsNet\UnitDefinitions\"); + foreach (var quantity in overloadGenerator.Quantities) + { + var overloads = overloadGenerator.GetOverloads(quantity); + Assert.NotNull(overloads); + foreach (Overload overload in overloads) + { + Assert.NotNull(overload); + } + } + } } } diff --git a/UnitsNet.OperatorOverloads/ArrayExtensions.cs b/UnitsNet.OperatorOverloads/ArrayExtensions.cs index 5cb1b85312..a233fd5f49 100644 --- a/UnitsNet.OperatorOverloads/ArrayExtensions.cs +++ b/UnitsNet.OperatorOverloads/ArrayExtensions.cs @@ -41,7 +41,7 @@ public static bool EqualContent(this T[] left, T[] right) { if (left == default(T[])) { - throw new ArgumentNullException(nameof(left)); + return false; } if (right == default(T[])) { diff --git a/UnitsNet.OperatorOverloads/Overload.cs b/UnitsNet.OperatorOverloads/Overload.cs new file mode 100644 index 0000000000..0304e39563 --- /dev/null +++ b/UnitsNet.OperatorOverloads/Overload.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UnitsNet.OperatorOverloads +{ + public class Overload + { + public Quantity Result { get; } + public Quantity Left { get; } + public Quantity Right { get; } + + public Overload(Quantity result, Quantity left, Quantity right) + { + Result = result; + Left = left; + Right = right; + } + + public override string ToString() + { + return $"{nameof(Result)}: {Result}, {nameof(Left)}: {Left}, {nameof(Right)}: {Right}"; + } + } +} diff --git a/UnitsNet.OperatorOverloads/OverloadGenerator.cs b/UnitsNet.OperatorOverloads/OverloadGenerator.cs index 0b133e6cdd..e4e3ab77e7 100644 --- a/UnitsNet.OperatorOverloads/OverloadGenerator.cs +++ b/UnitsNet.OperatorOverloads/OverloadGenerator.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; namespace UnitsNet.OperatorOverloads { @@ -10,6 +12,16 @@ public class OverloadGenerator { private readonly Quantity[] _quantities; + public OverloadGenerator(string directory) + { + var files = Directory.EnumerateFiles(directory, "*.json"); + _quantities = files.Select(f => JsonConvert.DeserializeObject(File.ReadAllText(f))).ToArray(); + if (_quantities.Length == 0) + { + throw new InvalidOperationException($"{files}"); + } + } + public OverloadGenerator(Quantity[] quantities) { _quantities = quantities; @@ -17,8 +29,12 @@ public OverloadGenerator(Quantity[] quantities) public IEnumerable GetDivisionOverloads(Quantity quantity) { + if (quantity.SiArray == null) + yield break; foreach (Quantity q in _quantities) { + if (q.SiArray == null) + continue; if (!quantity.Name.Equals(q.Name,StringComparison.OrdinalIgnoreCase)) { var newSiArray = quantity.SiArray.ElementwiseSubtract(q.SiArray); @@ -26,7 +42,7 @@ public IEnumerable GetDivisionOverloads(Quantity quantity) Quantity matchingQuantity = _quantities.SingleOrDefault(x => x.SiArray.EqualContent(newSiArray)); if (matchingQuantity != null) { - yield return new Overload(matchingQuantity, q, quantity); + yield return new Overload(matchingQuantity, quantity, q); } } } @@ -34,10 +50,14 @@ public IEnumerable GetDivisionOverloads(Quantity quantity) public IEnumerable GetMultiplicationOverloads(Quantity quantity) { + if (quantity.SiArray == null) + yield break; foreach (Quantity q in _quantities) { if (!quantity.Name.Equals(q.Name, StringComparison.OrdinalIgnoreCase)) { + if (q.SiArray == null) + continue; var newSiArray = quantity.SiArray.ElementwiseAdd(q.SiArray); Quantity matchingQuantity = _quantities.SingleOrDefault(x => x.SiArray.EqualContent(newSiArray)); @@ -45,10 +65,21 @@ public IEnumerable GetMultiplicationOverloads(Quantity quantity) { yield return new Overload(matchingQuantity, q, quantity); } + } } } + public IReadOnlyList Quantities => _quantities; + + public int NumberOfQuantities => _quantities.Length; + + public Quantity GetQuantityByName(string name) + { + return _quantities.Single(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + } + + public IEnumerable GetOverloads(Quantity quantity) { var multiplications = GetMultiplicationOverloads(quantity); diff --git a/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj b/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj index 9ebbcac719..62fd6fdee3 100644 --- a/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj +++ b/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.csproj @@ -5,4 +5,7 @@ + + + \ No newline at end of file diff --git a/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.v3.ncrunchproject b/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.v3.ncrunchproject new file mode 100644 index 0000000000..6800b4a3fe --- /dev/null +++ b/UnitsNet.OperatorOverloads/UnitsNet.OperatorOverloads.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/UnitsNet/GeneratedCode/UnitClasses/Acceleration.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Acceleration.overloads.g.cs new file mode 100644 index 0000000000..854ca33465 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/Acceleration.overloads.g.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class Acceleration +#else + public partial struct Acceleration +#endif + { + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/Area.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Area.overloads.g.cs new file mode 100644 index 0000000000..8fb8d366a7 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/Area.overloads.g.cs @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class Area +#else + public partial struct Area +#endif + { + public static Length operator /(Area left, Length right) + { + throw new NotImplementedException(); + } + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/AreaMomentOfInertia.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/AreaMomentOfInertia.overloads.g.cs new file mode 100644 index 0000000000..4467948a27 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/AreaMomentOfInertia.overloads.g.cs @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class AreaMomentOfInertia +#else + public partial struct AreaMomentOfInertia +#endif + { + public static Area operator /(AreaMomentOfInertia left, Area right) + { + throw new NotImplementedException(); + } + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/BrakeSpecificFuelConsumption.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/BrakeSpecificFuelConsumption.overloads.g.cs new file mode 100644 index 0000000000..253308c116 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/BrakeSpecificFuelConsumption.overloads.g.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class BrakeSpecificFuelConsumption +#else + public partial struct BrakeSpecificFuelConsumption +#endif + { + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/Density.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Density.overloads.g.cs new file mode 100644 index 0000000000..aa04c4ab19 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/Density.overloads.g.cs @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class Density +#else + public partial struct Density +#endif + { + public static DynamicViscosity operator /(Density left, Duration right) + { + throw new NotImplementedException(); + } + public static Duration operator /(Density left, DynamicViscosity right) + { + throw new NotImplementedException(); + } + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/Duration.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Duration.overloads.g.cs new file mode 100644 index 0000000000..8d3eff68a9 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/Duration.overloads.g.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class Duration +#else + public partial struct Duration +#endif + { + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.overloads.g.cs new file mode 100644 index 0000000000..3d0b39ea3b --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.overloads.g.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class DynamicViscosity +#else + public partial struct DynamicViscosity +#endif + { + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/Length.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Length.overloads.g.cs new file mode 100644 index 0000000000..313dac5766 --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/Length.overloads.g.cs @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class Length +#else + public partial struct Length +#endif + { + public static Speed operator /(Length left, Duration right) + { + throw new NotImplementedException(); + } + public static Duration operator /(Length left, Speed right) + { + throw new NotImplementedException(); + } + // End of overloads + } +} diff --git a/UnitsNet/GeneratedCode/UnitClasses/Speed.overloads.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Speed.overloads.g.cs new file mode 100644 index 0000000000..2441bad5fa --- /dev/null +++ b/UnitsNet/GeneratedCode/UnitClasses/Speed.overloads.g.cs @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class Speed +#else + public partial struct Speed +#endif + { + public static Duration operator /(Speed left, Acceleration right) + { + throw new NotImplementedException(); + } + public static Acceleration operator /(Speed left, Duration right) + { + throw new NotImplementedException(); + } + // End of overloads + } +} diff --git a/UnitsNet/Scripts/GenerateUnits.ps1 b/UnitsNet/Scripts/GenerateUnits.ps1 index 92de1a2ef8..fb3a05a66b 100644 --- a/UnitsNet/Scripts/GenerateUnits.ps1 +++ b/UnitsNet/Scripts/GenerateUnits.ps1 @@ -19,6 +19,22 @@ function GenerateUnitClass($unitClass, $outDir) Write-Host -NoNewline "class(OK) " } +function GenerateUnitClassOverloads($unitClass, $outDir, $overloadGenerator) +{ + if ($($unitClass.SiArray)) { + $outFileName = "$outDir/$($unitClass.Name).overloads.g.cs" + GenerateUnitClassOverloadsSourceCode $unitClass $overloadGenerator | Out-File -Encoding "UTF8" $outFileName | Out-Null + if (!$?) { + exit 1 + } + Write-Host -NoNewline "overloads(OK) " + } + else{ + Write-Host -NoNewline "no overloads " + } + +} + function GenerateUnitTestBaseClass($unitClass, $outDir) { $outFileName = "$outDir/$($unitClass.Name)TestsBase.g.cs" @@ -255,6 +271,7 @@ function Add-InheritedUnits($unitClass, $unitClasses) { . "$PSScriptRoot/Include-GenerateUnitSystemDefaultSourceCode.ps1" . "$PSScriptRoot/Include-GenerateQuantityTypeSourceCode.ps1" . "$PSScriptRoot/Include-GenerateUnitClassSourceCode.ps1" +. "$PSScriptRoot/Include-GenerateUnitClassOverloadsSourceCode.ps1" . "$PSScriptRoot/Include-GenerateUnitEnumSourceCode.ps1" . "$PSScriptRoot/Include-GenerateUnitTestBaseClassSourceCode.ps1" . "$PSScriptRoot/Include-GenerateUnitTestPlaceholderSourceCode.ps1" @@ -278,12 +295,17 @@ $unitClasses = Get-ChildItem -Path $templatesDir -filter "*.json" ` | Set-ConversionFunctions ` | Set-UnitsOrderedByName +[System.Reflection.Assembly]::LoadFile("$PSScriptRoot/../../UnitsNet.OperatorOverloads/bin/Debug/net46/UnitsNet.OperatorOverloads.dll") +[System.Reflection.Assembly]::LoadFile("$PSScriptRoot/../../UnitsNet.OperatorOverloads/bin/Debug/net46/Newtonsoft.Json.dll") +$overloadGenerator = New-Object UnitsNet.OperatorOverloads.OverloadGenerator -ArgumentList "$PSScriptRoot/../UnitDefinitions" + foreach ($unitClass in $unitClasses) { Write-Host -NoNewline "$($unitClass.Name):".PadRight($pad) Add-InheritedUnits $unitClass $unitClasses GenerateUnitClass $unitClass $unitClassDir + GenerateUnitClassOverloads $unitClass $unitClassDir $overloadGenerator GenerateUnitEnum $unitClass $unitEnumDir GenerateNumberExtensions $unitClass $numberExtensionsDir GenerateUnitTestBaseClass $unitClass $testsDir diff --git a/UnitsNet/Scripts/Include-GenerateUnitClassOverloadsSourceCode.ps1 b/UnitsNet/Scripts/Include-GenerateUnitClassOverloadsSourceCode.ps1 new file mode 100644 index 0000000000..1f77a58d3e --- /dev/null +++ b/UnitsNet/Scripts/Include-GenerateUnitClassOverloadsSourceCode.ps1 @@ -0,0 +1,97 @@ +function GenerateUnitClassOverloadsSourceCode($unitClass, $overloadGenerator) +{ + $className = $unitClass.Name; + $units = $unitClass.Units; + $baseType = $unitClass.BaseType; + $baseUnit = $units | where { $_.SingularName -eq $unitClass.BaseUnit } + $baseUnitSingularName = $baseUnit.SingularName + $baseUnitPluralName = $baseUnit.PluralName + $baseUnitPluralNameLower = $baseUnitPluralName.ToLowerInvariant() + $unitEnumName = "$className" + "Unit"; + $baseUnitFieldName = "_"+[Char]::ToLowerInvariant($baseUnitPluralName[0]) + $baseUnitPluralName.Substring(1); + $quantity = $overloadGenerator.GetQuantityByName($className) + $divisonOverloads = $overloadGenerator.GetDivisionOverloads($quantity); + +@" +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes. +// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2017 Andreas Gullberg Larsen (anjdreas@gmail.com). +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class $className +#else + public partial struct $className +#endif + { +"@; if ($divisonOverloads) { + foreach ($overload in $divisonOverloads) { + if ($overload) { +@" + public static $($overload.Result) operator /($($overload.Left) left, $($overload.Right) right) + { + throw new NotImplementedException(); + } +"@; }}}@" + // End of overloads + } +} +"@; +} \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/Acceleration.json b/UnitsNet/UnitDefinitions/Acceleration.json index 5f8fef3b07..fef99adcb7 100644 --- a/UnitsNet/UnitDefinitions/Acceleration.json +++ b/UnitsNet/UnitDefinitions/Acceleration.json @@ -16,5 +16,6 @@ } ] } - ] + ], + "SiArray": [ 1, 0, -2, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/Area.json b/UnitsNet/UnitDefinitions/Area.json index 83fd048a2b..874f0bccf9 100644 --- a/UnitsNet/UnitDefinitions/Area.json +++ b/UnitsNet/UnitDefinitions/Area.json @@ -187,5 +187,6 @@ } ] } - ] + ], + "SiArray": [ 2, 0, 0, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/AreaMomentOfInertia.json b/UnitsNet/UnitDefinitions/AreaMomentOfInertia.json index 148004bed1..1166ae942d 100644 --- a/UnitsNet/UnitDefinitions/AreaMomentOfInertia.json +++ b/UnitsNet/UnitDefinitions/AreaMomentOfInertia.json @@ -75,5 +75,6 @@ } ] } - ] + ], + "SiArray": [ 4, 0, 0, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/BrakeSpecificFuelConsumption.json b/UnitsNet/UnitDefinitions/BrakeSpecificFuelConsumption.json index 3f861d72a4..895d211faf 100644 --- a/UnitsNet/UnitDefinitions/BrakeSpecificFuelConsumption.json +++ b/UnitsNet/UnitDefinitions/BrakeSpecificFuelConsumption.json @@ -40,5 +40,6 @@ } ] } - ] + ], + "SiArray": [ -2, 0, 2, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/Density.json b/UnitsNet/UnitDefinitions/Density.json index f86a3f0511..7dd0fd0b7e 100644 --- a/UnitsNet/UnitDefinitions/Density.json +++ b/UnitsNet/UnitDefinitions/Density.json @@ -162,5 +162,6 @@ } ] } - ] + ], + "SiArray": [ -1, 1, 0, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/Duration.json b/UnitsNet/UnitDefinitions/Duration.json index 7be53c66b6..b0ee7656df 100644 --- a/UnitsNet/UnitDefinitions/Duration.json +++ b/UnitsNet/UnitDefinitions/Duration.json @@ -163,5 +163,6 @@ } ] } - ] + ], + "SiArray": [ 0, 0, 1, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/DynamicViscosity.json b/UnitsNet/UnitDefinitions/DynamicViscosity.json index 6f3438b97b..9cd1bc796f 100644 --- a/UnitsNet/UnitDefinitions/DynamicViscosity.json +++ b/UnitsNet/UnitDefinitions/DynamicViscosity.json @@ -42,5 +42,6 @@ } ] } - ] + ], + "SiArray": [ -1, 1, -1, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/Length.json b/UnitsNet/UnitDefinitions/Length.json index 1bb9d0753a..ee3858f19a 100644 --- a/UnitsNet/UnitDefinitions/Length.json +++ b/UnitsNet/UnitDefinitions/Length.json @@ -169,5 +169,6 @@ } ] } - ] + ], + "SiArray": [ 1, 0, 0, 0, 0, 0, 0 ] } \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/Speed.json b/UnitsNet/UnitDefinitions/Speed.json index d0ce8a01f7..5c45f10b69 100644 --- a/UnitsNet/UnitDefinitions/Speed.json +++ b/UnitsNet/UnitDefinitions/Speed.json @@ -78,5 +78,6 @@ } ] } - ] + ], + "SiArray": [ 1, 0, -1, 0, 0, 0, 0 ] } \ No newline at end of file