From 9bf23f3ec822bf0246c06ef85580dbde41a3b8e8 Mon Sep 17 00:00:00 2001 From: ig Date: Wed, 1 Mar 2023 08:14:08 +0100 Subject: [PATCH] add Percent % to Units --- csharp/Lib/Units/Percent.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 csharp/Lib/Units/Percent.cs diff --git a/csharp/Lib/Units/Percent.cs b/csharp/Lib/Units/Percent.cs new file mode 100644 index 000000000..02bf1a146 --- /dev/null +++ b/csharp/Lib/Units/Percent.cs @@ -0,0 +1,29 @@ +namespace InnovEnergy.Lib.Units; + +using T = Percent; + +public readonly struct Percent +{ + public static String Unit => "%"; + public static String Symbol => "%"; // ?? + + public Percent(Decimal value) + { + if (value < 0) + throw new ArgumentException(nameof(Frequency) + " cannot be negative", nameof(value)); + + Value = value; + } + + // not generated + + public Decimal Value { get; } + public override String ToString() => Value + Unit; + + // scalar multiplication + public static Decimal operator *(Decimal scalar, T t) => scalar * t.Value/100m; + public static Decimal operator *(T t, Decimal scalar) => scalar * t.Value/100m; + + // parallel + public static Percent operator |(T left, T right) => new T((left.Value + right.Value)/2m); +} \ No newline at end of file