Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Src/UnitsNet/GeneratedCode/MassUnit.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ public double Nanograms
get { return (Kilograms - (0)) / 1E-12; }
}

/// <summary>
/// Get Mass in Pounds.
/// </summary>
/// <remarks>Example: x = (y - b) / a where x is value in Pounds and y is value in base unit Kilograms.</remarks>
public double Pounds
{
get { return (Kilograms - (0)) / 0.45359237; }
}

/// <summary>
/// Get Mass in ShortTons.
/// </summary>
Expand Down Expand Up @@ -275,6 +284,15 @@ public static Mass FromNanograms(double nanograms)
return new Mass(1E-12 * nanograms + 0);
}

/// <summary>
/// Get Mass from Pounds.
/// </summary>
/// <remarks>Example: y = ax + b where x is value in Pounds and y is value in base unit Kilograms.</remarks>
public static Mass FromPounds(double pounds)
{
return new Mass(0.45359237 * pounds + 0);
}

/// <summary>
/// Get Mass from ShortTons.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Src/UnitsNet/GeneratedCode/UnitConverter.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ private static bool TryConvertFromMass(double value, Unit fromUnit, Unit toUnit,
return TryConvert(Mass.FromNanograms(value), toUnit, out newValue);
case Unit.ShortTon:
return TryConvert(Mass.FromShortTons(value), toUnit, out newValue);
case Unit.Pound:
return TryConvert(Mass.FromPounds(value), toUnit, out newValue);
case Unit.LongTon:
return TryConvert(Mass.FromLongTons(value), toUnit, out newValue);

Expand Down Expand Up @@ -772,6 +774,9 @@ private static bool TryConvert(Mass value, Unit toUnit, out double newValue)
case Unit.ShortTon:
newValue = value.ShortTons;
return true;
case Unit.Pound:
newValue = value.Pounds;
return true;
case Unit.LongTon:
newValue = value.LongTons;
return true;
Expand Down
5 changes: 5 additions & 0 deletions Src/UnitsNet/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public enum Unit
/// <remarks>http://en.wikipedia.org/wiki/Short_ton</remarks>
[Mass(907.18474)] ShortTon,

/// <summary>
/// The pound or pound-mass (abbreviations: lb, lbm) is a unit of mass used in the imperial, United States customary and other systems of measurement. A number of different definitions have been used, the most common today being the international avoirdupois pound which is legally defined as exactly 0.45359237 kilograms, and which is divided into 16 avoirdupois ounces.
/// </summary>
[Mass(0.45359237)] Pound,

/// <summary>
/// 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.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Src/UnitsNet/UnitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,12 @@ private void CreateCultureInvariants()
MapUnitToAbbreviation(Unit.Decigram, "dg");
MapUnitToAbbreviation(Unit.Centigram, "cg");
MapUnitToAbbreviation(Unit.Milligram, "mg");
MapUnitToAbbreviation(Unit.Microgram, "µg");
MapUnitToAbbreviation(Unit.Nanogram, "ng");

// Mass (imperial)
MapUnitToAbbreviation(Unit.ShortTon, "short tn");
MapUnitToAbbreviation(Unit.Pound, "lb");
MapUnitToAbbreviation(Unit.LongTon, "long tn");

// Pressures
Expand Down
5 changes: 5 additions & 0 deletions Tests/CustomCode/MassTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public override double ShortTonsInOneKilogram
get { return 0.00110231; }
}

public override double PoundsInOneKilogram
{
get { return 2.2046226218487757d; }
}

public override double TonnesInOneKilogram
{
get { return 1E-3; }
Expand Down
3 changes: 3 additions & 0 deletions Tests/GeneratedCode/MassTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public abstract partial class MassTestsBase
public abstract double MicrogramsInOneKilogram { get; }
public abstract double MilligramsInOneKilogram { get; }
public abstract double NanogramsInOneKilogram { get; }
public abstract double PoundsInOneKilogram { get; }
public abstract double ShortTonsInOneKilogram { get; }
public abstract double TonnesInOneKilogram { get; }

Expand All @@ -66,6 +67,7 @@ public void KilogramToMassUnits()
Assert.AreEqual(MicrogramsInOneKilogram, kilogram.Micrograms, Delta);
Assert.AreEqual(MilligramsInOneKilogram, kilogram.Milligrams, Delta);
Assert.AreEqual(NanogramsInOneKilogram, kilogram.Nanograms, Delta);
Assert.AreEqual(PoundsInOneKilogram, kilogram.Pounds, Delta);
Assert.AreEqual(ShortTonsInOneKilogram, kilogram.ShortTons, Delta);
Assert.AreEqual(TonnesInOneKilogram, kilogram.Tonnes, Delta);
}
Expand All @@ -86,6 +88,7 @@ public void ConversionRoundTrip()
Assert.AreEqual(1, Mass.FromMicrograms(kilogram.Micrograms).Kilograms, Delta);
Assert.AreEqual(1, Mass.FromMilligrams(kilogram.Milligrams).Kilograms, Delta);
Assert.AreEqual(1, Mass.FromNanograms(kilogram.Nanograms).Kilograms, Delta);
Assert.AreEqual(1, Mass.FromPounds(kilogram.Pounds).Kilograms, Delta);
Assert.AreEqual(1, Mass.FromShortTons(kilogram.ShortTons).Kilograms, Delta);
Assert.AreEqual(1, Mass.FromTonnes(kilogram.Tonnes).Kilograms, Delta);
}
Expand Down
1 change: 1 addition & 0 deletions Tests/GeneratedCode/UnitConverterTests.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void KilogramToMassUnits()
Assert.AreEqual(t.MicrogramsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.Microgram), Delta);
Assert.AreEqual(t.NanogramsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.Nanogram), Delta);
Assert.AreEqual(t.ShortTonsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.ShortTon), Delta);
Assert.AreEqual(t.PoundsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.Pound), Delta);
Assert.AreEqual(t.LongTonsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.LongTon), Delta);
}
[Test]
Expand Down