2023-02-26 14:39:55 +00:00
|
|
|
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
|
2023-03-02 16:15:10 +00:00
|
|
|
#define AggregationType
|
2023-02-26 18:19:16 +00:00
|
|
|
|
|
|
|
using static System.Math;
|
2023-03-02 16:15:10 +00:00
|
|
|
using System.Text.Json;
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
using InnovEnergy.Lib.Utils;
|
2023-03-20 12:27:15 +00:00
|
|
|
using System.CodeDom.Compiler;
|
2023-02-26 14:39:55 +00:00
|
|
|
|
|
|
|
namespace InnovEnergy.Lib.Units;
|
|
|
|
|
|
|
|
using T = Template;
|
|
|
|
|
2023-03-20 12:27:15 +00:00
|
|
|
[GeneratedCode("generate.sh", "1")]
|
2023-03-06 08:52:27 +00:00
|
|
|
[JsonConverter(typeof(TemplateConverter))]
|
2023-02-26 14:39:55 +00:00
|
|
|
public readonly partial struct Template
|
|
|
|
{
|
|
|
|
public Decimal Value { get; }
|
2023-03-02 16:15:10 +00:00
|
|
|
public override String ToString() => Value.RoundToSignificantDigits(Units.DisplaySignificantDigits) + Unit;
|
2023-02-26 14:39:55 +00:00
|
|
|
|
|
|
|
// scalar multiplication
|
|
|
|
|
|
|
|
public static T operator *(Decimal scalar, T t) => new T(scalar * t.Value);
|
|
|
|
public static T operator *(T t, Decimal scalar) => new T(scalar * t.Value);
|
|
|
|
public static T operator /(T t, Decimal scalar) => new T(t.Value / scalar);
|
|
|
|
|
2023-03-20 12:22:57 +00:00
|
|
|
// addition
|
2023-02-26 18:19:16 +00:00
|
|
|
|
2023-03-20 12:22:57 +00:00
|
|
|
public static T operator +(T left, T right) => new T(left.Value + right.Value);
|
|
|
|
public static T operator -(T left, T right) => new T(left.Value - right.Value);
|
|
|
|
public static T operator -(T t) => new T(-t.Value);
|
2023-02-26 18:19:16 +00:00
|
|
|
|
2023-02-26 14:39:55 +00:00
|
|
|
// compare
|
|
|
|
|
|
|
|
public static Boolean operator ==(T left, T right) => left.Value == right.Value;
|
|
|
|
public static Boolean operator !=(T left, T right) => left.Value != right.Value;
|
|
|
|
public static Boolean operator > (T left, T right) => left.Value > right.Value;
|
|
|
|
public static Boolean operator < (T left, T right) => left.Value < right.Value;
|
|
|
|
public static Boolean operator >=(T left, T right) => left.Value >= right.Value;
|
|
|
|
public static Boolean operator <=(T left, T right) => left.Value <= right.Value;
|
|
|
|
|
|
|
|
// conversion
|
|
|
|
|
|
|
|
public static implicit operator T(Decimal d) => new T(d);
|
|
|
|
public static implicit operator T(Double d) => new T((Decimal)d);
|
|
|
|
public static implicit operator T(Int32 i) => new T(i);
|
|
|
|
public static implicit operator Decimal(T t) => t.Value;
|
|
|
|
|
|
|
|
// equality
|
|
|
|
|
|
|
|
public Boolean Equals(T other) => Value == other.Value;
|
|
|
|
public override Boolean Equals(Object? obj) => obj is T other && Equals(other);
|
|
|
|
public override Int32 GetHashCode() => Value.GetHashCode();
|
|
|
|
|
|
|
|
}
|
2023-03-02 16:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
internal class TemplateConverter : JsonConverter<Template>
|
|
|
|
{
|
|
|
|
public override Template Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
|
|
{
|
|
|
|
return new Template(reader.GetDecimal());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Write(Utf8JsonWriter writer, Template value, JsonSerializerOptions options)
|
|
|
|
{
|
|
|
|
var rounded = value.Value.RoundToSignificantDigits(Units.JsonSignificantDigits);
|
|
|
|
|
|
|
|
writer.WriteNumberValue(rounded);
|
|
|
|
}
|
|
|
|
}
|