-
Notifications
You must be signed in to change notification settings - Fork 387
/
Copy pathUnitSystem.cs
72 lines (60 loc) · 2.95 KB
/
UnitSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.
using System;
using UnitsNet.Units;
namespace UnitsNet
{
public sealed class UnitSystem
{
/// <summary>
/// Creates an instance of a unit system with the specified base units.
/// </summary>
/// <param name="baseUnits">The base units for the unit system.</param>
public UnitSystem(BaseUnits baseUnits)
{
if(baseUnits is null)
throw new ArgumentNullException(nameof(baseUnits));
if(baseUnits.Length == LengthUnit.Undefined)
throw new ArgumentException("A unit system must have all base units defined.", nameof(baseUnits));
if(baseUnits.Mass == MassUnit.Undefined)
throw new ArgumentException("A unit system must have all base units defined.", nameof(baseUnits));
if(baseUnits.Time == DurationUnit.Undefined)
throw new ArgumentException("A unit system must have all base units defined.", nameof(baseUnits));
if(baseUnits.Current == ElectricCurrentUnit.Undefined)
throw new ArgumentException("A unit system must have all base units defined.", nameof(baseUnits));
if(baseUnits.Temperature == TemperatureUnit.Undefined)
throw new ArgumentException("A unit system must have all base units defined.", nameof(baseUnits));
if(baseUnits.Amount == AmountOfSubstanceUnit.Undefined)
throw new ArgumentException("A unit system must have all base units defined.", nameof(baseUnits));
if(baseUnits.LuminousIntensity == LuminousIntensityUnit.Undefined)
throw new ArgumentException("A unit system must have all base units defined.", nameof(baseUnits));
BaseUnits = baseUnits;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if(obj is null || !(obj is UnitSystem))
return false;
return Equals((UnitSystem)obj);
}
[Windows.Foundation.Metadata.DefaultOverload]
public bool Equals(UnitSystem other)
{
if(other is null)
return false;
return BaseUnits.Equals(other.BaseUnits);
}
/// <inheritdoc />
public override int GetHashCode()
{
return new {BaseUnits}.GetHashCode();
}
public BaseUnits BaseUnits{ get; }
private static readonly BaseUnits SIBaseUnits = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);
/// <summary>
/// Gets the SI unit system.
/// </summary>
public static UnitSystem SI{ get; } = new UnitSystem(SIBaseUnits);
}
}