From 986d10b9d49cdfc97555e543dcf8e5843ef688e3 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Fri, 15 Nov 2013 01:18:45 +0100 Subject: [PATCH] Implement T4 template support to generat unit classes based on Unit enum values tagged with attributes. * Using wildcards in .csproj files to automatically load files. * Fixed all tests, mostly due to improved precision of constants and not using Delta. * Added ToString() to vectors. * In test code, disabled build warning CS1718: Comparison made to same variable; did you mean to compare something else? BREAKING BACKWARDS COMPATIBILITY ================================== * Fixed case and plural naming of units: Kilopascal, Megapascal, RevolutionPerSecond --- Src/UnitsNet/Area.cs | 247 -------- Src/UnitsNet/Attributes.cs | 139 ++++ Src/UnitsNet/Constants.cs | 27 + Src/UnitsNet/Extensions/EnumExtensions.cs | 52 ++ Src/UnitsNet/Flow.cs | 150 ----- .../Angle.generated.cs} | 125 ++-- Src/UnitsNet/Generated/Area.generated.cs | 245 +++++++ .../ElectricPotential.generated.cs} | 285 +++++---- Src/UnitsNet/Generated/Flow.generated.cs | 175 +++++ .../Force.generated.cs} | 459 +++++++------- .../Length.generated.cs} | 592 +++++++++-------- .../{Mass.cs => Generated/Mass.generated.cs} | 597 ++++++++---------- .../Generated/MultipleOutputHelper.ttinclude | 196 ++++++ .../Pressure.generated.cs} | 588 ++++++++--------- .../RotationalSpeed.generated.cs} | 325 +++++----- .../Torque.generated.cs} | 292 +++++---- Src/UnitsNet/Generated/UnitClass.ttinclude | 255 ++++++++ Src/UnitsNet/Generated/Volume.generated.cs | 335 ++++++++++ .../Generated/__GenerateUnitClasses.tt | 30 + Src/UnitsNet/Partial/Force.extra.cs | 45 ++ Src/UnitsNet/Partial/Mass.extra.cs | 32 + Src/UnitsNet/Unit.cs | 306 ++++----- Src/UnitsNet/UnitConverter.cs | 56 +- Src/UnitsNet/UnitParser.cs | 1 + Src/UnitsNet/UnitSystem.cs | 16 +- Src/UnitsNet/UnitsNet.net35.csproj | 23 +- Src/UnitsNet/UnitsNet.netcore45.csproj | 9 +- Src/UnitsNet/UnitsNet.pcl.csproj | 9 +- Src/UnitsNet/UnitsNet.sl4.csproj | 9 +- Src/UnitsNet/{ => Utils}/EnumUtils.cs | 146 ++--- Src/UnitsNet/Vector2.cs | 5 + Src/UnitsNet/Vector3.cs | 5 + Src/UnitsNet/Volume.cs | 376 ----------- Src/UnitsNet/packages.config | 4 + Tests/AngleTests.cs | 5 +- Tests/AreaTests.cs | 5 +- Tests/FlowTests.cs | 57 +- Tests/ForceTests.cs | 23 +- Tests/Length2dTests.cs | 35 +- Tests/LengthTests.cs | 21 +- Tests/MassTests.cs | 45 +- Tests/PressureTests.cs | 25 +- Tests/RevolutionTests.cs | 5 +- Tests/UnitConversionTests.cs | 8 +- Tests/UnitConverterTests.cs | 34 +- Tests/UnitSystemTests.cs | 6 +- Tests/UnitValueTests.cs | 2 +- Tests/VolumeTests.cs | 5 +- 48 files changed, 3605 insertions(+), 2827 deletions(-) delete mode 100644 Src/UnitsNet/Area.cs create mode 100644 Src/UnitsNet/Attributes.cs create mode 100644 Src/UnitsNet/Constants.cs create mode 100644 Src/UnitsNet/Extensions/EnumExtensions.cs delete mode 100644 Src/UnitsNet/Flow.cs rename Src/UnitsNet/{Angle.cs => Generated/Angle.generated.cs} (51%) create mode 100644 Src/UnitsNet/Generated/Area.generated.cs rename Src/UnitsNet/{ElectricPotential.cs => Generated/ElectricPotential.generated.cs} (65%) create mode 100644 Src/UnitsNet/Generated/Flow.generated.cs rename Src/UnitsNet/{Force.cs => Generated/Force.generated.cs} (69%) rename Src/UnitsNet/{Length.cs => Generated/Length.generated.cs} (57%) rename Src/UnitsNet/{Mass.cs => Generated/Mass.generated.cs} (50%) create mode 100644 Src/UnitsNet/Generated/MultipleOutputHelper.ttinclude rename Src/UnitsNet/{Pressure.cs => Generated/Pressure.generated.cs} (57%) rename Src/UnitsNet/{RotationalSpeed.cs => Generated/RotationalSpeed.generated.cs} (59%) rename Src/UnitsNet/{Torque.cs => Generated/Torque.generated.cs} (61%) create mode 100644 Src/UnitsNet/Generated/UnitClass.ttinclude create mode 100644 Src/UnitsNet/Generated/Volume.generated.cs create mode 100644 Src/UnitsNet/Generated/__GenerateUnitClasses.tt create mode 100644 Src/UnitsNet/Partial/Force.extra.cs create mode 100644 Src/UnitsNet/Partial/Mass.extra.cs rename Src/UnitsNet/{ => Utils}/EnumUtils.cs (93%) delete mode 100644 Src/UnitsNet/Volume.cs create mode 100644 Src/UnitsNet/packages.config diff --git a/Src/UnitsNet/Area.cs b/Src/UnitsNet/Area.cs deleted file mode 100644 index b5eaf61286..0000000000 --- a/Src/UnitsNet/Area.cs +++ /dev/null @@ -1,247 +0,0 @@ -using System; - -namespace UnitsNet -{ - public struct Area : IComparable, IComparable - { - private const double SquareKilometersToSquareMetersRatio = 1E6; - private const double SquareDecimetersToSquareMetersRatio = 1E-2; - private const double SquareCentimetersToSquareMetersRatio = 1E-4; - private const double SquareMillimetersToSquareMetersRatio = 1E-6; - private const double SquareMilesToSquareMetersRatio = 2.59*1E+6; - private const double SquareYardsToSquareMetersRatio = 0.836127; - private const double SquareFeetToSquareMetersRatio = 0.092903; - private const double SquareInchesToSquareMetersRatio = 0.00064516; - - public readonly double SquareMeters; - - public Area(double squareMeters) - { - SquareMeters = squareMeters; - } - - #region Unit Properties - - public double SquareKilometers - { - get { return SquareMeters / SquareKilometersToSquareMetersRatio; } - } - - public double SquareDecimeters - { - get { return SquareMeters / SquareDecimetersToSquareMetersRatio; } - } - - public double SquareCentimeters - { - get { return SquareMeters / SquareCentimetersToSquareMetersRatio; } - } - - public double SquareMillimeters - { - get { return SquareMeters / SquareMillimetersToSquareMetersRatio; } - } - - public double SquareMiles - { - get { return SquareMeters / SquareMilesToSquareMetersRatio; } - } - - public double SquareYards - { - get { return SquareMeters / SquareYardsToSquareMetersRatio; } - } - - public double SquareFeet - { - get { return SquareMeters / SquareFeetToSquareMetersRatio; } - } - - public double SquareInches - { - get { return SquareMeters / SquareInchesToSquareMetersRatio; } - } - - - #endregion - - #region Static - - /// - /// The maximum representable area in square meters. - /// - public static Area Max - { - get { return new Area(double.MaxValue); } - } - - /// - /// The smallest representable area in square meters. - /// - public static Area Min - { - get { return new Area(double.MinValue); } - } - - public static Area Zero - { - get { return new Area(); } - } - - public static Area FromSquareKilometers(double squareKilometers) - { - return new Area(squareKilometers * SquareKilometersToSquareMetersRatio); - } - - public static Area FromSquareMeters(double squareMeters) - { - return new Area(squareMeters); - } - - public static Area FromSquareDecimeters(double squareDecimeters) - { - return new Area(squareDecimeters * SquareDecimetersToSquareMetersRatio); - } - - public static Area FromSquareCentimeters(double squareCentimeters) - { - return new Area(squareCentimeters * SquareCentimetersToSquareMetersRatio); - } - - public static Area FromSquareMillimeters(double squareMillimeters) - { - return new Area(squareMillimeters * SquareMillimetersToSquareMetersRatio); - } - - public static Area FromSquareMiles(double sqmi) - { - return new Area(sqmi * SquareMilesToSquareMetersRatio); - } - - public static Area FromSquareYards(double yds) - { - return new Area(yds * SquareYardsToSquareMetersRatio); - } - - public static Area FromSquareFeet(double ft) - { - return new Area(ft * SquareFeetToSquareMetersRatio); - } - - public static Area FromSquareInches(double inches) - { - return new Area(inches * SquareInchesToSquareMetersRatio); - } - - #endregion - - #region Arithmetic operators - - public static Area operator -(Area right) - { - return FromSquareMeters(-right.SquareMeters); - } - - public static Area operator +(Area left, Area right) - { - return FromSquareMeters(left.SquareMeters + right.SquareMeters); - } - - public static Area operator -(Area left, Area right) - { - return FromSquareMeters(left.SquareMeters - right.SquareMeters); - } - - public static Area operator *(double left, Area right) - { - return FromSquareMeters(left * right.SquareMeters); - } - - public static Area operator *(Area left, double right) - { - return FromSquareMeters(left.SquareMeters * right); - } - - public static Area operator /(Area left, double right) - { - return FromSquareMeters(left.SquareMeters / right); - } - - public static double operator /(Area left, Area right) - { - return left.SquareMeters / right.SquareMeters; - } - - #endregion - - #region Comparable operators - - public static bool operator <=(Area left, Area right) - { - return left.SquareMeters <= right.SquareMeters; - } - - public static bool operator >=(Area left, Area right) - { - return left.SquareMeters >= right.SquareMeters; - } - - public static bool operator <(Area left, Area right) - { - return left.SquareMeters < right.SquareMeters; - } - - public static bool operator >(Area left, Area right) - { - return left.SquareMeters > right.SquareMeters; - } - - public static bool operator ==(Area left, Area right) - { - return left.SquareMeters == right.SquareMeters; - } - - public static bool operator !=(Area left, Area right) - { - return !(left.SquareMeters == right.SquareMeters); - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Area)) throw new ArgumentException("Expected type Area.", "obj"); - return CompareTo((Area)obj); - } - - public int CompareTo(Area other) - { - return SquareMeters.CompareTo(other.SquareMeters); - } - - public override bool Equals(object obj) - { - if (obj == null || !(obj is Area)) - { - return false; - } - - return SquareMeters.CompareTo(((Area)obj).SquareMeters) == 0; - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #endregion - - public override string ToString() - { - return string.Format("{0:0.##} {1}", SquareMeters, UnitSystem.Create().GetDefaultAbbreviation(Unit.SquareMeter)); - } - } -} \ No newline at end of file diff --git a/Src/UnitsNet/Attributes.cs b/Src/UnitsNet/Attributes.cs new file mode 100644 index 0000000000..b6f0b33213 --- /dev/null +++ b/Src/UnitsNet/Attributes.cs @@ -0,0 +1,139 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/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; + +namespace UnitsNet +{ + [AttributeUsage(AttributeTargets.Field)] + public class LengthAttribute : UnitAttribute + { + public LengthAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class MassAttribute : UnitAttribute + { + public MassAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class AngleAttribute : UnitAttribute + { + public AngleAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class AreaAttribute : UnitAttribute + { + public AreaAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class ElectricPotentialAttribute : UnitAttribute + { + public ElectricPotentialAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class FlowAttribute : UnitAttribute + { + public FlowAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class ForceAttribute : UnitAttribute + { + public ForceAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class PressureAttribute : UnitAttribute + { + public PressureAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class RotationalSpeedAttribute : UnitAttribute + { + public RotationalSpeedAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class TorqueAttribute : UnitAttribute + { + public TorqueAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class VolumeAttribute : UnitAttribute + { + public VolumeAttribute(double ratio, string pluralName = null) : base(pluralName, ratio) + { + } + } + + [AttributeUsage(AttributeTargets.Field)] + public class UnitAttribute : Attribute + { + /// + /// Ratio of unit to base unit. For example, is 1000:1 of the base unit . + /// + public readonly double Ratio; + + /// + /// Name of unit in plural form. Will be used as property name such as Force.FromNewtonmeters(). + /// + public readonly string PluralName; + + ///// + ///// Name of unit in singular form. Will be used as ???. + ///// + //public string SingularName { get; set; } + + public UnitAttribute(string pluralName, double ratio) + { + Ratio = ratio; + PluralName = pluralName; + //SingularName = null; + } + } +} \ No newline at end of file diff --git a/Src/UnitsNet/Constants.cs b/Src/UnitsNet/Constants.cs new file mode 100644 index 0000000000..f812f2a137 --- /dev/null +++ b/Src/UnitsNet/Constants.cs @@ -0,0 +1,27 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/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. +namespace UnitsNet +{ + public static class Constants + { + public const double Gravity = 9.80665002864; + } +} \ No newline at end of file diff --git a/Src/UnitsNet/Extensions/EnumExtensions.cs b/Src/UnitsNet/Extensions/EnumExtensions.cs new file mode 100644 index 0000000000..76361346bd --- /dev/null +++ b/Src/UnitsNet/Extensions/EnumExtensions.cs @@ -0,0 +1,52 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/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.Linq; + +#if NETFX_CORE +using System.Reflection; +#endif + +namespace UnitsNet.Extensions +{ + /// + /// Source: http://codereview.stackexchange.com/a/5354/32101 + /// + public static class EnumExtensions + { + public static TAttribute GetAttribute(this Enum value) + where TAttribute : Attribute + { + // Below code not compatible with WinRT. + var type = value.GetType(); + var name = Enum.GetName(type, value); +#if NETFX_CORE + return type.GetRuntimeField(name) // I prefer to get attributes this way +#else + return type.GetField(name) // I prefer to get attributes this way +#endif + .GetCustomAttributes(false) + .OfType() + .SingleOrDefault(); + } + } +} \ No newline at end of file diff --git a/Src/UnitsNet/Flow.cs b/Src/UnitsNet/Flow.cs deleted file mode 100644 index 5d04c7d1d4..0000000000 --- a/Src/UnitsNet/Flow.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Globalization; - -namespace UnitsNet -{ - /// - /// A class for representing flow. - /// - public struct Flow : IComparable, IComparable - { - private const double SecondToMinuteRatio = 60; - private const double SecondToHourRatio = 3600; - - public readonly double CubicMeterPerSecond; - - private Flow(double cubicMeterPerSecond) - : this() - { - CubicMeterPerSecond = cubicMeterPerSecond; - } - - public double CubicMeterPerHour - { - get { return CubicMeterPerSecond / SecondToHourRatio; } - } - - #region Static - - public static Flow Zero - { - get { return new Flow(); } - } - - public static Flow FromCubicMeterPerHour(double cmh) - { - return new Flow(cmh * SecondToHourRatio); - } - - public static Flow FromCubicMeterPerSecond(double cms) - { - return new Flow(cms); - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Flow)) throw new ArgumentException("Expected type Flow.", "obj"); - return CompareTo((Flow)obj); - } - - public int CompareTo(Flow other) - { - return CubicMeterPerSecond.CompareTo(other.CubicMeterPerSecond); - } - - public static bool operator <=(Flow left, Flow right) - { - return left.CubicMeterPerSecond <= right.CubicMeterPerSecond; - } - - public static bool operator >=(Flow left, Flow right) - { - return left.CubicMeterPerSecond >= right.CubicMeterPerSecond; - } - - public static bool operator <(Flow left, Flow right) - { - return left.CubicMeterPerSecond < right.CubicMeterPerSecond; - } - - public static bool operator >(Flow left, Flow right) - { - return left.CubicMeterPerSecond > right.CubicMeterPerSecond; - } - - public static bool operator ==(Flow left, Flow right) - { - return left.CubicMeterPerSecond == right.CubicMeterPerSecond; - } - - public static bool operator !=(Flow left, Flow right) - { - return left.CubicMeterPerSecond != right.CubicMeterPerSecond; - } - - public override bool Equals(object obj) - { - if (obj == null || GetType() != obj.GetType()) - { - return false; - } - - return CubicMeterPerSecond.Equals(((Flow)obj).CubicMeterPerSecond); - } - - public override int GetHashCode() - { - return CubicMeterPerSecond.GetHashCode(); - } - #endregion - - #region Arithmetic operators - - public static Flow operator -(Flow right) - { - return new Flow(-right.CubicMeterPerSecond); - } - - public static Flow operator +(Flow left, Flow right) - { - return new Flow(left.CubicMeterPerSecond + right.CubicMeterPerSecond); - } - - public static Flow operator -(Flow left, Flow right) - { - return new Flow(left.CubicMeterPerSecond - right.CubicMeterPerSecond); - } - - public static Flow operator *(double left, Flow right) - { - return new Flow(left * right.CubicMeterPerSecond); - } - - public static Flow operator *(Flow left, double right) - { - return new Flow(left.CubicMeterPerSecond * right); - } - - public static Flow operator /(Flow left, double right) - { - return new Flow(left.CubicMeterPerSecond / right); - } - - public static double operator /(Flow left, Flow right) - { - return left.CubicMeterPerSecond / right.CubicMeterPerSecond; - } - - #endregion - - public override string ToString() - { - return string.Format("{0:0.##} {1}", CubicMeterPerSecond, UnitSystem.Create().GetDefaultAbbreviation(Unit.CubicMeterPerSecond)); - } - } -} diff --git a/Src/UnitsNet/Angle.cs b/Src/UnitsNet/Generated/Angle.generated.cs similarity index 51% rename from Src/UnitsNet/Angle.cs rename to Src/UnitsNet/Generated/Angle.generated.cs index 0afd9b134c..dad35bdb1a 100644 --- a/Src/UnitsNet/Angle.cs +++ b/Src/UnitsNet/Generated/Angle.generated.cs @@ -1,97 +1,134 @@ -using System; - +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace namespace UnitsNet { - public struct Angle : IComparable, IComparable + /// + /// In geometry, an angle is the figure formed by two rays, called the sides of the angle, sharing a common endpoint, called the vertex of the angle. + /// + public partial struct Angle : IComparable, IComparable { - private const double RadiansToDegreesRatio = Math.PI / 180.0; - private const double GradiansToDegreesRatio = 1 / 0.9; - + /// + /// Base unit of Angle in degrees. + /// public readonly double Degrees; - public Angle(double degrees) + public Angle(double degrees) : this() { Degrees = degrees; } #region Unit Properties - public double Radians + public double Gradians { - get { return Degrees * RadiansToDegreesRatio; } + get { return Degrees/1.11111111111111; } } - public double Gradians + public double Radians { - get { return Degrees * GradiansToDegreesRatio; } + get { return Degrees/0.0174532925199433; } } - + #endregion - #region Static - + #region Static + public static Angle Zero { - get { return new Angle(0); } + get { return new Angle(); } } - + public static Angle FromDegrees(double degrees) { - return new Angle(degrees); + return new Angle(degrees*1); } - public static Angle FromRadians(double radians) + public static Angle FromGradians(double gradians) { - return new Angle(radians / RadiansToDegreesRatio); + return new Angle(gradians*1.11111111111111); } - public static Angle FromGradians(double gradians) + public static Angle FromRadians(double radians) { - return new Angle(gradians / GradiansToDegreesRatio); + return new Angle(radians*0.0174532925199433); } - + #endregion - #region Arithmetic operators + #region Arithmetic Operators public static Angle operator -(Angle right) { - return FromDegrees(-right.Degrees); + return new Angle(-right.Degrees); } public static Angle operator +(Angle left, Angle right) { - return FromDegrees(left.Degrees + right.Degrees); + return new Angle(left.Degrees + right.Degrees); } public static Angle operator -(Angle left, Angle right) { - return FromDegrees(left.Degrees - right.Degrees); + return new Angle(left.Degrees - right.Degrees); } public static Angle operator *(double left, Angle right) { - return FromDegrees(left * right.Degrees); + return new Angle(left*right.Degrees); } public static Angle operator *(Angle left, double right) { - return FromDegrees(left.Degrees * right); + return new Angle(left.Degrees*right); } public static Angle operator /(Angle left, double right) { - return FromDegrees(left.Degrees / right); + return new Angle(left.Degrees/right); } public static double operator /(Angle left, Angle right) { - return left.Degrees / right.Degrees; + return left.Degrees/right.Degrees; } #endregion - #region Comparable operators + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Angle)) throw new ArgumentException("Expected type Angle.", "obj"); + return CompareTo((Angle) obj); + } + + public int CompareTo(Angle other) + { + return Degrees.CompareTo(other.Degrees); + } public static bool operator <=(Angle left, Angle right) { @@ -120,38 +157,22 @@ public static Angle FromGradians(double gradians) public static bool operator !=(Angle left, Angle right) { - return !(left.Degrees == right.Degrees); - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Angle)) throw new ArgumentException("Expected type Angle.", "obj"); - return CompareTo((Angle)obj); - } - - public int CompareTo(Angle other) - { - return Degrees.CompareTo(other.Degrees); + return left.Degrees != right.Degrees; } public override bool Equals(object obj) { - if (obj == null || !(obj is Angle)) + if (obj == null || GetType() != obj.GetType()) { return false; } - return Degrees.CompareTo(((Angle)obj).Degrees) == 0; + return Degrees.Equals(((Angle) obj).Degrees); } public override int GetHashCode() { - return base.GetHashCode(); + return Degrees.GetHashCode(); } #endregion @@ -161,4 +182,4 @@ public override string ToString() return string.Format("{0:0.##} {1}", Degrees, UnitSystem.Create().GetDefaultAbbreviation(Unit.Degree)); } } -} \ No newline at end of file +} diff --git a/Src/UnitsNet/Generated/Area.generated.cs b/Src/UnitsNet/Generated/Area.generated.cs new file mode 100644 index 0000000000..746791c775 --- /dev/null +++ b/Src/UnitsNet/Generated/Area.generated.cs @@ -0,0 +1,245 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// Area is a quantity that expresses the extent of a two-dimensional surface or shape, or planar lamina, in the plane. Area can be understood as the amount of material with a given thickness that would be necessary to fashion a model of the shape, or the amount of paint necessary to cover the surface with a single coat.[1] It is the two-dimensional analog of the length of a curve (a one-dimensional concept) or the volume of a solid (a three-dimensional concept). + /// + public partial struct Area : IComparable, IComparable + { + /// + /// Base unit of Area in squaremeters. + /// + public readonly double SquareMeters; + + public Area(double squaremeters) : this() + { + SquareMeters = squaremeters; + } + + #region Unit Properties + + public double SquareCentimeters + { + get { return SquareMeters/0.0001; } + } + + public double SquareDecimeters + { + get { return SquareMeters/0.01; } + } + + public double SquareFeet + { + get { return SquareMeters/0.092903; } + } + + public double SquareInches + { + get { return SquareMeters/0.00064516; } + } + + public double SquareKilometers + { + get { return SquareMeters/1000000; } + } + + public double SquareMiles + { + get { return SquareMeters/2590000; } + } + + public double SquareMillimeters + { + get { return SquareMeters/1E-06; } + } + + public double SquareYards + { + get { return SquareMeters/0.836127; } + } + + #endregion + + #region Static + + public static Area Zero + { + get { return new Area(); } + } + + public static Area FromSquareCentimeters(double squarecentimeters) + { + return new Area(squarecentimeters*0.0001); + } + + public static Area FromSquareDecimeters(double squaredecimeters) + { + return new Area(squaredecimeters*0.01); + } + + public static Area FromSquareFeet(double squarefeet) + { + return new Area(squarefeet*0.092903); + } + + public static Area FromSquareInches(double squareinches) + { + return new Area(squareinches*0.00064516); + } + + public static Area FromSquareKilometers(double squarekilometers) + { + return new Area(squarekilometers*1000000); + } + + public static Area FromSquareMeters(double squaremeters) + { + return new Area(squaremeters*1); + } + + public static Area FromSquareMiles(double squaremiles) + { + return new Area(squaremiles*2590000); + } + + public static Area FromSquareMillimeters(double squaremillimeters) + { + return new Area(squaremillimeters*1E-06); + } + + public static Area FromSquareYards(double squareyards) + { + return new Area(squareyards*0.836127); + } + + #endregion + + #region Arithmetic Operators + + public static Area operator -(Area right) + { + return new Area(-right.SquareMeters); + } + + public static Area operator +(Area left, Area right) + { + return new Area(left.SquareMeters + right.SquareMeters); + } + + public static Area operator -(Area left, Area right) + { + return new Area(left.SquareMeters - right.SquareMeters); + } + + public static Area operator *(double left, Area right) + { + return new Area(left*right.SquareMeters); + } + + public static Area operator *(Area left, double right) + { + return new Area(left.SquareMeters*right); + } + + public static Area operator /(Area left, double right) + { + return new Area(left.SquareMeters/right); + } + + public static double operator /(Area left, Area right) + { + return left.SquareMeters/right.SquareMeters; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Area)) throw new ArgumentException("Expected type Area.", "obj"); + return CompareTo((Area) obj); + } + + public int CompareTo(Area other) + { + return SquareMeters.CompareTo(other.SquareMeters); + } + + public static bool operator <=(Area left, Area right) + { + return left.SquareMeters <= right.SquareMeters; + } + + public static bool operator >=(Area left, Area right) + { + return left.SquareMeters >= right.SquareMeters; + } + + public static bool operator <(Area left, Area right) + { + return left.SquareMeters < right.SquareMeters; + } + + public static bool operator >(Area left, Area right) + { + return left.SquareMeters > right.SquareMeters; + } + + public static bool operator ==(Area left, Area right) + { + return left.SquareMeters == right.SquareMeters; + } + + public static bool operator !=(Area left, Area right) + { + return left.SquareMeters != right.SquareMeters; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return SquareMeters.Equals(((Area) obj).SquareMeters); + } + + public override int GetHashCode() + { + return SquareMeters.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", SquareMeters, UnitSystem.Create().GetDefaultAbbreviation(Unit.SquareMeter)); + } + } +} diff --git a/Src/UnitsNet/ElectricPotential.cs b/Src/UnitsNet/Generated/ElectricPotential.generated.cs similarity index 65% rename from Src/UnitsNet/ElectricPotential.cs rename to Src/UnitsNet/Generated/ElectricPotential.generated.cs index ba1603d59b..6a506a9dcf 100644 --- a/Src/UnitsNet/ElectricPotential.cs +++ b/Src/UnitsNet/Generated/ElectricPotential.generated.cs @@ -1,120 +1,165 @@ -// Copyright © 2007 by Initial Force AS. All rights reserved. -// https://github.com/InitialForce/SIUnits -// -// 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; - -namespace UnitsNet -{ - /// - /// A class for representing electrical tension in SI units. - /// - public struct ElectricPotential : IComparable, IComparable - { - /// - /// Returns a volt representation of the voltage instance. - /// - public readonly double Volts; - - public ElectricPotential(double volts) - { - Volts = volts; - } - - public override string ToString() - { - return string.Format("{0:0.##} {1}", Volts, UnitSystem.Create().GetDefaultAbbreviation(Unit.Volt)); - } - - #region Static - - public static ElectricPotential FromVolts(double volts) - { - return new ElectricPotential(volts); - } - - #endregion - - #region Arithmetic operators - - public static ElectricPotential operator -(ElectricPotential right) - { - return new ElectricPotential(-right.Volts); - } - - public static ElectricPotential operator +(ElectricPotential left, ElectricPotential right) - { - return new ElectricPotential(left.Volts + right.Volts); - } - - public static ElectricPotential operator -(ElectricPotential left, ElectricPotential right) - { - return new ElectricPotential(left.Volts - right.Volts); - } - - public static ElectricPotential operator *(double left, ElectricPotential right) - { - return new ElectricPotential(left*right.Volts); - } - - public static ElectricPotential operator /(ElectricPotential left, double right) - { - return new ElectricPotential(left.Volts/right); - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is ElectricPotential)) throw new ArgumentException("Expected type ElectricPotential.", "obj"); - return CompareTo((ElectricPotential) obj); - } - - public int CompareTo(ElectricPotential other) - { - return Volts.CompareTo(other.Volts); - } - - public static bool operator <=(ElectricPotential left, ElectricPotential right) - { - return left.Volts <= right.Volts; - } - - public static bool operator >=(ElectricPotential left, ElectricPotential right) - { - return left.Volts >= right.Volts; - } - - public static bool operator <(ElectricPotential left, ElectricPotential right) - { - return left.Volts < right.Volts; - } - - public static bool operator >(ElectricPotential left, ElectricPotential right) - { - return left.Volts > right.Volts; - } - - #endregion - } -} \ No newline at end of file +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// In classical electromagnetism, the electric potential (a scalar quantity denoted by Φ, ΦE or V and also called the electric field potential or the electrostatic potential) at a point is the amount of electric potential energy that a unitary point charge would have when located at that point. + /// + public partial struct ElectricPotential : IComparable, IComparable + { + /// + /// Base unit of ElectricPotential in volts. + /// + public readonly double Volts; + + public ElectricPotential(double volts) : this() + { + Volts = volts; + } + + #region Unit Properties + + #endregion + + #region Static + + public static ElectricPotential Zero + { + get { return new ElectricPotential(); } + } + + public static ElectricPotential FromVolts(double volts) + { + return new ElectricPotential(volts*1); + } + + #endregion + + #region Arithmetic Operators + + public static ElectricPotential operator -(ElectricPotential right) + { + return new ElectricPotential(-right.Volts); + } + + public static ElectricPotential operator +(ElectricPotential left, ElectricPotential right) + { + return new ElectricPotential(left.Volts + right.Volts); + } + + public static ElectricPotential operator -(ElectricPotential left, ElectricPotential right) + { + return new ElectricPotential(left.Volts - right.Volts); + } + + public static ElectricPotential operator *(double left, ElectricPotential right) + { + return new ElectricPotential(left*right.Volts); + } + + public static ElectricPotential operator *(ElectricPotential left, double right) + { + return new ElectricPotential(left.Volts*right); + } + + public static ElectricPotential operator /(ElectricPotential left, double right) + { + return new ElectricPotential(left.Volts/right); + } + + public static double operator /(ElectricPotential left, ElectricPotential right) + { + return left.Volts/right.Volts; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is ElectricPotential)) throw new ArgumentException("Expected type ElectricPotential.", "obj"); + return CompareTo((ElectricPotential) obj); + } + + public int CompareTo(ElectricPotential other) + { + return Volts.CompareTo(other.Volts); + } + + public static bool operator <=(ElectricPotential left, ElectricPotential right) + { + return left.Volts <= right.Volts; + } + + public static bool operator >=(ElectricPotential left, ElectricPotential right) + { + return left.Volts >= right.Volts; + } + + public static bool operator <(ElectricPotential left, ElectricPotential right) + { + return left.Volts < right.Volts; + } + + public static bool operator >(ElectricPotential left, ElectricPotential right) + { + return left.Volts > right.Volts; + } + + public static bool operator ==(ElectricPotential left, ElectricPotential right) + { + return left.Volts == right.Volts; + } + + public static bool operator !=(ElectricPotential left, ElectricPotential right) + { + return left.Volts != right.Volts; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return Volts.Equals(((ElectricPotential) obj).Volts); + } + + public override int GetHashCode() + { + return Volts.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", Volts, UnitSystem.Create().GetDefaultAbbreviation(Unit.Volt)); + } + } +} diff --git a/Src/UnitsNet/Generated/Flow.generated.cs b/Src/UnitsNet/Generated/Flow.generated.cs new file mode 100644 index 0000000000..7749749dc8 --- /dev/null +++ b/Src/UnitsNet/Generated/Flow.generated.cs @@ -0,0 +1,175 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// In physics and engineering, in particular fluid dynamics and hydrometry, the volumetric flow rate, (also known as volume flow rate, rate of fluid flow or volume velocity) is the volume of fluid which passes through a given surface per unit time. The SI unit is m3·s−1 (cubic meters per second). In US Customary Units and British Imperial Units, volumetric flow rate is often expressed as ft3/s (cubic feet per second). It is usually represented by the symbol Q. + /// + public partial struct Flow : IComparable, IComparable + { + /// + /// Base unit of Flow in cubicmeterspersecond. + /// + public readonly double CubicMetersPerSecond; + + public Flow(double cubicmeterspersecond) : this() + { + CubicMetersPerSecond = cubicmeterspersecond; + } + + #region Unit Properties + + public double CubicMetersPerHour + { + get { return CubicMetersPerSecond/3600; } + } + + #endregion + + #region Static + + public static Flow Zero + { + get { return new Flow(); } + } + + public static Flow FromCubicMetersPerHour(double cubicmetersperhour) + { + return new Flow(cubicmetersperhour*3600); + } + + public static Flow FromCubicMetersPerSecond(double cubicmeterspersecond) + { + return new Flow(cubicmeterspersecond*1); + } + + #endregion + + #region Arithmetic Operators + + public static Flow operator -(Flow right) + { + return new Flow(-right.CubicMetersPerSecond); + } + + public static Flow operator +(Flow left, Flow right) + { + return new Flow(left.CubicMetersPerSecond + right.CubicMetersPerSecond); + } + + public static Flow operator -(Flow left, Flow right) + { + return new Flow(left.CubicMetersPerSecond - right.CubicMetersPerSecond); + } + + public static Flow operator *(double left, Flow right) + { + return new Flow(left*right.CubicMetersPerSecond); + } + + public static Flow operator *(Flow left, double right) + { + return new Flow(left.CubicMetersPerSecond*right); + } + + public static Flow operator /(Flow left, double right) + { + return new Flow(left.CubicMetersPerSecond/right); + } + + public static double operator /(Flow left, Flow right) + { + return left.CubicMetersPerSecond/right.CubicMetersPerSecond; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Flow)) throw new ArgumentException("Expected type Flow.", "obj"); + return CompareTo((Flow) obj); + } + + public int CompareTo(Flow other) + { + return CubicMetersPerSecond.CompareTo(other.CubicMetersPerSecond); + } + + public static bool operator <=(Flow left, Flow right) + { + return left.CubicMetersPerSecond <= right.CubicMetersPerSecond; + } + + public static bool operator >=(Flow left, Flow right) + { + return left.CubicMetersPerSecond >= right.CubicMetersPerSecond; + } + + public static bool operator <(Flow left, Flow right) + { + return left.CubicMetersPerSecond < right.CubicMetersPerSecond; + } + + public static bool operator >(Flow left, Flow right) + { + return left.CubicMetersPerSecond > right.CubicMetersPerSecond; + } + + public static bool operator ==(Flow left, Flow right) + { + return left.CubicMetersPerSecond == right.CubicMetersPerSecond; + } + + public static bool operator !=(Flow left, Flow right) + { + return left.CubicMetersPerSecond != right.CubicMetersPerSecond; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return CubicMetersPerSecond.Equals(((Flow) obj).CubicMetersPerSecond); + } + + public override int GetHashCode() + { + return CubicMetersPerSecond.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", CubicMetersPerSecond, UnitSystem.Create().GetDefaultAbbreviation(Unit.CubicMeterPerSecond)); + } + } +} diff --git a/Src/UnitsNet/Force.cs b/Src/UnitsNet/Generated/Force.generated.cs similarity index 69% rename from Src/UnitsNet/Force.cs rename to Src/UnitsNet/Generated/Force.generated.cs index 86a807581d..c38ff16954 100644 --- a/Src/UnitsNet/Force.cs +++ b/Src/UnitsNet/Generated/Force.generated.cs @@ -1,234 +1,225 @@ -// Copyright © 2007 by Initial Force AS. All rights reserved. -// https://github.com/InitialForce/SIUnits -// -// 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; - -namespace UnitsNet -{ - /// - /// A class for representing force. - /// - public struct Force : IComparable, IComparable - { - private const double Gravity = 9.80665002864; - - /// - /// Returns a Newton representation of the force instance. - /// - public readonly double Newtons; - - private Force(double newtons) : this() - { - Newtons = newtons; - } - - public double Kilonewtons - { - get { return Newtons*1E-3; } - } - - public double Dyne - { - get { return Newtons*1E5; } - } - - public double KilogramForce - { - get { return Newtons/Gravity; } - } - - public double KiloPonds - { - get { return KilogramForce; } - } - - public double PoundForce - { - get { return 0.22480894309971 * Newtons; } - } - - public double Poundal - { - get { return 7.23301 * Newtons; } - } - - #region Static - - public static Force Zero - { - get { return new Force(); } - } - - public static Force FromDyne(double dyn) - { - return new Force(dyn*1E-5); - } - - public static Force FromPoundal(double pdl) - { - return new Force(0.13825502798973041652092282466083*pdl); - } - - public static Force FromPoundForce(double lbf) - { - return new Force(4.4482216152605095551842641431421*lbf); - } - - public static Force FromKilogramForce(double kgf) - { - return new Force(Gravity*kgf); - } - - public static Force FromKiloPonds(double kp) - { - return FromKilogramForce(kp); - } - - public static Force FromNewtons(double newtons) - { - return new Force(newtons); - } - - public static Force FromKilonewtons(double kN) - { - return new Force(kN*1E3); - } - - public static Force FromPressureByArea(Pressure p, Length2d area) - { - double metersSquared = area.Meters.X*area.Meters.Y; - double newtons = p.Pascals*metersSquared; - return new Force(newtons); - } - - public static Force FromMassAcceleration(Mass mass, double metersPerSecondSquared) - { - return new Force(mass.Kilograms*metersPerSecondSquared); - } - - #endregion - - #region Arithmetic operators - - public static Force operator -(Force right) - { - return new Force(-right.Newtons); - } - - public static Force operator +(Force left, Force right) - { - return new Force(left.Newtons + right.Newtons); - } - - public static Force operator -(Force left, Force right) - { - return new Force(left.Newtons - right.Newtons); - } - - public static Force operator *(double left, Force right) - { - return new Force(left*right.Newtons); - } - - public static Force operator *(Force left, double right) - { - return new Force(left.Newtons*right); - } - - public static Force operator /(Force left, double right) - { - return new Force(left.Newtons/right); - } - - public static double operator /(Force left, Force right) - { - return left.Newtons/right.Newtons; - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Force)) throw new ArgumentException("Expected type Force.", "obj"); - return CompareTo((Force) obj); - } - - public int CompareTo(Force other) - { - return Newtons.CompareTo(other.Newtons); - } - - public static bool operator <=(Force left, Force right) - { - return left.Newtons <= right.Newtons; - } - - public static bool operator >=(Force left, Force right) - { - return left.Newtons >= right.Newtons; - } - - public static bool operator <(Force left, Force right) - { - return left.Newtons < right.Newtons; - } - - public static bool operator >(Force left, Force right) - { - return left.Newtons > right.Newtons; - } - - public static bool operator ==(Force left, Force right) - { - return left.Newtons == right.Newtons; - } - - public static bool operator !=(Force left, Force right) - { - return left.Newtons != right.Newtons; - } - - public override bool Equals(object obj) - { - if (obj == null || GetType() != obj.GetType()) - { - return false; - } - - return Newtons.Equals(((Force) obj).Newtons); - } - - public override int GetHashCode() - { - return Newtons.GetHashCode(); - } - - #endregion - - public override string ToString() - { - return string.Format("{0:0.##} {1}", Newtons, UnitSystem.Create().GetDefaultAbbreviation(Unit.Newton)); - } - } -} \ No newline at end of file +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// In physics, a force is any influence that causes an object to undergo a certain change, either concerning its movement, direction, or geometrical construction. In other words, a force can cause an object with mass to change its velocity (which includes to begin moving from a state of rest), i.e., to accelerate, or a flexible object to deform, or both. Force can also be described by intuitive concepts such as a push or a pull. A force has both magnitude and direction, making it a vector quantity. It is measured in the SI unit of newtons and represented by the symbol F. + /// + public partial struct Force : IComparable, IComparable + { + /// + /// Base unit of Force in newtons. + /// + public readonly double Newtons; + + public Force(double newtons) : this() + { + Newtons = newtons; + } + + #region Unit Properties + + public double Dyne + { + get { return Newtons/1E-05; } + } + + public double KilogramsForce + { + get { return Newtons/9.80665002864; } + } + + public double Kilonewtons + { + get { return Newtons/1000; } + } + + public double KiloPonds + { + get { return Newtons/9.80665002864; } + } + + public double Poundals + { + get { return Newtons/0.13825502798973; } + } + + public double PoundForces + { + get { return Newtons/4.44822161526051; } + } + + #endregion + + #region Static + + public static Force Zero + { + get { return new Force(); } + } + + public static Force FromDyne(double dyne) + { + return new Force(dyne*1E-05); + } + + public static Force FromKilogramsForce(double kilogramsforce) + { + return new Force(kilogramsforce*9.80665002864); + } + + public static Force FromKilonewtons(double kilonewtons) + { + return new Force(kilonewtons*1000); + } + + public static Force FromKiloPonds(double kiloponds) + { + return new Force(kiloponds*9.80665002864); + } + + public static Force FromNewtons(double newtons) + { + return new Force(newtons*1); + } + + public static Force FromPoundals(double poundals) + { + return new Force(poundals*0.13825502798973); + } + + public static Force FromPoundForces(double poundforces) + { + return new Force(poundforces*4.44822161526051); + } + + #endregion + + #region Arithmetic Operators + + public static Force operator -(Force right) + { + return new Force(-right.Newtons); + } + + public static Force operator +(Force left, Force right) + { + return new Force(left.Newtons + right.Newtons); + } + + public static Force operator -(Force left, Force right) + { + return new Force(left.Newtons - right.Newtons); + } + + public static Force operator *(double left, Force right) + { + return new Force(left*right.Newtons); + } + + public static Force operator *(Force left, double right) + { + return new Force(left.Newtons*right); + } + + public static Force operator /(Force left, double right) + { + return new Force(left.Newtons/right); + } + + public static double operator /(Force left, Force right) + { + return left.Newtons/right.Newtons; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Force)) throw new ArgumentException("Expected type Force.", "obj"); + return CompareTo((Force) obj); + } + + public int CompareTo(Force other) + { + return Newtons.CompareTo(other.Newtons); + } + + public static bool operator <=(Force left, Force right) + { + return left.Newtons <= right.Newtons; + } + + public static bool operator >=(Force left, Force right) + { + return left.Newtons >= right.Newtons; + } + + public static bool operator <(Force left, Force right) + { + return left.Newtons < right.Newtons; + } + + public static bool operator >(Force left, Force right) + { + return left.Newtons > right.Newtons; + } + + public static bool operator ==(Force left, Force right) + { + return left.Newtons == right.Newtons; + } + + public static bool operator !=(Force left, Force right) + { + return left.Newtons != right.Newtons; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return Newtons.Equals(((Force) obj).Newtons); + } + + public override int GetHashCode() + { + return Newtons.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", Newtons, UnitSystem.Create().GetDefaultAbbreviation(Unit.Newton)); + } + } +} diff --git a/Src/UnitsNet/Length.cs b/Src/UnitsNet/Generated/Length.generated.cs similarity index 57% rename from Src/UnitsNet/Length.cs rename to Src/UnitsNet/Generated/Length.generated.cs index f24c926e9a..72e1d8e876 100644 --- a/Src/UnitsNet/Length.cs +++ b/Src/UnitsNet/Generated/Length.generated.cs @@ -1,307 +1,285 @@ -// Copyright © 2007 by Initial Force AS. All rights reserved. -// https://github.com/InitialForce/SIUnits -// -// 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; - -namespace UnitsNet -{ - /// - /// A class for representing units of length. - /// - public struct Length : IComparable, IComparable - { - public readonly double Meters; - private const double MilsToMetersRatio = 2.54E-5; - private const double MicroinchToMeterRatio = 2.54E-8; - - /// - /// Enforce static methods for creation. - /// - private Length(double meters) : this() - { - Meters = meters; - } - - #region Unit Properties - - public double Miles - { - get { return Meters*0.000621371; } - } - - public double Yards - { - get { return Meters*1.09361; } - } - - public double Feet - { - get { return Meters*3.28084; } - } - - public double Inches - { - get { return Meters*39.3701; } - } - - public double Kilometers - { - get { return Meters*1E-3; } - } - - public double Decimeters - { - get { return Meters*1E1; } - } - - public double Centimeters - { - get { return Meters*1E2; } - } - - public double Millimeters - { - get { return Meters*1E3; } - } - - public double Micrometers - { - get { return Meters*1E6; } - } - - public double Nanometers - { - get { return Meters*1E9; } - } - - public double Microinches - { - get { return Meters / MicroinchToMeterRatio; } - } - - public double Mils - { - get { return Meters / MilsToMetersRatio; } - } - - #endregion - - #region Static - - /// - /// The maximum representable distance in meters. - /// - public static Length Max - { - get { return new Length(double.MaxValue); } - } - - /// - /// The smallest representable distance in meters. - /// - public static Length Min - { - get { return new Length(double.MinValue); } - } - - public static Length Zero - { - get { return new Length(); } - } - - public static Length FromKilometers(double km) - { - return new Length(km*1E3); - } - - public static Length FromMiles(double m) - { - return new Length(m*1609.34); - } - - public static Length FromYards(double yds) - { - return new Length(yds*0.9144); - } - - public static Length FromFeet(double ft) - { - return new Length(ft*0.3048); - } - - public static Length FromInches(double @in) - { - return new Length(@in*0.0254); - } - - public static Length FromMeters(double m) - { - return new Length(m); - } - - public static Length FromDecimeters(double dm) - { - return new Length(dm*1E-1); - } - - public static Length FromCentimeters(double cm) - { - return FromMeters(cm*1E-2); - } - - public static Length FromMillimeters(double mm) - { - return FromMeters(mm*1E-3); - } - - public static Length FromMicrometers(double um) - { - return FromMeters(um*1E-6); - } - - public static Length FromNanometers(double nm) - { - return FromMeters(nm*1E-9); - } - - public static Length FromMicroinches(double mi) - { - return FromMeters(mi * MicroinchToMeterRatio); - } - - public static Length FromMils(double mils) - { - return FromMeters(mils*MilsToMetersRatio); - } - - #endregion - - #region Arithmetic operators - - public static Length operator -(Length right) - { - return FromMeters(-right.Meters); - } - - public static Length operator +(Length left, Length right) - { - return FromMeters(left.Meters + right.Meters); - } - - public static Length operator -(Length left, Length right) - { - return FromMeters(left.Meters - right.Meters); - } - - public static Length operator *(double left, Length right) - { - return FromMeters(left*right.Meters); - } - - public static Length operator *(Length left, double right) - { - return FromMeters(left.Meters*right); - } - - public static Length operator /(Length left, double right) - { - return FromMeters(left.Meters/right); - } - - public static double operator /(Length left, Length right) - { - return left.Meters/right.Meters; - } - - #endregion - - #region Comparison / Equality Operators - - public static bool operator <=(Length left, Length right) - { - return left.Meters <= right.Meters; - } - - public static bool operator >=(Length left, Length right) - { - return left.Meters >= right.Meters; - } - - public static bool operator <(Length left, Length right) - { - return left.Meters < right.Meters; - } - - public static bool operator >(Length left, Length right) - { - return left.Meters > right.Meters; - } - - public static bool operator !=(Length left, Length right) - { - return left.Meters != right.Meters; - } - - public static bool operator ==(Length left, Length right) - { - return left.Meters == right.Meters; - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Length)) throw new ArgumentException("Expected type Length.", "obj"); - return CompareTo((Length) obj); - } - - public int CompareTo(Length other) - { - return Meters.CompareTo(other.Meters); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is Length && ((Length) obj).Meters.Equals(Meters); - } - - public bool Equals(Length other) - { - return other.Meters == Meters; - } - - public override int GetHashCode() - { - return Meters.GetHashCode(); - } - - #endregion - - public override string ToString() - { - return string.Format("{0:0.##} {1}", Meters, UnitSystem.Create().GetDefaultAbbreviation(Unit.Meter)); - } - } -} \ No newline at end of file +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// Many different units of length have been used around the world. The main units in modern use are U.S. customary units in the United States and the Metric system elsewhere. British Imperial units are still used for some purposes in the United Kingdom and some other countries. The metric system is sub-divided into SI and non-SI units. + /// + public partial struct Length : IComparable, IComparable + { + /// + /// Base unit of Length in meters. + /// + public readonly double Meters; + + public Length(double meters) : this() + { + Meters = meters; + } + + #region Unit Properties + + public double Centimeters + { + get { return Meters/0.01; } + } + + public double Decimeters + { + get { return Meters/0.1; } + } + + public double Feet + { + get { return Meters/0.3048; } + } + + public double Inches + { + get { return Meters/0.0254; } + } + + public double Kilometers + { + get { return Meters/1000; } + } + + public double Microinches + { + get { return Meters/2.54E-08; } + } + + public double Micrometers + { + get { return Meters/1E-06; } + } + + public double Mils + { + get { return Meters/2.54E-05; } + } + + public double Miles + { + get { return Meters/1609.34; } + } + + public double Millimeters + { + get { return Meters/0.001; } + } + + public double Nanometers + { + get { return Meters/1E-09; } + } + + public double Yards + { + get { return Meters/0.9144; } + } + + #endregion + + #region Static + + public static Length Zero + { + get { return new Length(); } + } + + public static Length FromCentimeters(double centimeters) + { + return new Length(centimeters*0.01); + } + + public static Length FromDecimeters(double decimeters) + { + return new Length(decimeters*0.1); + } + + public static Length FromFeet(double feet) + { + return new Length(feet*0.3048); + } + + public static Length FromInches(double inches) + { + return new Length(inches*0.0254); + } + + public static Length FromKilometers(double kilometers) + { + return new Length(kilometers*1000); + } + + public static Length FromMeters(double meters) + { + return new Length(meters*1); + } + + public static Length FromMicroinches(double microinches) + { + return new Length(microinches*2.54E-08); + } + + public static Length FromMicrometers(double micrometers) + { + return new Length(micrometers*1E-06); + } + + public static Length FromMils(double mils) + { + return new Length(mils*2.54E-05); + } + + public static Length FromMiles(double miles) + { + return new Length(miles*1609.34); + } + + public static Length FromMillimeters(double millimeters) + { + return new Length(millimeters*0.001); + } + + public static Length FromNanometers(double nanometers) + { + return new Length(nanometers*1E-09); + } + + public static Length FromYards(double yards) + { + return new Length(yards*0.9144); + } + + #endregion + + #region Arithmetic Operators + + public static Length operator -(Length right) + { + return new Length(-right.Meters); + } + + public static Length operator +(Length left, Length right) + { + return new Length(left.Meters + right.Meters); + } + + public static Length operator -(Length left, Length right) + { + return new Length(left.Meters - right.Meters); + } + + public static Length operator *(double left, Length right) + { + return new Length(left*right.Meters); + } + + public static Length operator *(Length left, double right) + { + return new Length(left.Meters*right); + } + + public static Length operator /(Length left, double right) + { + return new Length(left.Meters/right); + } + + public static double operator /(Length left, Length right) + { + return left.Meters/right.Meters; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Length)) throw new ArgumentException("Expected type Length.", "obj"); + return CompareTo((Length) obj); + } + + public int CompareTo(Length other) + { + return Meters.CompareTo(other.Meters); + } + + public static bool operator <=(Length left, Length right) + { + return left.Meters <= right.Meters; + } + + public static bool operator >=(Length left, Length right) + { + return left.Meters >= right.Meters; + } + + public static bool operator <(Length left, Length right) + { + return left.Meters < right.Meters; + } + + public static bool operator >(Length left, Length right) + { + return left.Meters > right.Meters; + } + + public static bool operator ==(Length left, Length right) + { + return left.Meters == right.Meters; + } + + public static bool operator !=(Length left, Length right) + { + return left.Meters != right.Meters; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return Meters.Equals(((Length) obj).Meters); + } + + public override int GetHashCode() + { + return Meters.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", Meters, UnitSystem.Create().GetDefaultAbbreviation(Unit.Meter)); + } + } +} diff --git a/Src/UnitsNet/Mass.cs b/Src/UnitsNet/Generated/Mass.generated.cs similarity index 50% rename from Src/UnitsNet/Mass.cs rename to Src/UnitsNet/Generated/Mass.generated.cs index 87610eb58f..e0da1ff927 100644 --- a/Src/UnitsNet/Mass.cs +++ b/Src/UnitsNet/Generated/Mass.generated.cs @@ -1,322 +1,275 @@ -// Copyright © 2007 by Initial Force AS. All rights reserved. -// https://github.com/InitialForce/SIUnits -// -// 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; - -namespace UnitsNet -{ - /// - /// A class for representing mass. - /// - public struct Mass : IComparable, IComparable - { - private const double ShortTonToKilogramsRatio = 907.18474; - private const double LongTonToKilogramRatio = 1016.0469088; - - /// - /// Returns a kilogram representation of the mass instance. - /// - public readonly double Kilograms; - - private Mass(double kilograms) - { - Kilograms = kilograms; - } - - /// - /// The short ton is a unit of mass equal to 2,000 pounds (907.18474 kg), that is most commonly used in the United States – known there simply as the ton. - /// - /// http://en.wikipedia.org/wiki/Short_ton - public double ShortTons - { - get { return Kilograms/ShortTonToKilogramsRatio; } - } - - /// - /// Long ton (weight ton or Imperial ton) is a unit of mass equal to 2,240 pounds (1,016 kg) and is the name for the unit called the "ton" in the avoirdupois or Imperial system of measurements that was used in the United Kingdom and several other Commonwealth countries before metrication. - /// - /// http://en.wikipedia.org/wiki/Long_ton - public double LongTons - { - get { return Kilograms/LongTonToKilogramRatio; } - } - - public double Megatonnes - { - get { return Kilograms*1E-9; } - } - - public double Kilotonnes - { - get { return Kilograms*1E-6; } - } - - public double Tonnes - { - get { return Kilograms*1E-3; } - } - - public double Hectograms - { - get { return Kilograms*1E1; } - } - - public double Decagrams - { - get { return Kilograms*1E2; } - } - - public double Grams - { - get { return Kilograms*1E3; } - } - - public double Decigrams - { - get { return Kilograms*1E4; } - } - - public double Centigrams - { - get { return Kilograms*1E5; } - } - - public double Milligrams - { - get { return Kilograms*1E6; } - } - - #region Static - - /// - /// The maximum representable distance in kilograms. - /// - public static Mass Max - { - get { return new Mass(double.MaxValue); } - } - - /// - /// The smallest representable distance in kilograms. - /// - public static Mass Min - { - get { return new Mass(double.MinValue); } - } - - public static Mass Zero - { - get { return new Mass(); } - } - - - public static Mass FromMegatonnes(double megatonnes) - { - return new Mass(megatonnes*1E9); - } - - public static Mass FromKilotonnes(double kt) - { - return new Mass(kt*1E6); - } - - public static Mass FromTonnes(double t) - { - return new Mass(t*1E3); - } - - public static Mass FromKilograms(double kilograms) - { - return new Mass(kilograms); - } - - public static Mass FromHectograms(double value) - { - return new Mass(value*1E-1); - } - - public static Mass FromDecagrams(double value) - { - return new Mass(value*1E-2); - } - - public static Mass FromGrams(double value) - { - return new Mass(value*1E-3); - } - - public static Mass FromDecigrams(double value) - { - return new Mass(value*1E-4); - } - - public static Mass FromCentigrams(double value) - { - return new Mass(value*1E-5); - } - - public static Mass FromMilligrams(double value) - { - return new Mass(value*1E-6); - } - - public static Mass FromGravitationalForce(Force f) - { - return new Mass(f.KilogramForce); - } - - /// - /// Long ton (weight ton or Imperial ton) is a unit of mass equal to 2,240 pounds (1,016 kg) and is the name for the unit called the "ton" in the avoirdupois or Imperial system of measurements that was used in the United Kingdom and several other Commonwealth countries before metrication. - /// - /// http://en.wikipedia.org/wiki/Long_ton - public static Mass FromLongTons(double value) - { - return new Mass(value*LongTonToKilogramRatio); - } - - /// - /// The short ton is a unit of mass equal to 2,000 pounds (907.18474 kg), that is most commonly used in the United States – known there simply as the ton. - /// - /// http://en.wikipedia.org/wiki/Short_ton - public static Mass FromShortTons(double value) - { - return new Mass(value*ShortTonToKilogramsRatio); - } - - #endregion - - #region Arithmetic operators - - /// - /// This operator overload is only intended to be used like -MyDistance, and will - /// throw an exception if left side is anything but zero. - /// - /// The SIMass to negativize. - /// - public static Mass operator -(Mass right) - { - return new Mass(-right.Kilograms); - } - - public static Mass operator +(Mass left, Mass right) - { - return new Mass(left.Kilograms + right.Kilograms); - } - - public static Mass operator -(Mass left, Mass right) - { - return new Mass(left.Kilograms - right.Kilograms); - } - - public static Mass operator *(Mass left, double right) - { - return new Mass(left.Kilograms*right); - } - - public static Mass operator *(double left, Mass right) - { - return new Mass(left*right.Kilograms); - } - - public static double operator /(Mass left, Mass right) - { - return left.Kilograms/right.Kilograms; - } - - public static Mass operator /(Mass left, double right) - { - return new Mass(left.Kilograms/right); - } - - #endregion - - #region Comparison / Equality Operators - - public static bool operator <=(Mass left, Mass right) - { - return left.Kilograms <= right.Kilograms; - } - - public static bool operator >=(Mass left, Mass right) - { - return left.Kilograms >= right.Kilograms; - } - - public static bool operator <(Mass left, Mass right) - { - return left.Kilograms < right.Kilograms; - } - - public static bool operator >(Mass left, Mass right) - { - return left.Kilograms > right.Kilograms; - } - - public static bool operator !=(Mass left, Mass right) - { - return left.Kilograms != right.Kilograms; - } - - public static bool operator ==(Mass left, Mass right) - { - return left.Kilograms == right.Kilograms; - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Mass)) throw new ArgumentException("Expected type Mass.", "obj"); - return CompareTo((Mass) obj); - } - - public int CompareTo(Mass other) - { - return Kilograms.CompareTo(other.Kilograms); - } - - public bool Equals(Mass other) - { - return Kilograms.Equals(other.Kilograms); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is Mass && ((Mass) obj).Kilograms.Equals(Kilograms); - } - - public override int GetHashCode() - { - return Kilograms.GetHashCode(); - } - - #endregion - - public override string ToString() - { - return string.Format("{0:0.##} {1}", Kilograms, UnitSystem.Create().GetDefaultAbbreviation(Unit.Kilogram)); - } - } -} \ No newline at end of file +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// In physics, mass (from Greek μᾶζα "barley cake, lump [of dough]") is a property of a physical system or body, giving rise to the phenomena of the body's resistance to being accelerated by a force and the strength of its mutual gravitational attraction with other bodies. Instruments such as mass balances or scales use those phenomena to measure mass. The SI unit of mass is the kilogram (kg). + /// + public partial struct Mass : IComparable, IComparable + { + /// + /// Base unit of Mass in kilograms. + /// + public readonly double Kilograms; + + public Mass(double kilograms) : this() + { + Kilograms = kilograms; + } + + #region Unit Properties + + public double Centigrams + { + get { return Kilograms/1E-05; } + } + + public double Decagrams + { + get { return Kilograms/0.01; } + } + + public double Decigrams + { + get { return Kilograms/0.0001; } + } + + public double Grams + { + get { return Kilograms/0.001; } + } + + public double Hectograms + { + get { return Kilograms/0.1; } + } + + public double Kilotonnes + { + get { return Kilograms/1000000; } + } + + public double LongTons + { + get { return Kilograms/1016.0469088; } + } + + public double Megatonnes + { + get { return Kilograms/1000000000; } + } + + public double Milligrams + { + get { return Kilograms/1E-06; } + } + + public double ShortTons + { + get { return Kilograms/907.18474; } + } + + public double Tonnes + { + get { return Kilograms/1000; } + } + + #endregion + + #region Static + + public static Mass Zero + { + get { return new Mass(); } + } + + public static Mass FromCentigrams(double centigrams) + { + return new Mass(centigrams*1E-05); + } + + public static Mass FromDecagrams(double decagrams) + { + return new Mass(decagrams*0.01); + } + + public static Mass FromDecigrams(double decigrams) + { + return new Mass(decigrams*0.0001); + } + + public static Mass FromGrams(double grams) + { + return new Mass(grams*0.001); + } + + public static Mass FromHectograms(double hectograms) + { + return new Mass(hectograms*0.1); + } + + public static Mass FromKilograms(double kilograms) + { + return new Mass(kilograms*1); + } + + public static Mass FromKilotonnes(double kilotonnes) + { + return new Mass(kilotonnes*1000000); + } + + public static Mass FromLongTons(double longtons) + { + return new Mass(longtons*1016.0469088); + } + + public static Mass FromMegatonnes(double megatonnes) + { + return new Mass(megatonnes*1000000000); + } + + public static Mass FromMilligrams(double milligrams) + { + return new Mass(milligrams*1E-06); + } + + public static Mass FromShortTons(double shorttons) + { + return new Mass(shorttons*907.18474); + } + + public static Mass FromTonnes(double tonnes) + { + return new Mass(tonnes*1000); + } + + #endregion + + #region Arithmetic Operators + + public static Mass operator -(Mass right) + { + return new Mass(-right.Kilograms); + } + + public static Mass operator +(Mass left, Mass right) + { + return new Mass(left.Kilograms + right.Kilograms); + } + + public static Mass operator -(Mass left, Mass right) + { + return new Mass(left.Kilograms - right.Kilograms); + } + + public static Mass operator *(double left, Mass right) + { + return new Mass(left*right.Kilograms); + } + + public static Mass operator *(Mass left, double right) + { + return new Mass(left.Kilograms*right); + } + + public static Mass operator /(Mass left, double right) + { + return new Mass(left.Kilograms/right); + } + + public static double operator /(Mass left, Mass right) + { + return left.Kilograms/right.Kilograms; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Mass)) throw new ArgumentException("Expected type Mass.", "obj"); + return CompareTo((Mass) obj); + } + + public int CompareTo(Mass other) + { + return Kilograms.CompareTo(other.Kilograms); + } + + public static bool operator <=(Mass left, Mass right) + { + return left.Kilograms <= right.Kilograms; + } + + public static bool operator >=(Mass left, Mass right) + { + return left.Kilograms >= right.Kilograms; + } + + public static bool operator <(Mass left, Mass right) + { + return left.Kilograms < right.Kilograms; + } + + public static bool operator >(Mass left, Mass right) + { + return left.Kilograms > right.Kilograms; + } + + public static bool operator ==(Mass left, Mass right) + { + return left.Kilograms == right.Kilograms; + } + + public static bool operator !=(Mass left, Mass right) + { + return left.Kilograms != right.Kilograms; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return Kilograms.Equals(((Mass) obj).Kilograms); + } + + public override int GetHashCode() + { + return Kilograms.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", Kilograms, UnitSystem.Create().GetDefaultAbbreviation(Unit.Kilogram)); + } + } +} diff --git a/Src/UnitsNet/Generated/MultipleOutputHelper.ttinclude b/Src/UnitsNet/Generated/MultipleOutputHelper.ttinclude new file mode 100644 index 0000000000..4ffb05215d --- /dev/null +++ b/Src/UnitsNet/Generated/MultipleOutputHelper.ttinclude @@ -0,0 +1,196 @@ +<#@ assembly name="System.Core" +#><#@ assembly name="System.Data.Linq" +#><#@ assembly name="EnvDTE" +#><#@ assembly name="System.Xml" +#><#@ assembly name="System.Xml.Linq" +#><#@ import namespace="System" +#><#@ import namespace="System.CodeDom" +#><#@ import namespace="System.CodeDom.Compiler" +#><#@ import namespace="System.Collections.Generic" +#><#@ import namespace="System.Data.Linq" +#><#@ import namespace="System.Data.Linq.Mapping" +#><#@ import namespace="System.IO" +#><#@ import namespace="System.Linq" +#><#@ import namespace="System.Reflection" +#><#@ import namespace="System.Text" +#><#@ import namespace="System.Xml.Linq" +#><#@ import namespace="Microsoft.VisualStudio.TextTemplating" +#><#+ + +// Manager class records the various blocks so it can split them up +class Manager { + private class Block { + public String Name; + public int Start, Length; + } + + private Block currentBlock; + private List files = new List(); + private Block footer = new Block(); + private Block header = new Block(); + private ITextTemplatingEngineHost host; + private StringBuilder template; + protected List generatedFileNames = new List(); + + public static Manager Create(ITextTemplatingEngineHost host, StringBuilder template) { + return (host is IServiceProvider) ? new VSManager(host, template) : new Manager(host, template); + } + + + public IDisposable StartNewFile(String name) { + if (name == null) + throw new ArgumentNullException("name"); + CurrentBlock = new Block { Name = name }; + return new StartNewFileBlock(this); + } + + public void StartFooter() { + CurrentBlock = footer; + } + + public void StartHeader() { + CurrentBlock = header; + } + + public void EndBlock() { + if (CurrentBlock == null) + return; + CurrentBlock.Length = template.Length - CurrentBlock.Start; + if (CurrentBlock != header && CurrentBlock != footer) + files.Add(CurrentBlock); + currentBlock = null; + } + + public virtual void Process(bool split) { + if (split) { + EndBlock(); + String headerText = template.ToString(header.Start, header.Length); + String footerText = template.ToString(footer.Start, footer.Length); + String outputPath = Path.GetDirectoryName(host.TemplateFile); + files.Reverse(); + foreach(Block block in files) { + String fileName = Path.Combine(outputPath, block.Name); + String content = headerText + template.ToString(block.Start, block.Length) + footerText; + generatedFileNames.Add(fileName); + CreateFile(fileName, content); + template.Remove(block.Start, block.Length); + } + } + } + + protected virtual void CreateFile(String fileName, String content) { + if (IsFileContentDifferent(fileName, content)) + File.WriteAllText(fileName, content); + } + + public virtual String GetCustomToolNamespace(String fileName) { + return null; + } + + public virtual String DefaultProjectNamespace { + get { return null; } + } + + protected bool IsFileContentDifferent(String fileName, String newContent) { + return !(File.Exists(fileName) && File.ReadAllText(fileName) == newContent); + } + + private Manager(ITextTemplatingEngineHost host, StringBuilder template) { + this.host = host; + this.template = template; + } + + private Block CurrentBlock { + get { return currentBlock; } + set { + if (CurrentBlock != null) + EndBlock(); + if (value != null) + value.Start = template.Length; + currentBlock = value; + } + } + + private class VSManager: Manager { + private EnvDTE.ProjectItem templateProjectItem; + private EnvDTE.DTE dte; + private Action checkOutAction; + private Action> projectSyncAction; + + public override String DefaultProjectNamespace { + get { + return templateProjectItem.ContainingProject.Properties.Item("DefaultNamespace").Value.ToString(); + } + } + + public override String GetCustomToolNamespace(string fileName) { + return dte.Solution.FindProjectItem(fileName).Properties.Item("CustomToolNamespace").Value.ToString(); + } + + public override void Process(bool split) { + if (templateProjectItem.ProjectItems == null) + return; + base.Process(split); + projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(generatedFileNames, null, null)); + } + + protected override void CreateFile(String fileName, String content) { + if (IsFileContentDifferent(fileName, content)) { + CheckoutFileIfRequired(fileName); + File.WriteAllText(fileName, content); + } + } + + internal VSManager(ITextTemplatingEngineHost host, StringBuilder template) + : base(host, template) { + var hostServiceProvider = (IServiceProvider) host; + if (hostServiceProvider == null) + throw new ArgumentNullException("Could not obtain IServiceProvider"); + dte = (EnvDTE.DTE) hostServiceProvider.GetService(typeof(EnvDTE.DTE)); + if (dte == null) + throw new ArgumentNullException("Could not obtain DTE from host"); + templateProjectItem = dte.Solution.FindProjectItem(host.TemplateFile); + checkOutAction = (String fileName) => dte.SourceControl.CheckOutItem(fileName); + projectSyncAction = (IEnumerable keepFileNames) => ProjectSync(templateProjectItem, keepFileNames); + } + + private static void ProjectSync(EnvDTE.ProjectItem templateProjectItem, IEnumerable keepFileNames) { + var keepFileNameSet = new HashSet(keepFileNames); + var projectFiles = new Dictionary(); + var originalFilePrefix = Path.GetFileNameWithoutExtension(templateProjectItem.get_FileNames(0)) + "."; + foreach(EnvDTE.ProjectItem projectItem in templateProjectItem.ProjectItems) + projectFiles.Add(projectItem.get_FileNames(0), projectItem); + + // Remove unused items from the project + foreach(var pair in projectFiles) + if (!keepFileNames.Contains(pair.Key) && !(Path.GetFileNameWithoutExtension(pair.Key) + ".").StartsWith(originalFilePrefix)) + pair.Value.Delete(); + + // Add missing files to the project + foreach(String fileName in keepFileNameSet) + if (!projectFiles.ContainsKey(fileName)) + templateProjectItem.ProjectItems.AddFromFile(fileName); + } + + private void CheckoutFileIfRequired(String fileName) { + var sc = dte.SourceControl; + if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName)) + checkOutAction.EndInvoke(checkOutAction.BeginInvoke(fileName, null, null)); + } + } + + private class StartNewFileBlock : IDisposable + { + private readonly Manager _manager; + + public StartNewFileBlock(Manager manager) + { + _manager = manager; + } + + public void Dispose() + { + _manager.EndBlock(); + } + } +} #> \ No newline at end of file diff --git a/Src/UnitsNet/Pressure.cs b/Src/UnitsNet/Generated/Pressure.generated.cs similarity index 57% rename from Src/UnitsNet/Pressure.cs rename to Src/UnitsNet/Generated/Pressure.generated.cs index 4d3f2798bc..e5ddc79dc3 100644 --- a/Src/UnitsNet/Pressure.cs +++ b/Src/UnitsNet/Generated/Pressure.generated.cs @@ -1,313 +1,275 @@ -// Copyright © 2007 by Initial Force AS. All rights reserved. -// https://github.com/InitialForce/SIUnits -// -// 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; - -namespace UnitsNet -{ - /// - /// A class for representing force. - /// - public struct Pressure : IComparable, IComparable - { - private const double KpaToPaRatio = 1000; - private const double MpaToPaRatio = 1000000; - private const double Nm2ToPaRatio = 1; - private const double Ncm2ToPaRatio = 1E+4; - private const double Nmm2ToPaRatio = 1E+6; - private const double BarToPaRatio = 1E+5; - private const double TaToPaRatio = 9.80680592331*1E4; - private const double AtmToPaRatio = 101325; - private const double TorrToPaRatio = 1.3332266752*1E2; - private const double PsiToPaRatio = 6.89464975179*1E3; - private const double KFSCToPaRatio = 98066.5; - - /// - /// Pressure in pascal. - /// - public readonly double Pascals; - - public Pressure(double pascals) : this() - { - Pascals = pascals; - } - - #region Unit Properties - - public double KiloPascals - { - get { return Pascals/KpaToPaRatio; } - } - - public double MegaPascals - { - get { return Pascals / MpaToPaRatio; } - } - - public double KilogramForcePerSquareCentimeter - { - get { return Pascals / KFSCToPaRatio; } - } - - public double NewtonsPerSquareMeter - { - get { return Pascals/Nm2ToPaRatio; } - } - - public double NewtonsPerSquareCentimeter - { - get { return Pascals/Ncm2ToPaRatio; } - } - - public double NewtonsPerSquareMillimeter - { - get { return Pascals/Nmm2ToPaRatio; } - } - - public double Bars - { - get { return Pascals/BarToPaRatio; } - } - - public double TechnicalAtmosphere - { - get { return Pascals/TaToPaRatio; } - } - - public double Atmosphere - { - get { return Pascals/AtmToPaRatio; } - } - - public double Torr - { - get { return Pascals/TorrToPaRatio; } - } - - public double Psi - { - get { return Pascals/PsiToPaRatio; } - } - - #endregion - - #region Static - - /// - /// The maximum representable distance in pascals. - /// - public static Pressure Max - { - get { return new Pressure(double.MaxValue); } - } - - /// - /// The smallest representable distance in pascals. - /// - public static Pressure Min - { - get { return new Pressure(double.MinValue); } - } - - public static Pressure Zero - { - get { return new Pressure(0); } - } - - public static Pressure FromPascals(double pascals) - { - return new Pressure(pascals); - } - - public static Pressure FromKiloPascals(double kpa) - { - return new Pressure(KpaToPaRatio*kpa); - } - - public static Pressure FromMegaPascals(double mpa) - { - return new Pressure(MpaToPaRatio * mpa); - } - - public static Pressure FromKilogramForcePerSquareCentimeter(double kfsc) - { - return new Pressure(KFSCToPaRatio * kfsc); - } - - public static Pressure FromNewtonsPerSquareCentimeter(double nsc) - { - return new Pressure(Ncm2ToPaRatio*nsc); - } - - public static Pressure FromNewtonsPerSquareMeter(double nm2) - { - return new Pressure(Nm2ToPaRatio*nm2); - } - - public static Pressure FromNewtonsPerSquareMillimeter(double nmm2) - { - return new Pressure(Nmm2ToPaRatio*nmm2); - } - - public static Pressure FromBars(double bars) - { - return new Pressure(BarToPaRatio*bars); - } - - public static Pressure FromTechnicalAtmosphere(double ta) - { - return new Pressure(TaToPaRatio*ta); - } - - public static Pressure FromAtmosphere(double atm) - { - return new Pressure(AtmToPaRatio*atm); - } - - public static Pressure FromTorr(double torr) - { - return new Pressure(TorrToPaRatio*torr); - } - - public static Pressure FromPsi(double psi) - { - return new Pressure(PsiToPaRatio*psi); - } - - #endregion - - #region Arithmetic operators - - /// - /// This operator overload is only intended to be used like -MyDistance, and will - /// throw an exception if left side is anything but zero. - /// - /// The SIPressure to negativize. - /// - public static Pressure operator -(Pressure right) - { - return new Pressure(-right.Pascals); - } - - public static Pressure operator +(Pressure left, Pressure right) - { - return new Pressure(left.Pascals + right.Pascals); - } - - public static Pressure operator -(Pressure left, Pressure right) - { - return new Pressure(left.Pascals - right.Pascals); - } - - public static Pressure operator *(Pressure left, double right) - { - return new Pressure(left.Pascals*right); - } - - public static Pressure operator *(double left, Pressure right) - { - return new Pressure(left*right.Pascals); - } - - public static Pressure operator /(Pressure left, double right) - { - return new Pressure(left.Pascals/right); - } - - public static double operator /(Pressure left, Pressure right) - { - return left.Pascals/right.Pascals; - } - - #endregion - - #region Comparison / Equality Operators - - public static bool operator <=(Pressure left, Pressure right) - { - return left.Pascals <= right.Pascals; - } - - public static bool operator >=(Pressure left, Pressure right) - { - return left.Pascals >= right.Pascals; - } - - public static bool operator <(Pressure left, Pressure right) - { - return left.Pascals < right.Pascals; - } - - public static bool operator >(Pressure left, Pressure right) - { - return left.Pascals > right.Pascals; - } - - public static bool operator !=(Pressure left, Pressure right) - { - return left.Pascals != right.Pascals; - } - - public static bool operator ==(Pressure left, Pressure right) - { - return left.Pascals == right.Pascals; - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Pressure)) throw new ArgumentException("Expected type Pressure.", "obj"); - return CompareTo((Pressure) obj); - } - - public int CompareTo(Pressure other) - { - return Pascals.CompareTo(other.Pascals); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is Pressure && ((Pressure) obj).Pascals.Equals(Pascals); - } - - public bool Equals(Pressure other) - { - return other.Pascals == Pascals; - } - - public override int GetHashCode() - { - return Pascals.GetHashCode(); - } - - #endregion - - public override string ToString() - { - return string.Format("{0:0.##} {1}", Pascals, UnitSystem.Create().GetDefaultAbbreviation(Unit.Pascal)); - } - } -} \ No newline at end of file +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// Pressure (symbol: P or p) is the ratio of force to the area over which that force is distributed. Pressure is force per unit area applied in a direction perpendicular to the surface of an object. Gauge pressure (also spelled gage pressure)[a] is the pressure relative to the local atmospheric or ambient pressure. Pressure is measured in any unit of force divided by any unit of area. The SI unit of pressure is the newton per square metre, which is called the pascal (Pa) after the seventeenth-century philosopher and scientist Blaise Pascal. A pressure of 1 Pa is small; it approximately equals the pressure exerted by a dollar bill resting flat on a table. Everyday pressures are often stated in kilopascals (1 kPa = 1000 Pa). + /// + public partial struct Pressure : IComparable, IComparable + { + /// + /// Base unit of Pressure in pascals. + /// + public readonly double Pascals; + + public Pressure(double pascals) : this() + { + Pascals = pascals; + } + + #region Unit Properties + + public double Atmospheres + { + get { return Pascals/101325; } + } + + public double Bars + { + get { return Pascals/100000; } + } + + public double KilogramForcePerSquareCentimeter + { + get { return Pascals/98066.5; } + } + + public double Kilopascals + { + get { return Pascals/1000; } + } + + public double Megapascals + { + get { return Pascals/1000000; } + } + + public double NewtonsPerSquareCentimeter + { + get { return Pascals/10000; } + } + + public double NewtonsPerSquareMeter + { + get { return Pascals/1; } + } + + public double NewtonsPerSquareMillimeter + { + get { return Pascals/1000000; } + } + + public double Psi + { + get { return Pascals/6894.64975179; } + } + + public double TechnicalAtmospheres + { + get { return Pascals/98068.0592331; } + } + + public double Torrs + { + get { return Pascals/133.32266752; } + } + + #endregion + + #region Static + + public static Pressure Zero + { + get { return new Pressure(); } + } + + public static Pressure FromAtmospheres(double atmospheres) + { + return new Pressure(atmospheres*101325); + } + + public static Pressure FromBars(double bars) + { + return new Pressure(bars*100000); + } + + public static Pressure FromKilogramForcePerSquareCentimeter(double kilogramforcepersquarecentimeter) + { + return new Pressure(kilogramforcepersquarecentimeter*98066.5); + } + + public static Pressure FromKilopascals(double kilopascals) + { + return new Pressure(kilopascals*1000); + } + + public static Pressure FromMegapascals(double megapascals) + { + return new Pressure(megapascals*1000000); + } + + public static Pressure FromNewtonsPerSquareCentimeter(double newtonspersquarecentimeter) + { + return new Pressure(newtonspersquarecentimeter*10000); + } + + public static Pressure FromNewtonsPerSquareMeter(double newtonspersquaremeter) + { + return new Pressure(newtonspersquaremeter*1); + } + + public static Pressure FromNewtonsPerSquareMillimeter(double newtonspersquaremillimeter) + { + return new Pressure(newtonspersquaremillimeter*1000000); + } + + public static Pressure FromPascals(double pascals) + { + return new Pressure(pascals*1); + } + + public static Pressure FromPsi(double psi) + { + return new Pressure(psi*6894.64975179); + } + + public static Pressure FromTechnicalAtmospheres(double technicalatmospheres) + { + return new Pressure(technicalatmospheres*98068.0592331); + } + + public static Pressure FromTorrs(double torrs) + { + return new Pressure(torrs*133.32266752); + } + + #endregion + + #region Arithmetic Operators + + public static Pressure operator -(Pressure right) + { + return new Pressure(-right.Pascals); + } + + public static Pressure operator +(Pressure left, Pressure right) + { + return new Pressure(left.Pascals + right.Pascals); + } + + public static Pressure operator -(Pressure left, Pressure right) + { + return new Pressure(left.Pascals - right.Pascals); + } + + public static Pressure operator *(double left, Pressure right) + { + return new Pressure(left*right.Pascals); + } + + public static Pressure operator *(Pressure left, double right) + { + return new Pressure(left.Pascals*right); + } + + public static Pressure operator /(Pressure left, double right) + { + return new Pressure(left.Pascals/right); + } + + public static double operator /(Pressure left, Pressure right) + { + return left.Pascals/right.Pascals; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Pressure)) throw new ArgumentException("Expected type Pressure.", "obj"); + return CompareTo((Pressure) obj); + } + + public int CompareTo(Pressure other) + { + return Pascals.CompareTo(other.Pascals); + } + + public static bool operator <=(Pressure left, Pressure right) + { + return left.Pascals <= right.Pascals; + } + + public static bool operator >=(Pressure left, Pressure right) + { + return left.Pascals >= right.Pascals; + } + + public static bool operator <(Pressure left, Pressure right) + { + return left.Pascals < right.Pascals; + } + + public static bool operator >(Pressure left, Pressure right) + { + return left.Pascals > right.Pascals; + } + + public static bool operator ==(Pressure left, Pressure right) + { + return left.Pascals == right.Pascals; + } + + public static bool operator !=(Pressure left, Pressure right) + { + return left.Pascals != right.Pascals; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return Pascals.Equals(((Pressure) obj).Pascals); + } + + public override int GetHashCode() + { + return Pascals.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", Pascals, UnitSystem.Create().GetDefaultAbbreviation(Unit.Pascal)); + } + } +} diff --git a/Src/UnitsNet/RotationalSpeed.cs b/Src/UnitsNet/Generated/RotationalSpeed.generated.cs similarity index 59% rename from Src/UnitsNet/RotationalSpeed.cs rename to Src/UnitsNet/Generated/RotationalSpeed.generated.cs index 3ca37e2358..96b6be4761 100644 --- a/Src/UnitsNet/RotationalSpeed.cs +++ b/Src/UnitsNet/Generated/RotationalSpeed.generated.cs @@ -1,150 +1,175 @@ -using System; -using System.Globalization; - -namespace UnitsNet -{ - /// - /// A class for representing revolution. - /// - public struct RotationalSpeed : IComparable, IComparable - { - private const double MinuteToSecondRatio = 0.0166666666666667; - private const double SecondToMinuteRatio = 60; - - public readonly double RevolutionsPerSecond; - - private RotationalSpeed(double revolutionsPerSecond) - : this() - { - RevolutionsPerSecond = revolutionsPerSecond; - } - - public double RevolutionsPerMinute - { - get { return RevolutionsPerSecond * SecondToMinuteRatio; } - } - - #region Static - - public static RotationalSpeed Zero - { - get { return new RotationalSpeed(); } - } - - public static RotationalSpeed FromRevolutionsPerMinute(double revolutionsPerMinute) - { - return new RotationalSpeed(revolutionsPerMinute * MinuteToSecondRatio); - } - - public static RotationalSpeed FromRevolutionsPerSecond(double revolutionsPerSecond) - { - return new RotationalSpeed(revolutionsPerSecond); - } - - #endregion - - #region Equality / IComparable - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is RotationalSpeed)) throw new ArgumentException("Expected type RotationalSpeed.", "obj"); - return CompareTo((RotationalSpeed)obj); - } - - public int CompareTo(RotationalSpeed other) - { - return RevolutionsPerSecond.CompareTo(other.RevolutionsPerSecond); - } - - public static bool operator <=(RotationalSpeed left, RotationalSpeed right) - { - return left.RevolutionsPerSecond <= right.RevolutionsPerSecond; - } - - public static bool operator >=(RotationalSpeed left, RotationalSpeed right) - { - return left.RevolutionsPerSecond >= right.RevolutionsPerSecond; - } - - public static bool operator <(RotationalSpeed left, RotationalSpeed right) - { - return left.RevolutionsPerSecond < right.RevolutionsPerSecond; - } - - public static bool operator >(RotationalSpeed left, RotationalSpeed right) - { - return left.RevolutionsPerSecond > right.RevolutionsPerSecond; - } - - public static bool operator ==(RotationalSpeed left, RotationalSpeed right) - { - return left.RevolutionsPerSecond == right.RevolutionsPerSecond; - } - - public static bool operator !=(RotationalSpeed left, RotationalSpeed right) - { - return left.RevolutionsPerSecond != right.RevolutionsPerSecond; - } - - public override bool Equals(object obj) - { - if (obj == null || GetType() != obj.GetType()) - { - return false; - } - - return RevolutionsPerSecond.Equals(((RotationalSpeed)obj).RevolutionsPerSecond); - } - - public override int GetHashCode() - { - return RevolutionsPerSecond.GetHashCode(); - } - #endregion - - #region Arithmetic operators - - public static RotationalSpeed operator -(RotationalSpeed right) - { - return new RotationalSpeed(-right.RevolutionsPerSecond); - } - - public static RotationalSpeed operator +(RotationalSpeed left, RotationalSpeed right) - { - return new RotationalSpeed(left.RevolutionsPerSecond + right.RevolutionsPerSecond); - } - - public static RotationalSpeed operator -(RotationalSpeed left, RotationalSpeed right) - { - return new RotationalSpeed(left.RevolutionsPerSecond - right.RevolutionsPerSecond); - } - - public static RotationalSpeed operator *(double left, RotationalSpeed right) - { - return new RotationalSpeed(left * right.RevolutionsPerSecond); - } - - public static RotationalSpeed operator *(RotationalSpeed left, double right) - { - return new RotationalSpeed(left.RevolutionsPerSecond * right); - } - - public static RotationalSpeed operator /(RotationalSpeed left, double right) - { - return new RotationalSpeed(left.RevolutionsPerSecond / right); - } - - public static double operator /(RotationalSpeed left, RotationalSpeed right) - { - return left.RevolutionsPerSecond / right.RevolutionsPerSecond; - } - - #endregion - - public override string ToString() - { - return string.Format("{0:0.##} {1}", RevolutionsPerSecond, UnitSystem.Create().GetDefaultAbbreviation(Unit.RevolutionsPerSecond)); - } - } -} +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// Rotational speed (sometimes called speed of revolution) is the number of complete rotations, revolutions, cycles, or turns per time unit. Rotational speed is a cyclic frequency, measured in radians per second or in hertz in the SI System by scientists, or in revolutions per minute (rpm or min-1) or revolutions per second in everyday life. The symbol for rotational speed is ω (the Greek lowercase letter "omega"). + /// + public partial struct RotationalSpeed : IComparable, IComparable + { + /// + /// Base unit of RotationalSpeed in revolutionspersecond. + /// + public readonly double RevolutionsPerSecond; + + public RotationalSpeed(double revolutionspersecond) : this() + { + RevolutionsPerSecond = revolutionspersecond; + } + + #region Unit Properties + + public double RevolutionsPerMinute + { + get { return RevolutionsPerSecond/60; } + } + + #endregion + + #region Static + + public static RotationalSpeed Zero + { + get { return new RotationalSpeed(); } + } + + public static RotationalSpeed FromRevolutionsPerMinute(double revolutionsperminute) + { + return new RotationalSpeed(revolutionsperminute*60); + } + + public static RotationalSpeed FromRevolutionsPerSecond(double revolutionspersecond) + { + return new RotationalSpeed(revolutionspersecond*1); + } + + #endregion + + #region Arithmetic Operators + + public static RotationalSpeed operator -(RotationalSpeed right) + { + return new RotationalSpeed(-right.RevolutionsPerSecond); + } + + public static RotationalSpeed operator +(RotationalSpeed left, RotationalSpeed right) + { + return new RotationalSpeed(left.RevolutionsPerSecond + right.RevolutionsPerSecond); + } + + public static RotationalSpeed operator -(RotationalSpeed left, RotationalSpeed right) + { + return new RotationalSpeed(left.RevolutionsPerSecond - right.RevolutionsPerSecond); + } + + public static RotationalSpeed operator *(double left, RotationalSpeed right) + { + return new RotationalSpeed(left*right.RevolutionsPerSecond); + } + + public static RotationalSpeed operator *(RotationalSpeed left, double right) + { + return new RotationalSpeed(left.RevolutionsPerSecond*right); + } + + public static RotationalSpeed operator /(RotationalSpeed left, double right) + { + return new RotationalSpeed(left.RevolutionsPerSecond/right); + } + + public static double operator /(RotationalSpeed left, RotationalSpeed right) + { + return left.RevolutionsPerSecond/right.RevolutionsPerSecond; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is RotationalSpeed)) throw new ArgumentException("Expected type RotationalSpeed.", "obj"); + return CompareTo((RotationalSpeed) obj); + } + + public int CompareTo(RotationalSpeed other) + { + return RevolutionsPerSecond.CompareTo(other.RevolutionsPerSecond); + } + + public static bool operator <=(RotationalSpeed left, RotationalSpeed right) + { + return left.RevolutionsPerSecond <= right.RevolutionsPerSecond; + } + + public static bool operator >=(RotationalSpeed left, RotationalSpeed right) + { + return left.RevolutionsPerSecond >= right.RevolutionsPerSecond; + } + + public static bool operator <(RotationalSpeed left, RotationalSpeed right) + { + return left.RevolutionsPerSecond < right.RevolutionsPerSecond; + } + + public static bool operator >(RotationalSpeed left, RotationalSpeed right) + { + return left.RevolutionsPerSecond > right.RevolutionsPerSecond; + } + + public static bool operator ==(RotationalSpeed left, RotationalSpeed right) + { + return left.RevolutionsPerSecond == right.RevolutionsPerSecond; + } + + public static bool operator !=(RotationalSpeed left, RotationalSpeed right) + { + return left.RevolutionsPerSecond != right.RevolutionsPerSecond; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return RevolutionsPerSecond.Equals(((RotationalSpeed) obj).RevolutionsPerSecond); + } + + public override int GetHashCode() + { + return RevolutionsPerSecond.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", RevolutionsPerSecond, UnitSystem.Create().GetDefaultAbbreviation(Unit.RevolutionPerSecond)); + } + } +} diff --git a/Src/UnitsNet/Torque.cs b/Src/UnitsNet/Generated/Torque.generated.cs similarity index 61% rename from Src/UnitsNet/Torque.cs rename to Src/UnitsNet/Generated/Torque.generated.cs index 692e09cf9f..6131830ac2 100644 --- a/Src/UnitsNet/Torque.cs +++ b/Src/UnitsNet/Generated/Torque.generated.cs @@ -1,127 +1,165 @@ -// Copyright © 2007 by Initial Force AS. All rights reserved. -// https://github.com/InitialForce/SIUnits -// -// 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; - -namespace UnitsNet -{ - /// - /// A class for representing torque, according to the International System of Units (SI). - /// - public struct Torque : IComparable, IComparable - { - /// - /// Returns a newtonmeter representation of the torque. - /// - public readonly double Newtonmeters; - - - private Torque(double newtonmeters) - { - Newtonmeters = newtonmeters; - } - - public override string ToString() - { - return string.Format("{0:0.##} {1}", Newtonmeters, UnitSystem.Create().GetDefaultAbbreviation(Unit.Newtonmeter)); - } - - #region Static - - public static Torque FromNewtonmeters(double newtonmeters) - { - return new Torque(newtonmeters); - } - - #endregion - - #region Arithmetic operators - - /// - /// This operator overload is only intended to be used like -MyDistance, and will - /// throw an exception if left side is anything but zero. - /// - /// The SITorque to negativize. - /// - public static Torque operator -(Torque right) - { - return new Torque(-right.Newtonmeters); - } - - public static Torque operator +(Torque left, Torque right) - { - return new Torque(left.Newtonmeters + right.Newtonmeters); - } - - public static Torque operator -(Torque left, Torque right) - { - return new Torque(left.Newtonmeters - right.Newtonmeters); - } - - public static Torque operator *(double left, Torque right) - { - return new Torque(left*right.Newtonmeters); - } - - public static Torque operator /(Torque left, double right) - { - return new Torque(left.Newtonmeters/right); - } - - #endregion - - #region Equality - - public int CompareTo(object obj) - { - if (obj == null) throw new ArgumentNullException("obj"); - if (!(obj is Torque)) throw new ArgumentException("Expected type Torque.", "obj"); - return CompareTo((Torque) obj); - } - - public int CompareTo(Torque other) - { - return Newtonmeters.CompareTo(other.Newtonmeters); - } - - public static bool operator <=(Torque left, Torque right) - { - return left.Newtonmeters <= right.Newtonmeters; - } - - public static bool operator >=(Torque left, Torque right) - { - return left.Newtonmeters >= right.Newtonmeters; - } - - public static bool operator <(Torque left, Torque right) - { - return left.Newtonmeters < right.Newtonmeters; - } - - public static bool operator >(Torque left, Torque right) - { - return left.Newtonmeters > right.Newtonmeters; - } - - #endregion - } -} \ No newline at end of file +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// Torque, moment or moment of force (see the terminology below), is the tendency of a force to rotate an object about an axis,[1] fulcrum, or pivot. Just as a force is a push or a pull, a torque can be thought of as a twist to an object. Mathematically, torque is defined as the cross product of the lever-arm distance and force, which tends to produce rotation. Loosely speaking, torque is a measure of the turning force on an object such as a bolt or a flywheel. For example, pushing or pulling the handle of a wrench connected to a nut or bolt produces a torque (turning force) that loosens or tightens the nut or bolt. + /// + public partial struct Torque : IComparable, IComparable + { + /// + /// Base unit of Torque in newtonmeters. + /// + public readonly double Newtonmeters; + + public Torque(double newtonmeters) : this() + { + Newtonmeters = newtonmeters; + } + + #region Unit Properties + + #endregion + + #region Static + + public static Torque Zero + { + get { return new Torque(); } + } + + public static Torque FromNewtonmeters(double newtonmeters) + { + return new Torque(newtonmeters*1); + } + + #endregion + + #region Arithmetic Operators + + public static Torque operator -(Torque right) + { + return new Torque(-right.Newtonmeters); + } + + public static Torque operator +(Torque left, Torque right) + { + return new Torque(left.Newtonmeters + right.Newtonmeters); + } + + public static Torque operator -(Torque left, Torque right) + { + return new Torque(left.Newtonmeters - right.Newtonmeters); + } + + public static Torque operator *(double left, Torque right) + { + return new Torque(left*right.Newtonmeters); + } + + public static Torque operator *(Torque left, double right) + { + return new Torque(left.Newtonmeters*right); + } + + public static Torque operator /(Torque left, double right) + { + return new Torque(left.Newtonmeters/right); + } + + public static double operator /(Torque left, Torque right) + { + return left.Newtonmeters/right.Newtonmeters; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Torque)) throw new ArgumentException("Expected type Torque.", "obj"); + return CompareTo((Torque) obj); + } + + public int CompareTo(Torque other) + { + return Newtonmeters.CompareTo(other.Newtonmeters); + } + + public static bool operator <=(Torque left, Torque right) + { + return left.Newtonmeters <= right.Newtonmeters; + } + + public static bool operator >=(Torque left, Torque right) + { + return left.Newtonmeters >= right.Newtonmeters; + } + + public static bool operator <(Torque left, Torque right) + { + return left.Newtonmeters < right.Newtonmeters; + } + + public static bool operator >(Torque left, Torque right) + { + return left.Newtonmeters > right.Newtonmeters; + } + + public static bool operator ==(Torque left, Torque right) + { + return left.Newtonmeters == right.Newtonmeters; + } + + public static bool operator !=(Torque left, Torque right) + { + return left.Newtonmeters != right.Newtonmeters; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return Newtonmeters.Equals(((Torque) obj).Newtonmeters); + } + + public override int GetHashCode() + { + return Newtonmeters.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", Newtonmeters, UnitSystem.Create().GetDefaultAbbreviation(Unit.Newtonmeter)); + } + } +} diff --git a/Src/UnitsNet/Generated/UnitClass.ttinclude b/Src/UnitsNet/Generated/UnitClass.ttinclude new file mode 100644 index 0000000000..39b2c45ae7 --- /dev/null +++ b/Src/UnitsNet/Generated/UnitClass.ttinclude @@ -0,0 +1,255 @@ +<# // Load types in current assembly. #> +<#@ assembly name="$(TargetPath)" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="UnitsNet" #> +<#@ import namespace="UnitsNet.Extensions" #> +<#@ include file="MultipleOutputHelper.ttinclude" once="true"#> +<#+ + + private string GetUnitPluralName(Dictionary unitToAttribute, Unit unit) + { +// Use attribute value if it has a valid value, otherwise append 's' to the enum value name to get plural form (works for 90%). + UnitAttribute att = unitToAttribute[unit]; + + string baseUnitPluralName = (att != null && !string.IsNullOrWhiteSpace(att.PluralName)) + ? att.PluralName + : unit + "s"; + return baseUnitPluralName; + } + + private void GenerateUnitClass(Manager manager, string className, string classDescription, Unit baseUnit) + where TUnitAttribute : UnitAttribute + { + using (manager.StartNewFile(className+".generated.cs")) + { + Dictionary unitToAttribute = + Enum.GetValues(typeof (Unit)) + .Cast() + .Select(u => new {unit = u, attr = u.GetAttribute()}) + .Where(item => item.attr != null) + .ToDictionary(u => u.unit, u => (UnitAttribute) u.attr); + + Unit[] orderedClassUnits = unitToAttribute + .Keys + .OrderBy(unit => unit.ToString()) + .ToArray(); + + Unit[] orderedClassUnitsExceptBaseUnit = + orderedClassUnits + .Except(new[] {baseUnit}) + .OrderBy(unit => unit.ToString()) + .ToArray(); + + string baseUnitPluralName = GetUnitPluralName(unitToAttribute, baseUnit); +#> +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// <#=classDescription #> + /// + public partial struct <#=className #> : IComparable, IComparable<<#=className #>> + { + /// + /// Base unit of <#=className #> in <#=baseUnitPluralName.ToLowerInvariant() #>. + /// + public readonly double <#=baseUnitPluralName #>; + + public <#=className #>(double <#=baseUnitPluralName.ToLowerInvariant() #>) : this() + { + <#=baseUnitPluralName #> = <#=baseUnitPluralName.ToLowerInvariant() #>; + } + + #region Unit Properties + +<#+ + foreach (Unit unit in orderedClassUnitsExceptBaseUnit) + { + string propertyName = GetUnitPluralName(unitToAttribute, unit); + double unitToBaseRatio = unitToAttribute[unit].Ratio; + /* + Example: + public double Kilonewtons + { + get { return Newtons*1E-3; } + } + */ +#> + public double <#=propertyName #> + { + get { return <#=baseUnitPluralName #>/<#=unitToBaseRatio #>; } + } + +<#+ + } +#> + #endregion + + #region Static + + public static <#=className #> Zero + { + get { return new <#=className #>(); } + } + +<#+ + // First unit is the base unit and already a public field, so skip making a property for it. + foreach (Unit unit in orderedClassUnits) + { + string methodNamePostfix = GetUnitPluralName(unitToAttribute, unit); + string valueParamName = methodNamePostfix.ToLowerInvariant(); + double unitToBaseRatio = unitToAttribute[unit].Ratio; + /* + Example: + public static Force FromKilonewtons(double kilonewtons) + { + return new Force(kilonewtons*1000); + } + */ +#> + public static <#=className #> From<#=methodNamePostfix #>(double <#=valueParamName #>) + { + return new <#=className #>(<#=valueParamName #>*<#=unitToBaseRatio #>); + } + +<#+ + } +#> + #endregion + + #region Arithmetic Operators + + public static <#=className #> operator -(<#=className #> right) + { + return new <#=className #>(-right.<#=baseUnitPluralName #>); + } + + public static <#=className #> operator +(<#=className #> left, <#=className #> right) + { + return new <#=className #>(left.<#=baseUnitPluralName #> + right.<#=baseUnitPluralName #>); + } + + public static <#=className #> operator -(<#=className #> left, <#=className #> right) + { + return new <#=className #>(left.<#=baseUnitPluralName #> - right.<#=baseUnitPluralName #>); + } + + public static <#=className #> operator *(double left, <#=className #> right) + { + return new <#=className #>(left*right.<#=baseUnitPluralName #>); + } + + public static <#=className #> operator *(<#=className #> left, double right) + { + return new <#=className #>(left.<#=baseUnitPluralName #>*right); + } + + public static <#=className #> operator /(<#=className #> left, double right) + { + return new <#=className #>(left.<#=baseUnitPluralName #>/right); + } + + public static double operator /(<#=className #> left, <#=className #> right) + { + return left.<#=baseUnitPluralName #>/right.<#=baseUnitPluralName #>; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is <#=className #>)) throw new ArgumentException("Expected type <#=className #>.", "obj"); + return CompareTo((<#=className #>) obj); + } + + public int CompareTo(<#=className #> other) + { + return <#=baseUnitPluralName #>.CompareTo(other.<#=baseUnitPluralName #>); + } + + public static bool operator <=(<#=className #> left, <#=className #> right) + { + return left.<#=baseUnitPluralName #> <= right.<#=baseUnitPluralName #>; + } + + public static bool operator >=(<#=className #> left, <#=className #> right) + { + return left.<#=baseUnitPluralName #> >= right.<#=baseUnitPluralName #>; + } + + public static bool operator <(<#=className #> left, <#=className #> right) + { + return left.<#=baseUnitPluralName #> < right.<#=baseUnitPluralName #>; + } + + public static bool operator >(<#=className #> left, <#=className #> right) + { + return left.<#=baseUnitPluralName #> > right.<#=baseUnitPluralName #>; + } + + public static bool operator ==(<#=className #> left, <#=className #> right) + { + return left.<#=baseUnitPluralName #> == right.<#=baseUnitPluralName #>; + } + + public static bool operator !=(<#=className #> left, <#=className #> right) + { + return left.<#=baseUnitPluralName #> != right.<#=baseUnitPluralName #>; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return <#=baseUnitPluralName #>.Equals(((<#=className #>) obj).<#=baseUnitPluralName #>); + } + + public override int GetHashCode() + { + return <#=baseUnitPluralName #>.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", <#=baseUnitPluralName #>, UnitSystem.Create().GetDefaultAbbreviation(Unit.<#=baseUnit #>)); + } + } +} +<#+ + } + } +#> \ No newline at end of file diff --git a/Src/UnitsNet/Generated/Volume.generated.cs b/Src/UnitsNet/Generated/Volume.generated.cs new file mode 100644 index 0000000000..efc362bec6 --- /dev/null +++ b/Src/UnitsNet/Generated/Volume.generated.cs @@ -0,0 +1,335 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/SIUnits +// +// 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; + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + /// + /// Volume is the quantity of three-dimensional space enclosed by some closed boundary, for example, the space that a substance (solid, liquid, gas, or plasma) or shape occupies or contains.[1] Volume is often quantified numerically using the SI derived unit, the cubic metre. The volume of a container is generally understood to be the capacity of the container, i. e. the amount of fluid (gas or liquid) that the container could hold, rather than the amount of space the container itself displaces. + /// + public partial struct Volume : IComparable, IComparable + { + /// + /// Base unit of Volume in cubicmeters. + /// + public readonly double CubicMeters; + + public Volume(double cubicmeters) : this() + { + CubicMeters = cubicmeters; + } + + #region Unit Properties + + public double Centiliters + { + get { return CubicMeters/1E-05; } + } + + public double CubicCentimeters + { + get { return CubicMeters/1E-06; } + } + + public double CubicDecimeters + { + get { return CubicMeters/0.001; } + } + + public double CubicFeet + { + get { return CubicMeters/0.0283168; } + } + + public double CubicInches + { + get { return CubicMeters/1.6387E-05; } + } + + public double CubicKilometers + { + get { return CubicMeters/1000000000; } + } + + public double CubicMiles + { + get { return CubicMeters/4168181830; } + } + + public double CubicMillimeters + { + get { return CubicMeters/1E-09; } + } + + public double CubicYards + { + get { return CubicMeters/0.764554858; } + } + + public double Deciliters + { + get { return CubicMeters/0.0001; } + } + + public double Hectoliters + { + get { return CubicMeters/0.1; } + } + + public double ImperialGallons + { + get { return CubicMeters/0.00454609000000181; } + } + + public double ImperialOunces + { + get { return CubicMeters/2.84130624999629E-05; } + } + + public double Liters + { + get { return CubicMeters/0.001; } + } + + public double Milliliters + { + get { return CubicMeters/1E-06; } + } + + public double UsGallons + { + get { return CubicMeters/0.00378541; } + } + + public double UsOunces + { + get { return CubicMeters/2.95735295625376E-05; } + } + + #endregion + + #region Static + + public static Volume Zero + { + get { return new Volume(); } + } + + public static Volume FromCentiliters(double centiliters) + { + return new Volume(centiliters*1E-05); + } + + public static Volume FromCubicCentimeters(double cubiccentimeters) + { + return new Volume(cubiccentimeters*1E-06); + } + + public static Volume FromCubicDecimeters(double cubicdecimeters) + { + return new Volume(cubicdecimeters*0.001); + } + + public static Volume FromCubicFeet(double cubicfeet) + { + return new Volume(cubicfeet*0.0283168); + } + + public static Volume FromCubicInches(double cubicinches) + { + return new Volume(cubicinches*1.6387E-05); + } + + public static Volume FromCubicKilometers(double cubickilometers) + { + return new Volume(cubickilometers*1000000000); + } + + public static Volume FromCubicMeters(double cubicmeters) + { + return new Volume(cubicmeters*1); + } + + public static Volume FromCubicMiles(double cubicmiles) + { + return new Volume(cubicmiles*4168181830); + } + + public static Volume FromCubicMillimeters(double cubicmillimeters) + { + return new Volume(cubicmillimeters*1E-09); + } + + public static Volume FromCubicYards(double cubicyards) + { + return new Volume(cubicyards*0.764554858); + } + + public static Volume FromDeciliters(double deciliters) + { + return new Volume(deciliters*0.0001); + } + + public static Volume FromHectoliters(double hectoliters) + { + return new Volume(hectoliters*0.1); + } + + public static Volume FromImperialGallons(double imperialgallons) + { + return new Volume(imperialgallons*0.00454609000000181); + } + + public static Volume FromImperialOunces(double imperialounces) + { + return new Volume(imperialounces*2.84130624999629E-05); + } + + public static Volume FromLiters(double liters) + { + return new Volume(liters*0.001); + } + + public static Volume FromMilliliters(double milliliters) + { + return new Volume(milliliters*1E-06); + } + + public static Volume FromUsGallons(double usgallons) + { + return new Volume(usgallons*0.00378541); + } + + public static Volume FromUsOunces(double usounces) + { + return new Volume(usounces*2.95735295625376E-05); + } + + #endregion + + #region Arithmetic Operators + + public static Volume operator -(Volume right) + { + return new Volume(-right.CubicMeters); + } + + public static Volume operator +(Volume left, Volume right) + { + return new Volume(left.CubicMeters + right.CubicMeters); + } + + public static Volume operator -(Volume left, Volume right) + { + return new Volume(left.CubicMeters - right.CubicMeters); + } + + public static Volume operator *(double left, Volume right) + { + return new Volume(left*right.CubicMeters); + } + + public static Volume operator *(Volume left, double right) + { + return new Volume(left.CubicMeters*right); + } + + public static Volume operator /(Volume left, double right) + { + return new Volume(left.CubicMeters/right); + } + + public static double operator /(Volume left, Volume right) + { + return left.CubicMeters/right.CubicMeters; + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is Volume)) throw new ArgumentException("Expected type Volume.", "obj"); + return CompareTo((Volume) obj); + } + + public int CompareTo(Volume other) + { + return CubicMeters.CompareTo(other.CubicMeters); + } + + public static bool operator <=(Volume left, Volume right) + { + return left.CubicMeters <= right.CubicMeters; + } + + public static bool operator >=(Volume left, Volume right) + { + return left.CubicMeters >= right.CubicMeters; + } + + public static bool operator <(Volume left, Volume right) + { + return left.CubicMeters < right.CubicMeters; + } + + public static bool operator >(Volume left, Volume right) + { + return left.CubicMeters > right.CubicMeters; + } + + public static bool operator ==(Volume left, Volume right) + { + return left.CubicMeters == right.CubicMeters; + } + + public static bool operator !=(Volume left, Volume right) + { + return left.CubicMeters != right.CubicMeters; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return CubicMeters.Equals(((Volume) obj).CubicMeters); + } + + public override int GetHashCode() + { + return CubicMeters.GetHashCode(); + } + + #endregion + + public override string ToString() + { + return string.Format("{0:0.##} {1}", CubicMeters, UnitSystem.Create().GetDefaultAbbreviation(Unit.CubicMeter)); + } + } +} diff --git a/Src/UnitsNet/Generated/__GenerateUnitClasses.tt b/Src/UnitsNet/Generated/__GenerateUnitClasses.tt new file mode 100644 index 0000000000..8fd82f9a0b --- /dev/null +++ b/Src/UnitsNet/Generated/__GenerateUnitClasses.tt @@ -0,0 +1,30 @@ +<#@ template debug="True" language="C#" hostspecific="True" #> +<# // Load types in current assembly. #> +<#@ assembly name="$(TargetPath)" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ include file="MultipleOutputHelper.ttinclude" once="true"#> +<#@ include file="UnitClass.ttinclude" once="true"#> +<# // Disable output of this file, note this causes a build warning #> +<#@ output extension="/" #> +<#//@ output extension=".cs" #> +<# + + var m = Manager.Create(Host, GenerationEnvironment); + + GenerateUnitClass(m, "Angle", "In geometry, an angle is the figure formed by two rays, called the sides of the angle, sharing a common endpoint, called the vertex of the angle.", Unit.Degree); + GenerateUnitClass(m, "Area", "Area is a quantity that expresses the extent of a two-dimensional surface or shape, or planar lamina, in the plane. Area can be understood as the amount of material with a given thickness that would be necessary to fashion a model of the shape, or the amount of paint necessary to cover the surface with a single coat.[1] It is the two-dimensional analog of the length of a curve (a one-dimensional concept) or the volume of a solid (a three-dimensional concept).", Unit.SquareMeter); + GenerateUnitClass(m, "ElectricPotential", "In classical electromagnetism, the electric potential (a scalar quantity denoted by Φ, ΦE or V and also called the electric field potential or the electrostatic potential) at a point is the amount of electric potential energy that a unitary point charge would have when located at that point.", Unit.Volt); + GenerateUnitClass(m, "Flow", "In physics and engineering, in particular fluid dynamics and hydrometry, the volumetric flow rate, (also known as volume flow rate, rate of fluid flow or volume velocity) is the volume of fluid which passes through a given surface per unit time. The SI unit is m3·s−1 (cubic meters per second). In US Customary Units and British Imperial Units, volumetric flow rate is often expressed as ft3/s (cubic feet per second). It is usually represented by the symbol Q.", Unit.CubicMeterPerSecond); + GenerateUnitClass(m, "Force", "In physics, a force is any influence that causes an object to undergo a certain change, either concerning its movement, direction, or geometrical construction. In other words, a force can cause an object with mass to change its velocity (which includes to begin moving from a state of rest), i.e., to accelerate, or a flexible object to deform, or both. Force can also be described by intuitive concepts such as a push or a pull. A force has both magnitude and direction, making it a vector quantity. It is measured in the SI unit of newtons and represented by the symbol F.", Unit.Newton); + GenerateUnitClass(m, "Length", "Many different units of length have been used around the world. The main units in modern use are U.S. customary units in the United States and the Metric system elsewhere. British Imperial units are still used for some purposes in the United Kingdom and some other countries. The metric system is sub-divided into SI and non-SI units.", Unit.Meter); + GenerateUnitClass(m, "Mass", "In physics, mass (from Greek μᾶζα \"barley cake, lump [of dough]\") is a property of a physical system or body, giving rise to the phenomena of the body's resistance to being accelerated by a force and the strength of its mutual gravitational attraction with other bodies. Instruments such as mass balances or scales use those phenomena to measure mass. The SI unit of mass is the kilogram (kg).", Unit.Kilogram); + GenerateUnitClass(m, "Pressure", "Pressure (symbol: P or p) is the ratio of force to the area over which that force is distributed. Pressure is force per unit area applied in a direction perpendicular to the surface of an object. Gauge pressure (also spelled gage pressure)[a] is the pressure relative to the local atmospheric or ambient pressure. Pressure is measured in any unit of force divided by any unit of area. The SI unit of pressure is the newton per square metre, which is called the pascal (Pa) after the seventeenth-century philosopher and scientist Blaise Pascal. A pressure of 1 Pa is small; it approximately equals the pressure exerted by a dollar bill resting flat on a table. Everyday pressures are often stated in kilopascals (1 kPa = 1000 Pa).", Unit.Pascal); + GenerateUnitClass(m, "RotationalSpeed", "Rotational speed (sometimes called speed of revolution) is the number of complete rotations, revolutions, cycles, or turns per time unit. Rotational speed is a cyclic frequency, measured in radians per second or in hertz in the SI System by scientists, or in revolutions per minute (rpm or min-1) or revolutions per second in everyday life. The symbol for rotational speed is ω (the Greek lowercase letter \"omega\").", Unit.RevolutionPerSecond); + GenerateUnitClass(m, "Torque", "Torque, moment or moment of force (see the terminology below), is the tendency of a force to rotate an object about an axis,[1] fulcrum, or pivot. Just as a force is a push or a pull, a torque can be thought of as a twist to an object. Mathematically, torque is defined as the cross product of the lever-arm distance and force, which tends to produce rotation. Loosely speaking, torque is a measure of the turning force on an object such as a bolt or a flywheel. For example, pushing or pulling the handle of a wrench connected to a nut or bolt produces a torque (turning force) that loosens or tightens the nut or bolt.", Unit.Newtonmeter); + GenerateUnitClass(m, "Volume", "Volume is the quantity of three-dimensional space enclosed by some closed boundary, for example, the space that a substance (solid, liquid, gas, or plasma) or shape occupies or contains.[1] Volume is often quantified numerically using the SI derived unit, the cubic metre. The volume of a container is generally understood to be the capacity of the container, i. e. the amount of fluid (gas or liquid) that the container could hold, rather than the amount of space the container itself displaces.", Unit.CubicMeter); + + m.Process(split: true); +#> diff --git a/Src/UnitsNet/Partial/Force.extra.cs b/Src/UnitsNet/Partial/Force.extra.cs new file mode 100644 index 0000000000..bac30d624e --- /dev/null +++ b/Src/UnitsNet/Partial/Force.extra.cs @@ -0,0 +1,45 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/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. + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + public partial struct Force + { + public static Force FromPressureByArea(Pressure p, Length2d area) + { + double metersSquared = area.Meters.X * area.Meters.Y; + double newtons = p.Pascals * metersSquared; + return new Force(newtons); + } + + public static Force FromPressureByArea(Pressure p, Area area) + { + double newtons = p.Pascals * area.SquareMeters; + return new Force(newtons); + } + + public static Force FromMassByAcceleration(Mass mass, double metersPerSecondSquared) + { + return new Force(mass.Kilograms * metersPerSecondSquared); + } + } +} \ No newline at end of file diff --git a/Src/UnitsNet/Partial/Mass.extra.cs b/Src/UnitsNet/Partial/Mass.extra.cs new file mode 100644 index 0000000000..d29d1d2c30 --- /dev/null +++ b/Src/UnitsNet/Partial/Mass.extra.cs @@ -0,0 +1,32 @@ +// Copyright © 2007 by Initial Force AS. All rights reserved. +// https://github.com/InitialForce/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. + +// ReSharper disable once CheckNamespace +namespace UnitsNet +{ + public partial struct Mass + { + public static Mass FromGravitationalForce(Force f) + { + return new Mass(f.KilogramsForce); + } + } +} \ No newline at end of file diff --git a/Src/UnitsNet/Unit.cs b/Src/UnitsNet/Unit.cs index 677b6dc28e..c55afb8316 100644 --- a/Src/UnitsNet/Unit.cs +++ b/Src/UnitsNet/Unit.cs @@ -19,130 +19,132 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; + namespace UnitsNet { public enum Unit { Undefined = 0, - - // Length - Kilometer, - Meter, - Decimeter, - Centimeter, - Millimeter, - Micrometer, - Nanometer, - - // Length (imperial) - Microinch, - Mil, - Mile, - Yard, - Foot, - Inch, - - // Mass - Megatonne, - Kilotonne, - Tonne, - Kilogram, - Hectogram, - Decagram, - Gram, - Decigram, - Centigram, - Milligram, - //Microgram, - //Nanogram, - - // Mass (imperial) + + // Metric + [Length(1e3)] Kilometer, + [Length(1)] Meter, // Base unit + [Length(1e-1)] Decimeter, + [Length(1e-2)] Centimeter, + [Length(1e-3)] Millimeter, + [Length(1e-6)] Micrometer, + [Length(1e-9)] Nanometer, + + // US, imperial and other + [Length(1609.34)] Mile, + [Length(0.9144)] Yard, + [Length(0.3048, "Feet")] Foot, + [Length(2.54e-2, "Inches")] Inch, + [Length(2.54e-5)] Mil, + [Length(2.54e-8, "Microinches")] Microinch, + + // Metric + [Mass(1e9)] Megatonne, + [Mass(1e6)] Kilotonne, + [Mass(1e3)] Tonne, + [Mass(1)] Kilogram, // Base unit + [Mass(1e-1)] Hectogram, + [Mass(1e-2)] Decagram, + [Mass(1e-3)] Gram, + [Mass(1e-4)] Decigram, + [Mass(1e-5)] Centigram, + [Mass(1e-6)] Milligram, + //[Mass(1e-9)] Microgram, + //[Mass(1e-12)] Nanogram, + + // US, imperial and other /// /// The short ton is a unit of mass equal to 2,000 pounds (907.18474 kg), that is most commonly used in the United States known there simply as the ton. /// /// http://en.wikipedia.org/wiki/Short_ton - ShortTon, + [Mass(907.18474)] ShortTon, /// /// Long ton (weight ton or Imperial ton) is a unit of mass equal to 2,240 pounds (1,016 kg) and is the name for the unit called the "ton" in the avoirdupois or Imperial system of measurements that was used in the United Kingdom and several other Commonwealth countries before metrication. /// /// http://en.wikipedia.org/wiki/Long_ton - LongTon, + [Mass(1016.0469088)] LongTon, // Pressure - Pascal, - KiloPascal, - MegaPascal, - Psi, - NewtonPerSquareCentimeter, - NewtonPerSquareMillimeter, - NewtonPerSquareMeter, - Bar, - TechnicalAtmosphere, - Atmosphere, - Torr, - KilogramForcePerSquareCentimeter, - - // Force - Kilonewton, - Newton, - KilogramForce, - Dyn, - - // Force (imperial/other) - KiloPond, - PoundForce, - Poundal, - - // Area - SquareKilometer, - SquareMeter, - SquareDecimeter, - SquareCentimeter, - SquareMillimeter, - - // Area Imperial - SquareMile, - SquareYard, - SquareFoot, - SquareInch, - - // Angle - Degree, - Radian, - Gradian, - - // Volume - CubicKilometer, - CubicMeter, - CubicDecimeter, - CubicCentimeter, - CubicMillimeter, - Hectoliter, - Liter, - Deciliter, - Centiliter, - Milliliter, - - // Volume US/Imperial - CubicMile, - CubicYard, - CubicFoot, - CubicInch, - UsGallon, - UsOunce, - ImperialGallon, - ImperialOunce, - - // Torque - Newtonmeter, + [Pressure(1e6, "NewtonsPerSquareMillimeter")] NewtonPerSquareMillimeter, + [Pressure(1e4, "NewtonsPerSquareCentimeter")] NewtonPerSquareCentimeter, + [Pressure(1, "NewtonsPerSquareMeter")] NewtonPerSquareMeter, + [Pressure(9.80665*1e4, "KilogramForcePerSquareCentimeter")] KilogramForcePerSquareCentimeter, + [Pressure(1.01325*1e5)] Atmosphere, + [Pressure(9.80680592331*1e4)] TechnicalAtmosphere, + [Pressure(6.89464975179*1e3, "Psi")] Psi, + [Pressure(1.3332266752*1e2)] Torr, + [Pressure(1e5)] Bar, + [Pressure(1e6)] Megapascal, + [Pressure(1e3)] Kilopascal, + [Pressure(1)] Pascal, // Base unit + + // Metric + [Force(1e3)] Kilonewton, + [Force(Constants.Gravity, "KilogramsForce")] KilogramForce, + [Force(1)] Newton, // Base unit + [Force(1e-5, "Dyne")] Dyn, + + // US, imperial and other + [Force(Constants.Gravity)] KiloPond, + [Force(4.4482216152605095551842641431421)] PoundForce, + [Force(0.13825502798973041652092282466083)] Poundal, + + // Metric + [Area(1e6)] SquareKilometer, + [Area(1)] SquareMeter, // Base unit + [Area(1e-2)] SquareDecimeter, + [Area(1e-4)] SquareCentimeter, + [Area(1e-6)] SquareMillimeter, + + // US, imperial and other + [Area(2.59*1e6)] SquareMile, + [Area(0.836127)] SquareYard, + [Area(0.092903, "SquareFeet")] SquareFoot, + [Area(0.00064516, "SquareInches")] SquareInch, + + // Metric + [Angle(Math.PI / 180.0)] Radian, + [Angle(1)] Degree, // Base unit + [Angle(1 / 0.9)] Gradian, + + // Metric + [Volume(1e9)] CubicKilometer, + [Volume(1)] CubicMeter, + [Volume(1e-3)] CubicDecimeter, + [Volume(1e-6)] CubicCentimeter, + [Volume(1e-9)] CubicMillimeter, + [Volume(1e-1)] Hectoliter, + [Volume(1e-3)] Liter, + [Volume(1e-4)] Deciliter, + [Volume(1e-5)] Centiliter, + [Volume(1e-6)] Milliliter, + + // US, imperial and other + [Volume(4.16818183*1e9)] CubicMile, + [Volume(0.764554858)] CubicYard, + [Volume(0.0283168, "CubicFeet")]CubicFoot, + [Volume(1.6387*1e-5, "CubicInches")] CubicInch, + [Volume(0.00454609000000181429905810072407)] ImperialGallon, + [Volume(0.00378541)] UsGallon, + [Volume(2.957352956253760505068307980135*1e-5)] UsOunce, + [Volume(2.8413062499962901241875439064617e-5)] ImperialOunce, + + // Metric + [Torque(1)] Newtonmeter, // Generic / Other Piece, Percent, // Electric potential - Volt, + [ElectricPotential(1)] Volt, // Time /// @@ -167,96 +169,12 @@ public enum Unit Tablespoon, Teaspoon, - // Flow - CubicMeterPerSecond, - CubicMeterPerHour, - - // RotationalSpeed - RevolutionsPerSecond, - RevolutionsPerMinute, - } - - //public enum LengthUnit - //{ - // Kilometer, - // Meter, - // Decimeter, - // Centimeter, - // Millimeter, - - // Mile, - // Yard, - // Foot, - // Inch, - //} - - //public enum MassUnit - //{ - // Megatonne, - // Kilotonne, - // Tonne, - // Kilogram, - // Hectogram, - // Decagram, - // Gram, - // Decigram, - // Centigram, - // Milligram, - // Microgram, - // Nanogram, - //} - - //public enum PressureUnit - //{ - // Pascal, - // KiloPascal, - // Psi, - // NewtonPerSquareCentimeter, - // NewtonPerSquareMillimeter, - // NewtonPerSquareMeter, - // Bar, - // TechnicalAtmosphere, - // Atmosphere, - // Torr, - //} - - //public enum ForceUnit - //{ - // Kilonewton, - // Newton, - // KilogramForce, - // Dyn, - - // KiloPond, - // PoundForce, - // Poundal, - //} - - //public enum VolumeUnit - //{ - // Liter, - // Deciliter, - // Centiliter, - // Milliliter, - - // //Gallon, - - //} - - //public enum TorqueUnit - //{ - // Newtonmeter, - //} - - //public enum GenericUnit - //{ - // Piece, - // Percent, - //} + // Metric + [Flow(1, "CubicMetersPerSecond")] CubicMeterPerSecond, + [Flow(3600, "CubicMetersPerHour")] CubicMeterPerHour, - //public enum CookingUnit - //{ - // Tablespoon, - // Teaspoon, - //} -} \ No newline at end of file + // Metric + [RotationalSpeed(1, "RevolutionsPerSecond")] RevolutionPerSecond, + [RotationalSpeed(60, "RevolutionsPerMinute")] RevolutionPerMinute, + } + } \ No newline at end of file diff --git a/Src/UnitsNet/UnitConverter.cs b/Src/UnitsNet/UnitConverter.cs index e0e5b22f9e..248bc23e21 100644 --- a/Src/UnitsNet/UnitConverter.cs +++ b/Src/UnitsNet/UnitConverter.cs @@ -144,15 +144,15 @@ private static bool TryConvertForce(double value, Unit fromUnit, Unit toUnit, ou case Unit.Newton: return TryConvert(Force.FromNewtons(value), toUnit, out newValue); case Unit.KilogramForce: - return TryConvert(Force.FromKilogramForce(value), toUnit, out newValue); + return TryConvert(Force.FromKilogramsForce(value), toUnit, out newValue); case Unit.Dyn: return TryConvert(Force.FromDyne(value), toUnit, out newValue); case Unit.KiloPond: return TryConvert(Force.FromKiloPonds(value), toUnit, out newValue); case Unit.PoundForce: - return TryConvert(Force.FromPoundForce(value), toUnit, out newValue); + return TryConvert(Force.FromPoundForces(value), toUnit, out newValue); case Unit.Poundal: - return TryConvert(Force.FromPoundal(value), toUnit, out newValue); + return TryConvert(Force.FromPoundals(value), toUnit, out newValue); default: newValue = 0; @@ -166,10 +166,10 @@ private static bool TryConvertPressure(double value, Unit fromUnit, Unit toUnit, { case Unit.Pascal: return TryConvert(Pressure.FromPascals(value), toUnit, out newValue); - case Unit.KiloPascal: - return TryConvert(Pressure.FromKiloPascals(value), toUnit, out newValue); - case Unit.MegaPascal: - return TryConvert(Pressure.FromMegaPascals(value), toUnit, out newValue); + case Unit.Kilopascal: + return TryConvert(Pressure.FromKilopascals(value), toUnit, out newValue); + case Unit.Megapascal: + return TryConvert(Pressure.FromMegapascals(value), toUnit, out newValue); case Unit.Psi: return TryConvert(Pressure.FromPsi(value), toUnit, out newValue); case Unit.NewtonPerSquareCentimeter: @@ -183,11 +183,11 @@ private static bool TryConvertPressure(double value, Unit fromUnit, Unit toUnit, case Unit.Bar: return TryConvert(Pressure.FromBars(value), toUnit, out newValue); case Unit.TechnicalAtmosphere: - return TryConvert(Pressure.FromTechnicalAtmosphere(value), toUnit, out newValue); + return TryConvert(Pressure.FromTechnicalAtmospheres(value), toUnit, out newValue); case Unit.Atmosphere: - return TryConvert(Pressure.FromAtmosphere(value), toUnit, out newValue); + return TryConvert(Pressure.FromAtmospheres(value), toUnit, out newValue); case Unit.Torr: - return TryConvert(Pressure.FromTorr(value), toUnit, out newValue); + return TryConvert(Pressure.FromTorrs(value), toUnit, out newValue); default: newValue = 0; @@ -368,9 +368,9 @@ private static bool TryConvertFlow(double value, Unit fromUnit, Unit toUnit, out switch (fromUnit) { case Unit.CubicMeterPerSecond: - return TryConvert(Flow.FromCubicMeterPerSecond(value), toUnit, out newValue); + return TryConvert(Flow.FromCubicMetersPerSecond(value), toUnit, out newValue); case Unit.CubicMeterPerHour: - return TryConvert(Flow.FromCubicMeterPerHour(value), toUnit, out newValue); + return TryConvert(Flow.FromCubicMetersPerHour(value), toUnit, out newValue); default: newValue = 0; @@ -382,9 +382,9 @@ private static bool TryConvertRevolutions(double value, Unit fromUnit, Unit toUn { switch (fromUnit) { - case Unit.RevolutionsPerSecond: + case Unit.RevolutionPerSecond: return TryConvert(RotationalSpeed.FromRevolutionsPerSecond(value), toUnit, out newValue); - case Unit.RevolutionsPerMinute: + case Unit.RevolutionPerMinute: return TryConvert(RotationalSpeed.FromRevolutionsPerMinute(value), toUnit, out newValue); default: @@ -624,11 +624,11 @@ private static bool TryConvert(Pressure p, Unit toUnit, out double newValue) case Unit.Pascal: newValue = p.Pascals; return true; - case Unit.KiloPascal: - newValue = p.KiloPascals; + case Unit.Kilopascal: + newValue = p.Kilopascals; return true; - case Unit.MegaPascal: - newValue = p.MegaPascals; + case Unit.Megapascal: + newValue = p.Megapascals; return true; case Unit.KilogramForcePerSquareCentimeter: newValue = p.KilogramForcePerSquareCentimeter; @@ -649,13 +649,13 @@ private static bool TryConvert(Pressure p, Unit toUnit, out double newValue) newValue = p.Bars; return true; case Unit.TechnicalAtmosphere: - newValue = p.TechnicalAtmosphere; + newValue = p.TechnicalAtmospheres; return true; case Unit.Atmosphere: - newValue = p.Atmosphere; + newValue = p.Atmospheres; return true; case Unit.Torr: - newValue = p.Torr; + newValue = p.Torrs; return true; default: @@ -675,7 +675,7 @@ private static bool TryConvert(Force f, Unit toUnit, out double newValue) newValue = f.Newtons; return true; case Unit.KilogramForce: - newValue = f.KilogramForce; + newValue = f.KilogramsForce; return true; case Unit.Dyn: newValue = f.Dyne; @@ -684,10 +684,10 @@ private static bool TryConvert(Force f, Unit toUnit, out double newValue) newValue = f.KiloPonds; return true; case Unit.PoundForce: - newValue = f.PoundForce; + newValue = f.PoundForces; return true; case Unit.Poundal: - newValue = f.Poundal; + newValue = f.Poundals; return true; default: @@ -756,10 +756,10 @@ private static bool TryConvert(Flow p, Unit toUnit, out double newValue) switch (toUnit) { case Unit.CubicMeterPerSecond: - newValue = p.CubicMeterPerSecond; + newValue = p.CubicMetersPerSecond; return true; case Unit.CubicMeterPerHour: - newValue = p.CubicMeterPerHour; + newValue = p.CubicMetersPerHour; return true; default: @@ -772,10 +772,10 @@ private static bool TryConvert(RotationalSpeed p, Unit toUnit, out double newVal { switch (toUnit) { - case Unit.RevolutionsPerSecond: + case Unit.RevolutionPerSecond: newValue = p.RevolutionsPerSecond; return true; - case Unit.RevolutionsPerMinute: + case Unit.RevolutionPerMinute: newValue = p.RevolutionsPerMinute; return true; diff --git a/Src/UnitsNet/UnitParser.cs b/Src/UnitsNet/UnitParser.cs index d197f277fd..46b79f09a8 100644 --- a/Src/UnitsNet/UnitParser.cs +++ b/Src/UnitsNet/UnitParser.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using UnitsNet.Utils; namespace UnitsNet { diff --git a/Src/UnitsNet/UnitSystem.cs b/Src/UnitsNet/UnitSystem.cs index 86e581e118..44d911114c 100644 --- a/Src/UnitsNet/UnitSystem.cs +++ b/Src/UnitsNet/UnitSystem.cs @@ -178,8 +178,8 @@ private void CreateRussian() // Pressures MapUnitToAbbreviation(Unit.Pascal, "Па"); - MapUnitToAbbreviation(Unit.KiloPascal, "кПа"); - MapUnitToAbbreviation(Unit.MegaPascal, "МПа"); + MapUnitToAbbreviation(Unit.Kilopascal, "кПа"); + MapUnitToAbbreviation(Unit.Megapascal, "МПа"); MapUnitToAbbreviation(Unit.KilogramForcePerSquareCentimeter, "кгс/см²"); MapUnitToAbbreviation(Unit.Psi, "psi"); MapUnitToAbbreviation(Unit.NewtonPerSquareCentimeter, "Н/см²"); @@ -272,8 +272,8 @@ private void CreateRussian() MapUnitToAbbreviation(Unit.CubicMeterPerHour, "м³/ч"); // RotationalSpeed - MapUnitToAbbreviation(Unit.RevolutionsPerSecond, "об/с"); - MapUnitToAbbreviation(Unit.RevolutionsPerMinute, "об/мин"); + MapUnitToAbbreviation(Unit.RevolutionPerSecond, "об/с"); + MapUnitToAbbreviation(Unit.RevolutionPerMinute, "об/мин"); } private void CreateCultureInvariants() @@ -317,8 +317,8 @@ private void CreateCultureInvariants() // Pressures MapUnitToAbbreviation(Unit.Pascal, "Pa"); - MapUnitToAbbreviation(Unit.KiloPascal, "kPa"); - MapUnitToAbbreviation(Unit.MegaPascal, "MPa"); + MapUnitToAbbreviation(Unit.Kilopascal, "kPa"); + MapUnitToAbbreviation(Unit.Megapascal, "MPa"); MapUnitToAbbreviation(Unit.KilogramForcePerSquareCentimeter, "kgf/cm²"); MapUnitToAbbreviation(Unit.Psi, "psi"); MapUnitToAbbreviation(Unit.NewtonPerSquareCentimeter, "N/cm²"); @@ -411,8 +411,8 @@ private void CreateCultureInvariants() MapUnitToAbbreviation(Unit.CubicMeterPerHour, "m³/h"); // RotationalSpeed - MapUnitToAbbreviation(Unit.RevolutionsPerSecond, "r/s"); - MapUnitToAbbreviation(Unit.RevolutionsPerMinute, "r/min"); + MapUnitToAbbreviation(Unit.RevolutionPerSecond, "r/s"); + MapUnitToAbbreviation(Unit.RevolutionPerMinute, "r/min"); } private void MapUnitToAbbreviation(Unit unit, params string[] abbreviations) diff --git a/Src/UnitsNet/UnitsNet.net35.csproj b/Src/UnitsNet/UnitsNet.net35.csproj index b4a74c62ce..6be34a937c 100644 --- a/Src/UnitsNet/UnitsNet.net35.csproj +++ b/Src/UnitsNet/UnitsNet.net35.csproj @@ -13,6 +13,8 @@ 512 Client ..\..\build\bin\$(Platform)_$(Configuration)\ + ..\ + true true @@ -38,10 +40,25 @@ - - - + + + + + TextTemplatingFileGenerator + + + __GenerateUnitClasses.tt + + + + + + + + + + - + + + TextTemplatingFileGenerator + + + __GenerateUnitClasses.tt + + 12.0 diff --git a/Src/UnitsNet/UnitsNet.pcl.csproj b/Src/UnitsNet/UnitsNet.pcl.csproj index 64efec8b7c..2d90799b06 100644 --- a/Src/UnitsNet/UnitsNet.pcl.csproj +++ b/Src/UnitsNet/UnitsNet.pcl.csproj @@ -40,7 +40,14 @@ - + + + TextTemplatingFileGenerator + + + __GenerateUnitClasses.tt + +