Innovenergy_trunk/csharp/Lib/Units/Resistance.generated.cs

68 lines
2.4 KiB
C#

#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
#define Generate
using static System.Math;
using System.Text.Json;
using System.Text.Json.Serialization;
using InnovEnergy.Lib.Utils;
using System.CodeDom.Compiler;
namespace InnovEnergy.Lib.Units;
using T = Resistance;
[GeneratedCode("generate.sh", "1")]
[JsonConverter(typeof(ResistanceConverter))]
public readonly partial struct Resistance
{
public Double Value { get; }
public override String ToString() => Value.RoundToSignificantDigits(Units.DisplaySignificantDigits) + Unit;
// scalar multiplication
public static T operator *(Double scalar, T t) => new T(scalar * t.Value);
public static T operator *(T t, Double scalar) => new T(scalar * t.Value);
public static T operator /(T t, Double scalar) => new T(t.Value / scalar);
// addition
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);
// 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(Double d) => new T(d);
// 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();
}
internal class ResistanceConverter : JsonConverter<Resistance>
{
public override Resistance Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return new Resistance(reader.GetDouble());
}
public override void Write(Utf8JsonWriter writer, Resistance value, JsonSerializerOptions options)
{
var rounded = value.Value.RoundToSignificantDigits(Units.JsonSignificantDigits);
writer.WriteNumberValue(rounded);
}
}