38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace InnovEnergy.Lib.Units;
|
|
|
|
public static class Units
|
|
{
|
|
static Units()
|
|
{
|
|
JsonConverters = typeof(Units)
|
|
.Assembly
|
|
.GetTypes()
|
|
.Where(t => t.IsAssignableTo(typeof(JsonConverter)))
|
|
.Select(Activator.CreateInstance)
|
|
.Cast<JsonConverter>()
|
|
.ToArray();
|
|
}
|
|
|
|
|
|
public static IReadOnlyList<JsonConverter> JsonConverters { get; }
|
|
|
|
public static Byte DisplaySignificantDigits { get; set; } = 3;
|
|
public static Byte JsonSignificantDigits { get; set; } = 3;
|
|
|
|
|
|
public const Decimal MaxRelativeError = 0.05m; // 5%
|
|
|
|
public static Current A (this Decimal value) => new Current(value);
|
|
public static Voltage V (this Decimal value) => new Voltage(value);
|
|
public static Power W (this Decimal value) => new Power(value);
|
|
public static ReactivePower Var (this Decimal value) => new ReactivePower(value);
|
|
public static ApparentPower Va (this Decimal value) => new ApparentPower(value);
|
|
public static Resistance Ohm (this Decimal value) => new Resistance(value);
|
|
public static Frequency Hz (this Decimal value) => new Frequency(value);
|
|
public static Angle Rad (this Decimal value) => new Angle(value);
|
|
public static Temperature Celsius(this Decimal value) => new Temperature(value);
|
|
|
|
|
|
} |