This commit is contained in:
melekhin
2026-06-08 12:00:10 +07:00
parent 78c1cc0ec8
commit 39ee5bdddf
29 changed files with 496 additions and 472 deletions

View File

@@ -98,9 +98,7 @@ using System.Runtime.Serialization;
namespace QWERTYkez.Mensura.Units;
public class {typeName}Converter : UnitJsonConverter<{typeName}> { }
[JsonConverter(typeof({typeName}Converter))]
[Newtonsoft.Json.JsonConverter(typeof(NewtonsoftUnitConverter<{typeName}>)), JsonConverter(typeof(UnitJsonConverter<{typeName}>))]
public readonly partial record struct {typeName} : IMensuraUnit<{typeName}>, IEquatable<{typeName}>, IMensuraUnit
{
[JsonInclude, DataMember, JsonPropertyName(""v""), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value
@@ -115,6 +113,21 @@ public readonly partial record struct {typeName} : IMensuraUnit<{typeName}>, IEq
public bool Equals({typeName}? other) => _Value.Equals(other?._Value);
public static explicit operator {typeName}(double val) => Unsafe.As<double, {typeName}>(ref val);
public static explicit operator double({typeName} unit) => unit._Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public {typeName} Abs() => new(Math.Abs(_Value));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal R Pow2_Internal<R>() where R : struct, IMensuraUnit, IEquatable<R> => (_Value * _Value).ToUnit<R>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal R Sqrt_Internal<R>() where R : struct, IMensuraUnit, IEquatable<R> => Math.Sqrt(_Value).ToUnit<R>();
[JsonIgnore, IgnoreDataMember] public bool IsPositive => _Value >= 0;
[JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero => _Value > 0;
[JsonIgnore, IgnoreDataMember] public bool IsNegative => double.IsNegative(_Value);
@@ -269,19 +282,6 @@ public readonly partial record struct {typeName} : IMensuraUnit<{typeName}>, IEq
public static {typeName} operator /({typeName} T1, UInt128 T2) => T1 / T2.ToDouble();
public static {typeName} operator /({typeName} T1, UInt128? T2) => T1 / T2.ToDouble();
#endif
public static explicit operator {typeName}(double val) => Unsafe.As<double, {typeName}>(ref val);
public static explicit operator double({typeName} unit) => unit._Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public {typeName} Abs() => new(Math.Abs(_Value));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal R Pow2_Internal<R>() where R : struct, IMensuraUnit, IEquatable<R> => (_Value * _Value).ToUnit<R>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal R Sqrt_Internal<R>() where R : struct, IMensuraUnit, IEquatable<R> => Math.Sqrt(_Value).ToUnit<R>();
}
public static class {typeName}Extensions