From 0591c666c2487c473c853d9ae54483d80b862b1e Mon Sep 17 00:00:00 2001 From: Fantom TM Date: Sun, 7 Jun 2026 15:54:53 +0700 Subject: [PATCH] Fulll --- .../ComplexUnitGenerator.cs | 852 +++++++++--------- .../OperatorsGenerator.cs | 360 ++++---- QWERTYkez.Mensura/Operators.cs | 220 ++--- QWERTYkez.Mensura/Units/Angle.cs | 2 +- QWERTYkez.Mensura/Units/Area.cs | 2 +- QWERTYkez.Mensura/Units/Boost.cs | 2 +- .../.LinearXXXXXXXX.Gen.cs} | 0 .../.LinearXXXXXXXX.Ref.cs} | 0 .../Units/Complex/ForceLinear.cs | 23 +- .../Units/Complex/ForceVolumetric.cs | 25 +- QWERTYkez.Mensura/Units/Complex/MassLinear.cs | 27 +- .../Units/Complex/MassVolumetric (Density).cs | 28 +- QWERTYkez.Mensura/Units/Force.cs | 2 +- QWERTYkez.Mensura/Units/Frequency.cs | 2 +- QWERTYkez.Mensura/Units/Length.cs | 2 +- QWERTYkez.Mensura/Units/Mass.cs | 2 +- QWERTYkez.Mensura/Units/MassPerSquare.cs | 2 +- QWERTYkez.Mensura/Units/Pogon/.Pogon.cs | 149 --- QWERTYkez.Mensura/Units/Pressure.cs | 2 +- QWERTYkez.Mensura/Units/Speed.cs | 2 +- QWERTYkez.Mensura/Units/Time.cs | 2 +- QWERTYkez.Mensura/Units/Torque.cs | 2 +- QWERTYkez.Mensura/Units/Udel/.Udel.cs | 175 ---- QWERTYkez.Mensura/Units/Voltage.cs | 2 +- QWERTYkez.Mensura/Units/Volume.cs | 2 +- QWERTYkez.Mensura/globals.cs | 3 +- 26 files changed, 721 insertions(+), 1169 deletions(-) rename QWERTYkez.Mensura/Units/{Pogon/PogonXXXXXXXX.Gen.cs => Complex/.LinearXXXXXXXX.Gen.cs} (100%) rename QWERTYkez.Mensura/Units/{Pogon/PogonXXXXXXXX.Ref.cs => Complex/.LinearXXXXXXXX.Ref.cs} (100%) delete mode 100644 QWERTYkez.Mensura/Units/Pogon/.Pogon.cs delete mode 100644 QWERTYkez.Mensura/Units/Udel/.Udel.cs diff --git a/QWERTYkez.Mensura.Generator/ComplexUnitGenerator.cs b/QWERTYkez.Mensura.Generator/ComplexUnitGenerator.cs index c470fe8..0f0fc63 100644 --- a/QWERTYkez.Mensura.Generator/ComplexUnitGenerator.cs +++ b/QWERTYkez.Mensura.Generator/ComplexUnitGenerator.cs @@ -141,76 +141,76 @@ namespace QWERTYkez.Mensura // В нём используйте {typeName}, {ns}, {typeNameA}, {typeNameB}, {typeNameZ} // Например: string template = @" -global using {typeNameZ}Extensions = QWERTYkez.Mensura.Units.Complex.{typeNameZ}Extensions; -global using {typeNameZ}Converter = QWERTYkez.Mensura.Units.Complex.{typeNameZ}Converter; -global using {typeNameZ} = QWERTYkez.Mensura.Units.Complex.{typeNameZ}; +global using {typeNameZ}Extensions = QWERTYkez.Mensura.Units.{typeNameZ}Extensions; +global using {typeNameZ}Converter = QWERTYkez.Mensura.Units.{typeNameZ}Converter; +global using {typeNameZ} = QWERTYkez.Mensura.Units.{typeNameZ}; using System.Globalization; using System.Runtime.Serialization; -namespace QWERTYkez.Mensura.Units +namespace QWERTYkez.Mensura.Units; + +public readonly partial record struct {typeNameB} { - public readonly partial record struct {typeNameB} - { - public static {typeNameZ} operator /({typeNameA} left, {typeNameB} right) => new(left._Value / right._Value); - public static {typeNameZ} operator /({typeNameA}? left, {typeNameB} right) => new(left.Protected() / right._Value); - public static {typeNameZ} operator /({typeNameA} left, {typeNameB}? right) => new(left._Value / right.Protected()); - public static {typeNameZ} operator /({typeNameA}? left, {typeNameB}? right) => new(left.Protected() / right.Protected()); + public static {typeNameZ} operator /({typeNameA} left, {typeNameB} right) => new(left._Value / right._Value); + public static {typeNameZ} operator /({typeNameA}? left, {typeNameB} right) => new(left.Protected() / right._Value); + public static {typeNameZ} operator /({typeNameA} left, {typeNameB}? right) => new(left._Value / right.Protected()); + public static {typeNameZ} operator /({typeNameA}? left, {typeNameB}? right) => new(left.Protected() / right.Protected()); - // === Array === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator - *({typeNameZ}[] units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator - *({typeNameZ}?[] units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator - *({typeNameB} multiplicator, {typeNameZ}[] units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator - *({typeNameB} multiplicator, {typeNameZ}?[] units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameZ}[] units, {typeNameB}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameZ}?[] units, {typeNameB}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameB}? multiplicator, {typeNameZ}[] units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameB}? multiplicator, {typeNameZ}?[] units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); + // === Array === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator + *({typeNameZ}[] units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator + *({typeNameZ}?[] units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator + *({typeNameB} multiplicator, {typeNameZ}[] units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator + *({typeNameB} multiplicator, {typeNameZ}?[] units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameZ}[] units, {typeNameB}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameZ}?[] units, {typeNameB}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameB}? multiplicator, {typeNameZ}[] units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameB}? multiplicator, {typeNameZ}?[] units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); - // === List === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator - *(List<{typeNameZ}> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator - *(List<{typeNameZ}?> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator - *({typeNameB} multiplicator, List<{typeNameZ}> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator - *({typeNameB} multiplicator, List<{typeNameZ}?> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *(List<{typeNameZ}> units, {typeNameB}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *(List<{typeNameZ}?> units, {typeNameB}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *({typeNameB}? multiplicator, List<{typeNameZ}> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *({typeNameB}? multiplicator, List<{typeNameZ}?> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); + // === List === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator + *(List<{typeNameZ}> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator + *(List<{typeNameZ}?> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator + *({typeNameB} multiplicator, List<{typeNameZ}> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator + *({typeNameB} multiplicator, List<{typeNameZ}?> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *(List<{typeNameZ}> units, {typeNameB}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *(List<{typeNameZ}?> units, {typeNameB}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *({typeNameB}? multiplicator, List<{typeNameZ}> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *({typeNameB}? multiplicator, List<{typeNameZ}?> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); - // === IEnumerable === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator - *(IEnumerable<{typeNameZ}> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator - *(IEnumerable<{typeNameZ}?> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator - *({typeNameB} multiplicator, IEnumerable<{typeNameZ}> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator - *({typeNameB} multiplicator, IEnumerable<{typeNameZ}?> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *(IEnumerable<{typeNameZ}> units, {typeNameB}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *(IEnumerable<{typeNameZ}?> units, {typeNameB}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *({typeNameB}? multiplicator, IEnumerable<{typeNameZ}> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *({typeNameB}? multiplicator, IEnumerable<{typeNameZ}?> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); + // === IEnumerable === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator + *(IEnumerable<{typeNameZ}> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator + *(IEnumerable<{typeNameZ}?> units, {typeNameB} multiplicator) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator + *({typeNameB} multiplicator, IEnumerable<{typeNameZ}> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator + *({typeNameB} multiplicator, IEnumerable<{typeNameZ}?> units) => units.Multiply<{typeNameZ}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *(IEnumerable<{typeNameZ}> units, {typeNameB}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *(IEnumerable<{typeNameZ}?> units, {typeNameB}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *({typeNameB}? multiplicator, IEnumerable<{typeNameZ}> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *({typeNameB}? multiplicator, IEnumerable<{typeNameZ}?> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); @@ -219,117 +219,117 @@ namespace QWERTYkez.Mensura.Units - - // === Array === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator - /({typeNameA}[] units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator - /({typeNameA}?[] units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator - /({typeNameB} dividend, {typeNameA}[] units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator - /({typeNameB} dividend, {typeNameA}?[] units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameA}[] units, {typeNameB}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameA}?[] units, {typeNameB}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameB}? dividend, {typeNameA}[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameB}? dividend, {typeNameA}?[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); + + // === Array === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator + /({typeNameA}[] units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator + /({typeNameA}?[] units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator + /({typeNameB} dividend, {typeNameA}[] units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator + /({typeNameB} dividend, {typeNameA}?[] units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameA}[] units, {typeNameB}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameA}?[] units, {typeNameB}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameB}? dividend, {typeNameA}[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameB}? dividend, {typeNameA}?[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); - // === List === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator - /(List<{typeNameA}> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator - /(List<{typeNameA}?> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator - /({typeNameB} dividend, List<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator - /({typeNameB} dividend, List<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /(List<{typeNameA}> units, {typeNameB}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /(List<{typeNameA}?> units, {typeNameB}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /({typeNameB}? dividend, List<{typeNameA}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /({typeNameB}? dividend, List<{typeNameA}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); + // === List === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator + /(List<{typeNameA}> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator + /(List<{typeNameA}?> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator + /({typeNameB} dividend, List<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator + /({typeNameB} dividend, List<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /(List<{typeNameA}> units, {typeNameB}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /(List<{typeNameA}?> units, {typeNameB}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /({typeNameB}? dividend, List<{typeNameA}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /({typeNameB}? dividend, List<{typeNameA}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); - // === IEnumerable === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator - /(IEnumerable<{typeNameA}> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator - /(IEnumerable<{typeNameA}?> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator - /({typeNameB} dividend, IEnumerable<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator - /({typeNameB} dividend, IEnumerable<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /(IEnumerable<{typeNameA}> units, {typeNameB}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /(IEnumerable<{typeNameA}?> units, {typeNameB}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /({typeNameB}? dividend, IEnumerable<{typeNameA}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /({typeNameB}? dividend, IEnumerable<{typeNameA}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); - } - public readonly partial record struct {typeNameA} - { - // === Array === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator - /({typeNameZ}[] units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator - /({typeNameZ}?[] units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator - /({typeNameA} dividend, {typeNameZ}[] units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator - /({typeNameA} dividend, {typeNameZ}?[] units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameZ}[] units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameZ}?[] units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}?[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameA}? dividend, {typeNameZ}[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameA}? dividend, {typeNameZ}?[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}?[units.Length]); + // === IEnumerable === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator + /(IEnumerable<{typeNameA}> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator + /(IEnumerable<{typeNameA}?> units, {typeNameB} divisor) => units.Divide<{typeNameA}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator + /({typeNameB} dividend, IEnumerable<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator + /({typeNameB} dividend, IEnumerable<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /(IEnumerable<{typeNameA}> units, {typeNameB}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /(IEnumerable<{typeNameA}?> units, {typeNameB}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /({typeNameB}? dividend, IEnumerable<{typeNameA}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /({typeNameB}? dividend, IEnumerable<{typeNameA}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); +} +public readonly partial record struct {typeNameA} +{ + // === Array === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator + /({typeNameZ}[] units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator + /({typeNameZ}?[] units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator + /({typeNameA} dividend, {typeNameZ}[] units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator + /({typeNameA} dividend, {typeNameZ}?[] units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameZ}[] units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameZ}?[] units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}?[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameA}? dividend, {typeNameZ}[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameA}? dividend, {typeNameZ}?[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}?[units.Length]); - // === List === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator - /(List<{typeNameZ}> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator - /(List<{typeNameZ}?> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator - /({typeNameA} dividend, List<{typeNameZ}> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator - /({typeNameA} dividend, List<{typeNameZ}?> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /(List<{typeNameZ}> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /(List<{typeNameZ}?> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /({typeNameA}? dividend, List<{typeNameZ}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /({typeNameA}? dividend, List<{typeNameZ}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); + // === List === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator + /(List<{typeNameZ}> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator + /(List<{typeNameZ}?> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator + /({typeNameA} dividend, List<{typeNameZ}> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator + /({typeNameA} dividend, List<{typeNameZ}?> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /(List<{typeNameZ}> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /(List<{typeNameZ}?> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /({typeNameA}? dividend, List<{typeNameZ}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /({typeNameA}? dividend, List<{typeNameZ}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); - // === IEnumerable === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator - /(IEnumerable<{typeNameZ}> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator - /(IEnumerable<{typeNameZ}?> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator - /({typeNameA} dividend, IEnumerable<{typeNameZ}> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator - /({typeNameA} dividend, IEnumerable<{typeNameZ}?> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /(IEnumerable<{typeNameZ}> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /(IEnumerable<{typeNameZ}?> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /({typeNameA}? dividend, IEnumerable<{typeNameZ}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /({typeNameA}? dividend, IEnumerable<{typeNameZ}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); - + // === IEnumerable === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator + /(IEnumerable<{typeNameZ}> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator + /(IEnumerable<{typeNameZ}?> units, {typeNameA} divisor) => units.Divide<{typeNameZ}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator + /({typeNameA} dividend, IEnumerable<{typeNameZ}> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator + /({typeNameA} dividend, IEnumerable<{typeNameZ}?> units) => dividend._Value.Divide<{typeNameZ}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /(IEnumerable<{typeNameZ}> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /(IEnumerable<{typeNameZ}?> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /({typeNameA}? dividend, IEnumerable<{typeNameZ}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /({typeNameA}? dividend, IEnumerable<{typeNameZ}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); + @@ -337,284 +337,280 @@ namespace QWERTYkez.Mensura.Units - - // === Array === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator - /({typeNameB}[] units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator - /({typeNameB}?[] units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator - /({typeNameA} dividend, {typeNameB}[] units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator - /({typeNameA} dividend, {typeNameB}?[] units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameB}[] units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameB}?[] units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameA}? dividend, {typeNameB}[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameA}? dividend, {typeNameB}?[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); + + // === Array === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator + /({typeNameB}[] units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator + /({typeNameB}?[] units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator + /({typeNameA} dividend, {typeNameB}[] units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator + /({typeNameA} dividend, {typeNameB}?[] units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameB}[] units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameB}?[] units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}[] operator /({typeNameA}? dividend, {typeNameB}[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameZ}?[] operator /({typeNameA}? dividend, {typeNameB}?[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameZ}?[units.Length]); - // === List === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator - /(List<{typeNameB}> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator - /(List<{typeNameB}?> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator - /({typeNameA} dividend, List<{typeNameB}> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator - /({typeNameA} dividend, List<{typeNameB}?> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /(List<{typeNameB}> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /(List<{typeNameB}?> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /({typeNameA}? dividend, List<{typeNameB}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /({typeNameA}? dividend, List<{typeNameB}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); + // === List === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator + /(List<{typeNameB}> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator + /(List<{typeNameB}?> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator + /({typeNameA} dividend, List<{typeNameB}> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator + /({typeNameA} dividend, List<{typeNameB}?> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /(List<{typeNameB}> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /(List<{typeNameB}?> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}> operator /({typeNameA}? dividend, List<{typeNameB}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameZ}?> operator /({typeNameA}? dividend, List<{typeNameB}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameZ}?>(units.Count)); - // === IEnumerable === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator - /(IEnumerable<{typeNameB}> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator - /(IEnumerable<{typeNameB}?> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator - /({typeNameA} dividend, IEnumerable<{typeNameB}> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator - /({typeNameA} dividend, IEnumerable<{typeNameB}?> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /(IEnumerable<{typeNameB}> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /(IEnumerable<{typeNameB}?> units, {typeNameA}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /({typeNameA}? dividend, IEnumerable<{typeNameB}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /({typeNameA}? dividend, IEnumerable<{typeNameB}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); - } + // === IEnumerable === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator + /(IEnumerable<{typeNameB}> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator + /(IEnumerable<{typeNameB}?> units, {typeNameA} divisor) => units.Divide<{typeNameB}, {typeNameZ}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator + /({typeNameA} dividend, IEnumerable<{typeNameB}> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator + /({typeNameA} dividend, IEnumerable<{typeNameB}?> units) => dividend._Value.Divide<{typeNameB}, {typeNameZ}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /(IEnumerable<{typeNameB}> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /(IEnumerable<{typeNameB}?> units, {typeNameA}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}> operator /({typeNameA}? dividend, IEnumerable<{typeNameB}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameZ}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameZ}?> operator /({typeNameA}? dividend, IEnumerable<{typeNameB}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameZ}?)null : new {typeNameZ}(0d))); } -namespace QWERTYkez.Mensura.Units.Complex +[JsonConverter(typeof({typeNameZ}Converter))] +public readonly partial record struct {typeNameZ} : IMensuraUnit<{typeNameZ}>, IEquatable<{typeNameZ}>, IMensuraUnit { - [JsonConverter(typeof({typeNameZ}Converter))] - public readonly partial record struct {typeNameZ} : IMensuraUnit<{typeNameZ}>, IEquatable<{typeNameZ}>, IMensuraUnit + + [JsonInclude, DataMember, JsonPropertyName(""v""), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value + internal double Value { get => _Value; init => _Value = value; } + internal readonly double _Value; + internal {typeNameZ}(double value) => _Value = value; + + + [NotMapped, JsonIgnore] internal {typeNameA} PerValue + { get => ({typeNameA})_Value; init => _Value = (double)value; } + + + + [JsonIgnore, IgnoreDataMember] public bool IsPositive => _Value >= 0; + [JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero => _Value > 0; + [JsonIgnore, IgnoreDataMember] public bool IsNegative => double.IsNegative(_Value); + [JsonIgnore, IgnoreDataMember] public bool IsZero => _Value == 0; + [JsonIgnore, IgnoreDataMember] public bool IsNaN => double.IsNaN(_Value); + [JsonIgnore, IgnoreDataMember] public bool IsFinite => double.IsFinite(_Value); + [JsonIgnore, IgnoreDataMember] public bool IsInfinity => double.IsInfinity(_Value); + [JsonIgnore, IgnoreDataMember] public bool IsPositiveInfinity => double.IsPositiveInfinity(_Value); + [JsonIgnore, IgnoreDataMember] public bool IsNegativeInfinity => double.IsNegativeInfinity(_Value); + + + public static {typeNameA} operator *({typeNameZ} left, {typeNameB} right) => new(left._Value * right._Value); + public static {typeNameA} operator *({typeNameZ}? left, {typeNameB} right) => new(left.Protected() * right._Value); + public static {typeNameA} operator *({typeNameZ} left, {typeNameB}? right) => new(left._Value * right.Protected()); + public static {typeNameA} operator *({typeNameZ}? left, {typeNameB}? right) => new(left.Protected() * right.Protected()); + + public static {typeNameA} operator *({typeNameB} left, {typeNameZ} right) => new(right._Value * left._Value); + public static {typeNameA} operator *({typeNameB}? left, {typeNameZ} right) => new(right._Value * left.Protected()); + public static {typeNameA} operator *({typeNameB} left, {typeNameZ}? right) => new(right.Protected() * left._Value); + public static {typeNameA} operator *({typeNameB}? left, {typeNameZ}? right) => new(right.Protected() * left.Protected()); + + public static {typeNameB} operator /({typeNameA} left, {typeNameZ} right) => new(left._Value / right._Value); + public static {typeNameB} operator /({typeNameA}? left, {typeNameZ} right) => new(left.Protected() / right._Value); + public static {typeNameB} operator /({typeNameA} left, {typeNameZ}? right) => new(left._Value / right.Protected()); + public static {typeNameB} operator /({typeNameA}? left, {typeNameZ}? right) => new(left.Protected() / right.Protected()); + + + + + + + + + // === Array === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator + *({typeNameB}[] units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator + *({typeNameB}?[] units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator + *({typeNameZ} multiplicator, {typeNameB}[] units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator + *({typeNameZ} multiplicator, {typeNameB}?[] units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameB}[] units, {typeNameZ}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameB}?[] units, {typeNameZ}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameZ}? multiplicator, {typeNameB}[] units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameZ}? multiplicator, {typeNameB}?[] units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); + + // === List === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator + *(List<{typeNameB}> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator + *(List<{typeNameB}?> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator + *({typeNameZ} multiplicator, List<{typeNameB}> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator + *({typeNameZ} multiplicator, List<{typeNameB}?> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *(List<{typeNameB}> units, {typeNameZ}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *(List<{typeNameB}?> units, {typeNameZ}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *({typeNameZ}? multiplicator, List<{typeNameB}> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *({typeNameZ}? multiplicator, List<{typeNameB}?> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); + + // === IEnumerable === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator + *(IEnumerable<{typeNameB}> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator + *(IEnumerable<{typeNameB}?> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator + *({typeNameZ} multiplicator, IEnumerable<{typeNameB}> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator + *({typeNameZ} multiplicator, IEnumerable<{typeNameB}?> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *(IEnumerable<{typeNameB}> units, {typeNameZ}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *(IEnumerable<{typeNameB}?> units, {typeNameZ}? multiplicator) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *({typeNameZ}? multiplicator, IEnumerable<{typeNameB}> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *({typeNameZ}? multiplicator, IEnumerable<{typeNameB}?> units) => + multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); + + + + + + + // === Array === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator + /({typeNameA}[] units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator + /({typeNameA}?[] units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator + /({typeNameZ} dividend, {typeNameA}[] units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator + /({typeNameZ} dividend, {typeNameA}?[] units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameA}[] units, {typeNameZ}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameA}?[] units, {typeNameZ}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}?[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameZ}? dividend, {typeNameA}[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}[units.Length]); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameZ}? dividend, {typeNameA}?[] units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}?[units.Length]); + + // === List === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator + /(List<{typeNameA}> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator + /(List<{typeNameA}?> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator + /({typeNameZ} dividend, List<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator + /({typeNameZ} dividend, List<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /(List<{typeNameA}> units, {typeNameZ}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /(List<{typeNameA}?> units, {typeNameZ}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /({typeNameZ}? dividend, List<{typeNameA}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /({typeNameZ}? dividend, List<{typeNameA}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); + + // === IEnumerable === + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator + /(IEnumerable<{typeNameA}> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator + /(IEnumerable<{typeNameA}?> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator + /({typeNameZ} dividend, IEnumerable<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator + /({typeNameZ} dividend, IEnumerable<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /(IEnumerable<{typeNameA}> units, {typeNameZ}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /(IEnumerable<{typeNameA}?> units, {typeNameZ}? divisor) => + divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /({typeNameZ}? dividend, IEnumerable<{typeNameA}> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /({typeNameZ}? dividend, IEnumerable<{typeNameA}?> units) => + dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); +} + +internal static class {typeNameZ}Extensions +{ + public static double Protected(this {typeNameZ}? unit) => unit is null ? 0d : unit.Value._Value; + internal static double ToDouble(this {typeNameB}? unit) => unit?._Value ?? 0d; +} + +public class {typeNameZ}Converter : JsonConverter<{typeNameZ}> +{ + // Используем инвариантную культуру, чтобы разделителем всегда была точка (10.5, а не 10,5) + private static readonly CultureInfo Culture = CultureInfo.InvariantCulture; + + public override {typeNameZ} Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { + double double_Value; - [JsonInclude, DataMember, JsonPropertyName(""v""), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value - internal double Value { get => _Value; init => _Value = value; } - internal readonly double _Value; - internal {typeNameZ}(double value) => _Value = value; + if (reader.TokenType == JsonTokenType.String) + { + // Безопасно парсим double из строки с поддержкой точки как разделителя + if (!double.TryParse(reader.GetString(), NumberStyles.Float, Culture, out double_Value)) + { + throw new JsonException($""Не удалось преобразовать строковое значение в double для метрики {nameof({typeNameZ})}.""); + } + } + else + { + // Прямое быстрое чтение числа из JSON + double_Value = reader.GetDouble(); + } - - [NotMapped, JsonIgnore] internal {typeNameA} PerValue - { get => ({typeNameA})_Value; init => _Value = (double)value; } - - - - [JsonIgnore, IgnoreDataMember] public bool IsPositive => _Value >= 0; - [JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero => _Value > 0; - [JsonIgnore, IgnoreDataMember] public bool IsNegative => double.IsNegative(_Value); - [JsonIgnore, IgnoreDataMember] public bool IsZero => _Value == 0; - [JsonIgnore, IgnoreDataMember] public bool IsNaN => double.IsNaN(_Value); - [JsonIgnore, IgnoreDataMember] public bool IsFinite => double.IsFinite(_Value); - [JsonIgnore, IgnoreDataMember] public bool IsInfinity => double.IsInfinity(_Value); - [JsonIgnore, IgnoreDataMember] public bool IsPositiveInfinity => double.IsPositiveInfinity(_Value); - [JsonIgnore, IgnoreDataMember] public bool IsNegativeInfinity => double.IsNegativeInfinity(_Value); - - - public static {typeNameA} operator *({typeNameZ} left, {typeNameB} right) => new(left._Value * right._Value); - public static {typeNameA} operator *({typeNameZ}? left, {typeNameB} right) => new(left.Protected() * right._Value); - public static {typeNameA} operator *({typeNameZ} left, {typeNameB}? right) => new(left._Value * right.Protected()); - public static {typeNameA} operator *({typeNameZ}? left, {typeNameB}? right) => new(left.Protected() * right.Protected()); - - public static {typeNameA} operator *({typeNameB} left, {typeNameZ} right) => new(right._Value * left._Value); - public static {typeNameA} operator *({typeNameB}? left, {typeNameZ} right) => new(right._Value * left.Protected()); - public static {typeNameA} operator *({typeNameB} left, {typeNameZ}? right) => new(right.Protected() * left._Value); - public static {typeNameA} operator *({typeNameB}? left, {typeNameZ}? right) => new(right.Protected() * left.Protected()); - - public static {typeNameB} operator /({typeNameA} left, {typeNameZ} right) => new(left._Value / right._Value); - public static {typeNameB} operator /({typeNameA}? left, {typeNameZ} right) => new(left.Protected() / right._Value); - public static {typeNameB} operator /({typeNameA} left, {typeNameZ}? right) => new(left._Value / right.Protected()); - public static {typeNameB} operator /({typeNameA}? left, {typeNameZ}? right) => new(left.Protected() / right.Protected()); - - - - - - - - - // === Array === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator - *({typeNameB}[] units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator - *({typeNameB}?[] units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator - *({typeNameZ} multiplicator, {typeNameB}[] units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator - *({typeNameZ} multiplicator, {typeNameB}?[] units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameB}[] units, {typeNameZ}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameB}?[] units, {typeNameZ}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}[] operator *({typeNameZ}? multiplicator, {typeNameB}[] units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameA}?[] operator *({typeNameZ}? multiplicator, {typeNameB}?[] units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new {typeNameA}?[units.Length]); - - // === List === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator - *(List<{typeNameB}> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator - *(List<{typeNameB}?> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator - *({typeNameZ} multiplicator, List<{typeNameB}> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator - *({typeNameZ} multiplicator, List<{typeNameB}?> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *(List<{typeNameB}> units, {typeNameZ}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *(List<{typeNameB}?> units, {typeNameZ}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}> operator *({typeNameZ}? multiplicator, List<{typeNameB}> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameA}?> operator *({typeNameZ}? multiplicator, List<{typeNameB}?> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<{typeNameA}?>(units.Count)); - - // === IEnumerable === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator - *(IEnumerable<{typeNameB}> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator - *(IEnumerable<{typeNameB}?> units, {typeNameZ} multiplicator) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator - *({typeNameZ} multiplicator, IEnumerable<{typeNameB}> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator - *({typeNameZ} multiplicator, IEnumerable<{typeNameB}?> units) => units.Multiply<{typeNameB}, {typeNameA}>(multiplicator._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *(IEnumerable<{typeNameB}> units, {typeNameZ}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *(IEnumerable<{typeNameB}?> units, {typeNameZ}? multiplicator) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}> operator *({typeNameZ}? multiplicator, IEnumerable<{typeNameB}> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new {typeNameA}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameA}?> operator *({typeNameZ}? multiplicator, IEnumerable<{typeNameB}?> units) => - multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameA}?)null : new {typeNameA}(0d))); - - - - - - - // === Array === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator - /({typeNameA}[] units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator - /({typeNameA}?[] units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator - /({typeNameZ} dividend, {typeNameA}[] units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator - /({typeNameZ} dividend, {typeNameA}?[] units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameA}[] units, {typeNameZ}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameA}?[] units, {typeNameZ}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new {typeNameB}?[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}[] operator /({typeNameZ}? dividend, {typeNameA}[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}[units.Length]); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static {typeNameB}?[] operator /({typeNameZ}? dividend, {typeNameA}?[] units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new {typeNameB}?[units.Length]); - - // === List === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator - /(List<{typeNameA}> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator - /(List<{typeNameA}?> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator - /({typeNameZ} dividend, List<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator - /({typeNameZ} dividend, List<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /(List<{typeNameA}> units, {typeNameZ}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /(List<{typeNameA}?> units, {typeNameZ}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}> operator /({typeNameZ}? dividend, List<{typeNameA}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}>(units.Count)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<{typeNameB}?> operator /({typeNameZ}? dividend, List<{typeNameA}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : new List<{typeNameB}?>(units.Count)); - - // === IEnumerable === - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator - /(IEnumerable<{typeNameA}> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator - /(IEnumerable<{typeNameA}?> units, {typeNameZ} divisor) => units.Divide<{typeNameA}, {typeNameB}>(divisor._Value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator - /({typeNameZ} dividend, IEnumerable<{typeNameA}> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator - /({typeNameZ} dividend, IEnumerable<{typeNameA}?> units) => dividend._Value.Divide<{typeNameA}, {typeNameB}>(units); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /(IEnumerable<{typeNameA}> units, {typeNameZ}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /(IEnumerable<{typeNameA}?> units, {typeNameZ}? divisor) => - divisor.HasValue ? units / divisor.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}> operator /({typeNameZ}? dividend, IEnumerable<{typeNameA}> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => new {typeNameB}(0d))); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<{typeNameB}?> operator /({typeNameZ}? dividend, IEnumerable<{typeNameA}?> units) => - dividend.HasValue ? units / dividend.Value : (units is null ? null! : units.Select(u => u is null ? ({typeNameB}?)null : new {typeNameB}(0d))); + return new(double_Value); } - internal static class {typeNameZ}Extensions + public override void Write(Utf8JsonWriter writer, {typeNameZ} value, JsonSerializerOptions options) { - public static double Protected(this {typeNameZ}? unit) => unit is null ? 0d : unit.Value._Value; - internal static double ToDouble(this {typeNameB}? unit) => unit?._Value ?? 0d; + // Записываем число напрямую в байтовый буфер без выделения памяти под строки + writer.WriteNumberValue(value._Value); } - public class {typeNameZ}Converter : JsonConverter<{typeNameZ}> + public override void WriteAsPropertyName(Utf8JsonWriter writer, {typeNameZ} value, JsonSerializerOptions options) { - // Используем инвариантную культуру, чтобы разделителем всегда была точка (10.5, а не 10,5) - private static readonly CultureInfo Culture = CultureInfo.InvariantCulture; + // Ключи JSON-объектов всегда должны быть строками. + // Форматируем double в строку с точкой, чтобы другие сервисы экосистемы прочитали её корректно. + // Формат ""R"" (Round-trip) гарантирует, что число не потеряет точность при обратном парсинге. + writer.WritePropertyName(value._Value.ToString(""R"", Culture)); + } - public override {typeNameZ} Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override {typeNameZ} ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string propertyName = reader.GetString()!; + + if (!double.TryParse(propertyName, NumberStyles.Float, Culture, out double double_Value)) { - double double_Value; - - if (reader.TokenType == JsonTokenType.String) - { - // Безопасно парсим double из строки с поддержкой точки как разделителя - if (!double.TryParse(reader.GetString(), NumberStyles.Float, Culture, out double_Value)) - { - throw new JsonException($""Не удалось преобразовать строковое значение в double для метрики {nameof({typeNameZ})}.""); - } - } - else - { - // Прямое быстрое чтение числа из JSON - double_Value = reader.GetDouble(); - } - - return new(double_Value); + throw new JsonException($""Невалидное числовое значение в ключе свойства JSON: '{propertyName}' для метрики {nameof({typeNameZ})}.""); } - public override void Write(Utf8JsonWriter writer, {typeNameZ} value, JsonSerializerOptions options) - { - // Записываем число напрямую в байтовый буфер без выделения памяти под строки - writer.WriteNumberValue(value._Value); - } - - public override void WriteAsPropertyName(Utf8JsonWriter writer, {typeNameZ} value, JsonSerializerOptions options) - { - // Ключи JSON-объектов всегда должны быть строками. - // Форматируем double в строку с точкой, чтобы другие сервисы экосистемы прочитали её корректно. - // Формат ""R"" (Round-trip) гарантирует, что число не потеряет точность при обратном парсинге. - writer.WritePropertyName(value._Value.ToString(""R"", Culture)); - } - - public override {typeNameZ} ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - string propertyName = reader.GetString()!; - - if (!double.TryParse(propertyName, NumberStyles.Float, Culture, out double double_Value)) - { - throw new JsonException($""Невалидное числовое значение в ключе свойства JSON: '{propertyName}' для метрики {nameof({typeNameZ})}.""); - } - - return new(double_Value); - } + return new(double_Value); } } "; diff --git a/QWERTYkez.Mensura.Generator/OperatorsGenerator.cs b/QWERTYkez.Mensura.Generator/OperatorsGenerator.cs index c70e77e..f784505 100644 --- a/QWERTYkez.Mensura.Generator/OperatorsGenerator.cs +++ b/QWERTYkez.Mensura.Generator/OperatorsGenerator.cs @@ -2,194 +2,208 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; -using System.Collections.Immutable; using System.Linq; using System.Text; -namespace G; - -[Generator(LanguageNames.CSharp)] -public class CollectionsOperatorsGenerator : IIncrementalGenerator +namespace G { - private const string AttributeShortName = "CollectionsOperatorsGenerator"; - private const string AttributeFullName = AttributeShortName + "Attribute"; - - private const string AttributeSource = @"namespace QWERTYkez.Mensura; - -[System.AttributeUsage(System.AttributeTargets.Struct | System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -internal sealed class CollectionsOperatorsGeneratorAttribute : System.Attribute { }"; - - // Какие типы коллекций поддерживаем - private static readonly (string Type, string Selector)[] CollectionTypes = - [ - ("T[]", "array => array.Select(u => left * u).ToArray()"), // но нужно адаптировать под конкретный тип - // Проще генерировать отдельные методы для каждого типа - ]; - - public void Initialize(IncrementalGeneratorInitializationContext context) + [Generator(LanguageNames.CSharp)] + public class OperatorsGenerator : IIncrementalGenerator { - context.RegisterPostInitializationOutput(ctx => - ctx.AddSource($"{AttributeFullName}.g", SourceText.From(AttributeSource, Encoding.UTF8))); + private const string AttributeSource = @"// +using System; - var operatorsPipeline = context.SyntaxProvider - .CreateSyntaxProvider( - predicate: static (node, _) => IsTargetType(node), - transform: static (ctx, _) => GetTypeInfo(ctx)) - .Where(info => info.HasValue) // использование nullable value type - .Select((info, _) => info!.Value) - .Collect(); - - context.RegisterSourceOutput(operatorsPipeline, GenerateOperators); - } - - private static bool IsTargetType(SyntaxNode node) +namespace QWERTYkez.Mensura +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + public sealed class OperatorsGeneratorAttribute : Attribute { - if (node is not TypeDeclarationSyntax typeDecl) - return false; + public string CoeffName { get; } - // Должен быть partial и не generic - if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword)) - return false; - if (typeDecl.TypeParameterList != null) - return false; - - // Проверяем наличие атрибута на самом типе - foreach (var attrList in typeDecl.AttributeLists) - foreach (var attr in attrList.Attributes) - { - string name = attr.Name.ToString(); - if (name == AttributeShortName || name == AttributeFullName) - return true; - } - - // Или на операторах внутри - foreach (var member in typeDecl.Members) + public OperatorsGeneratorAttribute() { - if (member is OperatorDeclarationSyntax opDecl && - opDecl.AttributeLists.SelectMany(al => al.Attributes) - .Any(a => a.Name.ToString().Contains(AttributeShortName))) - return true; - } - return false; - } - - private static TypeInfoData? GetTypeInfo(GeneratorSyntaxContext ctx) - { - var typeDecl = (TypeDeclarationSyntax)ctx.Node; - var semanticModel = ctx.SemanticModel; - - var symbol = semanticModel.GetDeclaredSymbol(typeDecl); - if (symbol == null) return null; - - string namespaceName = symbol.ContainingNamespace?.ToString() ?? ""; - - // Формируем заголовок (для отладочных целей) - var headerBuilder = new StringBuilder(); - foreach (var modifier in typeDecl.Modifiers) - headerBuilder.Append(modifier.Text).Append(' '); - if (typeDecl is RecordDeclarationSyntax) - headerBuilder.Append("record "); - headerBuilder.Append(typeDecl.Identifier.Text); - string header = headerBuilder.ToString(); - - // Собираем операторы - var operators = ImmutableArray.CreateBuilder(); - foreach (var member in typeDecl.Members) - { - if (member is not OperatorDeclarationSyntax opDecl) continue; - if (opDecl.ParameterList.Parameters.Count != 2) continue; - if (!opDecl.AttributeLists.SelectMany(al => al.Attributes) - .Any(a => a.Name.ToString().Contains(AttributeShortName))) continue; - - operators.Add(new Operation( - opDecl.OperatorToken.Text, - opDecl.ParameterList.Parameters[0].Type!.ToString(), - opDecl.ParameterList.Parameters[1].Type!.ToString(), - opDecl.ReturnType.ToString() - )); } - if (operators.Count == 0) return null; - - return new TypeInfoData(namespaceName, typeDecl.Identifier.Text, header, operators.ToImmutable()); - } - - private static void GenerateOperators(SourceProductionContext context, ImmutableArray types) - { - foreach (var group in types.GroupBy(t => t.Namespace)) + public OperatorsGeneratorAttribute(string coeffName) { - var document = new StringBuilder(); - document.AppendLine("namespace ").Append(group.Key).AppendLine(";"); - document.AppendLine("using System.Collections.Generic;"); - document.AppendLine("using System.Linq;"); - - var allOperators = group.SelectMany(t => t.Operators).ToList(); - var multiplications = allOperators.Where(op => op.OperatorToken == "*").ToList(); - var divisions = allOperators.Where(op => op.OperatorToken == "/").ToList(); - - // Генерация для умножения: left * collection и collection * left - foreach (var mul in multiplications) - { - // left * collection - document.AppendLine($@" - public static {mul.ReturnType}[] operator *({mul.TypeA} left, {mul.TypeB}[] right) => - right.Select(u => left * u).ToArray(); - public static List<{mul.ReturnType}> operator *({mul.TypeA} left, List<{mul.TypeB}> right) => - right.Select(u => left * u).ToList(); - public static IEnumerable<{mul.ReturnType}> operator *({mul.TypeA} left, IEnumerable<{mul.TypeB}> right) => - right.Select(u => left * u); -"); - // collection * left - document.AppendLine($@" - public static {mul.ReturnType}[] operator *({mul.TypeB}[] left, {mul.TypeA} right) => - left.Select(u => u * right).ToArray(); - public static List<{mul.ReturnType}> operator *(List<{mul.TypeB}> left, {mul.TypeA} right) => - left.Select(u => u * right).ToList(); - public static IEnumerable<{mul.ReturnType}> operator *(IEnumerable<{mul.TypeB}> left, {mul.TypeA} right) => - left.Select(u => u * right); -"); - } - - // Деление: left / collection (left - тип A, collection - тип B) - foreach (var div in divisions.Where(op => op.TypeA != null)) // все деления - { - // left / collection - document.AppendLine($@" - public static {div.ReturnType}[] operator /({div.TypeA} left, {div.TypeB}[] right) => - right.Select(u => left / u).ToArray(); - public static List<{div.ReturnType}> operator /({div.TypeA} left, List<{div.TypeB}> right) => - right.Select(u => left / u).ToList(); - public static IEnumerable<{div.ReturnType}> operator /({div.TypeA} left, IEnumerable<{div.TypeB}> right) => - right.Select(u => left / u); -"); - // collection / right (где right - тип B) - document.AppendLine($@" - public static {div.ReturnType}[] operator /({div.TypeA}[] left, {div.TypeB} right) => - left.Select(u => u / right).ToArray(); - public static List<{div.ReturnType}> operator /(List<{div.TypeA}> left, {div.TypeB} right) => - left.Select(u => u / right).ToList(); - public static IEnumerable<{div.ReturnType}> operator /(IEnumerable<{div.TypeA}> left, {div.TypeB} right) => - left.Select(u => u / right); -"); - } - - context.AddSource($"operations.{group.Key}.g", document.ToString()); + CoeffName = coeffName; } } +}"; - private readonly struct TypeInfoData(string ns, string name, string header, ImmutableArray ops) - { - public string Namespace { get; } = ns; - public string TypeName { get; } = name; - public string Header { get; } = header; - public ImmutableArray Operators { get; } = ops; - } + public void Initialize(IncrementalGeneratorInitializationContext context) + { + // 1. Внедряем атрибут + context.RegisterPostInitializationOutput(static postInitializationContext => + { + postInitializationContext.AddSource( + ".OperatorsGeneratorAttribute.g.cs", + SourceText.From(AttributeSource, Encoding.UTF8)); + }); - private readonly struct Operation(string token, string a, string b, string ret) - { - public string OperatorToken { get; } = token; - public string TypeA { get; } = a; - public string TypeB { get; } = b; - public string ReturnType { get; } = ret; + // 2. Ищем методы-операторы, помеченные атрибутом + IncrementalValuesProvider operatorDeclarations = context.SyntaxProvider + .ForAttributeWithMetadataName( + fullyQualifiedMetadataName: "QWERTYkez.Mensura.OperatorsGeneratorAttribute", + predicate: static (node, _) => node is OperatorDeclarationSyntax, + transform: static (ctx, _) => GetSemanticTargetForGeneration(ctx)) + .Where(static m => m is not null)!; + + // 3. Выполняем генерацию кода + context.RegisterSourceOutput(operatorDeclarations, static (spc, opInfo) => Execute(spc, opInfo)); + } + + private static OperatorInfo GetSemanticTargetForGeneration(GeneratorAttributeSyntaxContext context) + { + var opDeclaration = (OperatorDeclarationSyntax)context.TargetNode; + + if (opDeclaration.ParameterList.Parameters.Count < 2) return null; + + if (context.SemanticModel.GetDeclaredSymbol(opDeclaration) is not IMethodSymbol symbol) return null; + + var namespaceName = symbol.ContainingNamespace.ToDisplayString(); + + var leftType = opDeclaration.ParameterList.Parameters[0].Type?.ToString() ?? ""; + var rightType = opDeclaration.ParameterList.Parameters[1].Type?.ToString() ?? ""; + var returnType = opDeclaration.ReturnType.ToString(); + + var isMultiplication = opDeclaration.OperatorToken.IsKind(SyntaxKind.AsteriskToken); + var isDivision = opDeclaration.OperatorToken.IsKind(SyntaxKind.SlashToken); + + if (!isMultiplication && !isDivision) return null; + + // АВТОМАТИЧЕСКИЙ ПОИСК: Ищем содержащий тип (структуру/рекорд) по синтаксическому дереву + string containingTypeName = leftType; // Фолбэк по умолчанию + var parentTypeDeclaration = opDeclaration.Ancestors() + .OfType() + .FirstOrDefault(); + + if (parentTypeDeclaration != null) + { + containingTypeName = parentTypeDeclaration.Identifier.ToString(); + } + + string coeffName = null; + string coeffType = containingTypeName; // По умолчанию считаем, что коэффициент в текущем классе + + // Извлекаем аргумент атрибута + var attribute = opDeclaration.AttributeLists + .SelectMany(al => al.Attributes) + .FirstOrDefault(a => a.Name.ToString().EndsWith("OperatorsGenerator") || a.Name.ToString() == "OperatorsGenerator"); + + if (attribute?.ArgumentList != null && attribute.ArgumentList.Arguments.Count > 0) + { + var expr = attribute.ArgumentList.Arguments[0].Expression; + + // Проверяем синтаксис nameof(...) + if (expr is InvocationExpressionSyntax invocation && + invocation.Expression.ToString() == "nameof" && + invocation.ArgumentList.Arguments.Count > 0) + { + var nameofArg = invocation.ArgumentList.Arguments[0].Expression; + + // Если все-таки написали явно nameof(Type.Property) + if (nameofArg is MemberAccessExpressionSyntax memberAccess) + { + coeffType = memberAccess.Expression.ToString(); + coeffName = memberAccess.Name.ToString(); + } + else + { + coeffName = nameofArg.ToString(); + // coeffType остается равным содержащему классу containingTypeName + } + } + else + { + coeffName = expr.ToString().Trim('"'); + // coeffType остается равным содержащему классу containingTypeName + } + } + + return new OperatorInfo + { + Namespace = namespaceName, + LeftType = leftType, + RightType = rightType, + ReturnType = returnType, + IsMultiplication = isMultiplication, + IsDivision = isDivision, + CoeffName = coeffName, + CoeffType = coeffType, + HasCoeff = !string.IsNullOrWhiteSpace(coeffName) + }; + } + + private static void Execute(SourceProductionContext context, OperatorInfo info) + { + var opType = info.IsMultiplication ? "Mul" : "Div"; + var coeffSuffix = info.HasCoeff ? ".Coeff" : ""; + var hintName = $"Op.{info.LeftType}.{opType}.{info.RightType}{coeffSuffix}.g.cs"; + + var source = info.IsMultiplication + ? GenerateMultiplicationSource(info) + : GenerateDivisionSource(info); + + context.AddSource(hintName, SourceText.From(source, Encoding.UTF8)); + } + + private static string GenerateMultiplicationSource(OperatorInfo info) + { + return $@"// +using System; +using System.Collections.Generic; + +namespace {info.Namespace}; + +public readonly partial record struct {info.LeftType} +{{ + public static {info.ReturnType}[] operator *({info.LeftType} left, {info.RightType}[] right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * left._Value)" : "left._Value")}.Multiply<{info.RightType}, {info.ReturnType}>(right); + public static List<{info.ReturnType}> operator *({info.LeftType} left, List<{info.RightType}> right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * left._Value)" : "left._Value")}.Multiply<{info.RightType}, {info.ReturnType}>(right); + public static IEnumerable<{info.ReturnType}> operator *({info.LeftType} left, IEnumerable<{info.RightType}> right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * left._Value)" : "left._Value")}.Multiply<{info.RightType}, {info.ReturnType}>(right); +}} + +public readonly partial record struct {info.RightType} +{{ + public static {info.ReturnType}[] operator *({info.LeftType}[] left, {info.RightType} right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * right._Value)" : "right._Value")}.Multiply<{info.LeftType}, {info.ReturnType}>(left); + public static List<{info.ReturnType}> operator *(List<{info.LeftType}> left, {info.RightType} right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * right._Value)" : "right._Value")}.Multiply<{info.LeftType}, {info.ReturnType}>(left); + public static IEnumerable<{info.ReturnType}> operator *(IEnumerable<{info.LeftType}> left, {info.RightType} right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * right._Value)" : "right._Value")}.Multiply<{info.LeftType}, {info.ReturnType}>(left); +}}"; + } + + private static string GenerateDivisionSource(OperatorInfo info) + { + return $@"// +using System; +using System.Collections.Generic; + +namespace {info.Namespace}; + +public readonly partial record struct {info.LeftType} +{{ + public static {info.ReturnType}[] operator /({info.LeftType} left, {info.RightType}[] right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * left._Value)" : "left._Value")}.Divide<{info.RightType}, {info.ReturnType}>(right); + public static List<{info.ReturnType}> operator /({info.LeftType} left, List<{info.RightType}> right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * left._Value)" : "left._Value")}.Divide<{info.RightType}, {info.ReturnType}>(right); + public static IEnumerable<{info.ReturnType}> operator /({info.LeftType} left, IEnumerable<{info.RightType}> right) => {(info.HasCoeff ? $"({info.CoeffType}.{info.CoeffName} * left._Value)" : "left._Value")}.Divide<{info.RightType}, {info.ReturnType}>(right); +}} + +public readonly partial record struct {info.RightType} +{{ + public static {info.ReturnType}[] operator /({info.LeftType}[] left, {info.RightType} right) => {(info.HasCoeff ? $"left.Multiply<{info.LeftType}, {info.ReturnType}>({info.CoeffType}.{info.CoeffName} / right._Value)" : $"left.Divide<{info.LeftType}, {info.ReturnType}>(right._Value)")}; + public static List<{info.ReturnType}> operator /(List<{info.LeftType}> left, {info.RightType} right) => {(info.HasCoeff ? $"left.Multiply<{info.LeftType}, {info.ReturnType}>({info.CoeffType}.{info.CoeffName} / right._Value)" : $"left.Divide<{info.LeftType}, {info.ReturnType}>(right._Value)")}; + public static IEnumerable<{info.ReturnType}> operator /(IEnumerable<{info.LeftType}> left, {info.RightType} right) => {(info.HasCoeff ? $"left.Multiply<{info.LeftType}, {info.ReturnType}>({info.CoeffType}.{info.CoeffName} / right._Value)" : $"left.Divide<{info.LeftType}, {info.ReturnType}>(right._Value)")}; +}}"; + } + + private class OperatorInfo + { + public string Namespace { get; set; } = string.Empty; + public string LeftType { get; set; } = string.Empty; + public string RightType { get; set; } = string.Empty; + public string ReturnType { get; set; } = string.Empty; + public bool IsMultiplication { get; set; } + public bool IsDivision { get; set; } + public string CoeffName { get; set; } + public string CoeffType { get; set; } + public bool HasCoeff { get; set; } } } } \ No newline at end of file diff --git a/QWERTYkez.Mensura/Operators.cs b/QWERTYkez.Mensura/Operators.cs index 7dfbf60..7ff9cf1 100644 --- a/QWERTYkez.Mensura/Operators.cs +++ b/QWERTYkez.Mensura/Operators.cs @@ -1,32 +1,5 @@ namespace QWERTYkez.Mensura.Units; -internal static class OperationsExtension -{ - internal static TResult MultiplyProtected(this T1 t1, T2 t2) - where T1 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where T2 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where TResult : struct, IMensuraUnit, IEquatable, IMensuraUnit - => (t1.ToDouble() * t2.ToDouble()).ToUnit(); - - internal static TResult MultiplyProtected(this T1 t1, T2 t2, double multiplicator) - where T1 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where T2 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where TResult : struct, IMensuraUnit, IEquatable, IMensuraUnit - => (t1.ToDouble() * t2.ToDouble() * multiplicator).ToUnit(); - - internal static TResult DivideProtected(this T1 t1, T2 t2) - where T1 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where T2 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where TResult : struct, IMensuraUnit, IEquatable, IMensuraUnit - => (t1.ToDouble() / t2.ToDouble()).ToUnit(); - - internal static TResult DivideProtected(this T1 t1, T2 t2, double multiplicator) - where T1 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where T2 : struct, IMensuraUnit, IEquatable, IMensuraUnit - where TResult : struct, IMensuraUnit, IEquatable, IMensuraUnit - => (t1.ToDouble() * multiplicator / t2.ToDouble()).ToUnit(); -} - internal static class Coefficients { internal static double MultiplyCoefficient(T1 a, T2 b, TResult r) @@ -45,172 +18,153 @@ internal static class Coefficients -[CollectionsOperatorsGenerator] public readonly partial record struct Length + + +public readonly partial record struct Length { - [CollectionsOperatorsGenerator] public static Area operator *(Length left, Length right) - => left.MultiplyProtected(right, Coeff1); - - static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MilliMeter, MilliMeter, Area.MilliMeterSquared); + [OperatorsGenerator] public static Area operator *(Length left, Length right) => new(left._Value * right._Value); - [CollectionsOperatorsGenerator] public static Volume operator *(Area left, Length right) => right * left; - [CollectionsOperatorsGenerator] public static Volume operator *(Length left, Area right) - => left.MultiplyProtected(right, Coeff2); - - static readonly double Coeff2 = Coefficients.MultiplyCoefficient(MilliMeter, Area.MilliMeterSquared, Volume.MilliMeterCubic); + public static Volume operator *(Area left, Length right) => right * left; + [OperatorsGenerator] public static Volume operator *(Length left, Area right) => new(left._Value * right._Value); - [CollectionsOperatorsGenerator] public static Pressure operator *(Length left, ForceVolumetric right) => right * left; - [CollectionsOperatorsGenerator] public static Pressure operator *(ForceVolumetric left, Length right) => left.MultiplyProtected(right, Coeff3); - static readonly double Coeff3 = Coefficients.MultiplyCoefficient(ForceVolumetric.NewtonPerMeterCubic, Length.Meter, Pressure.NewtonPerMeterSquared); + public static Pressure operator *(Length left, ForceVolumetric right) => right * left; + [OperatorsGenerator(nameof(Coeff1))] public static Pressure operator *(ForceVolumetric left, Length right) => new(left._Value * right._Value * Coeff1); + public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(ForceVolumetric.NewtonPerMeterCubic, Length.Meter, Pressure.NewtonPerMeterSquared); - [CollectionsOperatorsGenerator] public static Torque operator *(Force left, Length right) => right * left; - [CollectionsOperatorsGenerator] public static Torque operator *(Length left, Force right) => left.MultiplyProtected(right, Coeff6); - static readonly double Coeff6 = Coefficients.MultiplyCoefficient(Length.Meter, Force.Newton, Torque.Newton_Meter); + public static Torque operator *(Force left, Length right) => right * left; + [OperatorsGenerator(nameof(Coeff2))] public static Torque operator *(Length left, Force right) => new(left._Value * right._Value * Coeff2); + public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Length.Meter, Force._Newton, Torque._Newton_Meter); } -[CollectionsOperatorsGenerator] public readonly partial record struct Mass // Grams +public readonly partial record struct Mass // Grams { } -[CollectionsOperatorsGenerator] public readonly partial record struct Pressure // Pascals +public readonly partial record struct Pressure // Pascals { - [CollectionsOperatorsGenerator] public static Length operator /(Pressure left, ForceVolumetric right) => left.DivideProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.DivideCoefficient(Pressure.Pascal, ForceVolumetric.NewtonPerMeterCubic, Length.Meter); + [OperatorsGenerator(nameof(Coeff1))] public static Length operator /(Pressure left, ForceVolumetric right) => new(left._Value * Coeff1 / right._Value); + public static readonly double Coeff1 = Coefficients.DivideCoefficient(Pressure._Pascal, ForceVolumetric.NewtonPerMeterCubic, Length.Meter); - [CollectionsOperatorsGenerator] public static Force operator *(Pressure left, Area right) => right * left; - [CollectionsOperatorsGenerator] public static Force operator *(Area left, Pressure right) => left.MultiplyProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Area.MeterSquared, Pressure.Pascal, Force.Newton); + public static Force operator *(Pressure left, Area right) => right * left; + [OperatorsGenerator(nameof(Coeff2))] public static Force operator *(Area left, Pressure right) => new (left._Value * right._Value * Coeff2); + public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Area.MeterSquared, Pressure._Pascal, Force._Newton); - [CollectionsOperatorsGenerator] public static Length operator /(ForceLinear left, Pressure right) => left.DivideProtected(right, Coeff3); - static readonly double Coeff3 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, Pressure.NewtonPerMilliMeterSquared, Length.MilliMeter); + [OperatorsGenerator(nameof(Coeff3))] public static Length operator /(ForceLinear left, Pressure right) => new(left._Value * Coeff3 / right._Value); + public static readonly double Coeff3 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, Pressure.NewtonPerMilliMeterSquared, Length._MilliMeter); - [CollectionsOperatorsGenerator] public static ForceLinear operator *(Pressure left, Length right) => right * left; - [CollectionsOperatorsGenerator] public static ForceLinear operator *(Length left, Pressure right) => left.MultiplyProtected(right, Coeff4); - static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length.MilliMeter, Pressure.NewtonPerMilliMeterSquared, ForceLinear._NewtonPerMilliMeter); + public static ForceLinear operator *(Pressure left, Length right) => right * left; + [OperatorsGenerator(nameof(Coeff4))] public static ForceLinear operator *(Length left, Pressure right) => new(left._Value * right._Value * Coeff4); + public static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length._MilliMeter, Pressure.NewtonPerMilliMeterSquared, ForceLinear._NewtonPerMilliMeter); } -[CollectionsOperatorsGenerator] public readonly partial record struct Area // MilliMetersSquared +public readonly partial record struct Area // MilliMetersSquared { - [CollectionsOperatorsGenerator] public static Torque operator *(ForceLinear left, Area right) => right * left; - [CollectionsOperatorsGenerator] public static Torque operator *(Area left, ForceLinear right) => left.MultiplyProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Area.MeterSquared, ForceLinear.NewtonPerMeter, Torque.Newton_Meter); + public static Torque operator *(ForceLinear left, Area right) => right * left; + [OperatorsGenerator(nameof(Coeff1))] public static Torque operator *(Area left, ForceLinear right) => new(left._Value * right._Value * Coeff1); + public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Area.MeterSquared, ForceLinear.NewtonPerMeter, Torque._Newton_Meter); - [CollectionsOperatorsGenerator] public static Length operator /(Area left, Length right) => left.DivideProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.DivideCoefficient(Area.MilliMeterSquared, Length.MilliMeter, Length.MilliMeter); + [OperatorsGenerator] public static Length operator /(Area left, Length right) => new(left._Value / right._Value); } -[CollectionsOperatorsGenerator] public readonly partial record struct Volume // MillimetersCubic +public readonly partial record struct Volume // MillimetersCubic { - [CollectionsOperatorsGenerator] public static Torque operator *(Pressure left, Volume right) => right * left; - [CollectionsOperatorsGenerator] public static Torque operator *(Volume left, Pressure right) => left.MultiplyProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Volume.MeterCubic, Pressure.Pascal, Torque.Newton_Meter); + public static Torque operator *(Pressure left, Volume right) => right * left; + [OperatorsGenerator(nameof(Coeff2))] public static Torque operator *(Volume left, Pressure right) => new(left._Value * right._Value * Coeff2); + public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Volume.MeterCubic, Pressure._Pascal, Torque._Newton_Meter); - [CollectionsOperatorsGenerator] public static Area operator /(Volume left, Length right) => left.DivideProtected(right); - [CollectionsOperatorsGenerator] public static Length operator /(Volume left, Area right) => left.DivideProtected(right, Coeff3); - static readonly double Coeff3 = Coefficients.DivideCoefficient(Volume.MilliMeterCubic, Length.MilliMeter, Area.MilliMeterSquared); + [OperatorsGenerator] public static Area operator /(Volume left, Length right) => new(left._Value / right._Value); + [OperatorsGenerator] public static Length operator /(Volume left, Area right) => new(left._Value / right._Value); } -[CollectionsOperatorsGenerator] public readonly partial record struct Force // Newtons +public readonly partial record struct Force // Newtons { - [CollectionsOperatorsGenerator] public static Area operator /(Force left, Pressure right) => left.DivideProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.DivideCoefficient(Force.Newton, Pressure.Pascal, Area.MeterSquared); - [CollectionsOperatorsGenerator] public static Pressure operator /(Force left, Area right) => left.DivideProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.DivideCoefficient(Force.Newton, Area.MeterSquared, Pressure.Pascal); + [OperatorsGenerator(nameof(Coeff1))] public static Area operator /(Force left, Pressure right) => new(left._Value * Coeff1 / right._Value); + public static readonly double Coeff1 = Coefficients.DivideCoefficient(Force._Newton, Pressure._Pascal, Area.MeterSquared); + [OperatorsGenerator(nameof(Coeff2))] public static Pressure operator /(Force left, Area right) => new(left._Value * Coeff2 / right._Value); + public static readonly double Coeff2 = Coefficients.DivideCoefficient(Force._Newton, Area.MeterSquared, Pressure._Pascal); } -[CollectionsOperatorsGenerator] public readonly partial record struct Torque // NewtonMeters +public readonly partial record struct Torque // NewtonMeters { - [CollectionsOperatorsGenerator] public static Length operator /(Torque left, Force right) => left.DivideProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Force.Newton, Length.Meter); - [CollectionsOperatorsGenerator] public static Force operator /(Torque left, Length right) => left.DivideProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Length.Meter, Force.Newton); - [CollectionsOperatorsGenerator] public static ForceLinear operator /(Torque left, Area right) => left.DivideProtected(right, Coeff3); - static readonly double Coeff3 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Area.MilliMeterSquared, ForceLinear.KiloNewtonPerMilliMeter ); - [CollectionsOperatorsGenerator] public static Pressure operator /(Torque left, Volume right) => left.DivideProtected(right, Coeff4); - static readonly double Coeff4 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Volume.MeterCubic, Pressure.Pascal); - [CollectionsOperatorsGenerator] public static Volume operator /(Torque left, Pressure right) => left.DivideProtected(right, Coeff5); - static readonly double Coeff5 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Pressure.Pascal, Volume.MeterCubic); + [OperatorsGenerator(nameof(Coeff1))] public static Length operator /(Torque left, Force right) => new(left._Value * Coeff1 / right._Value); + public static readonly double Coeff1 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Force._Newton, Length.Meter); + [OperatorsGenerator(nameof(Coeff2))] public static Force operator /(Torque left, Length right) => new(left._Value * Coeff2 / right._Value); + public static readonly double Coeff2 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Length.Meter, Force._Newton); + [OperatorsGenerator(nameof(Coeff3))] public static ForceLinear operator /(Torque left, Area right) => new(left._Value * Coeff3 / right._Value); + public static readonly double Coeff3 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Area._MilliMeterSquared, ForceLinear.KiloNewtonPerMilliMeter ); + [OperatorsGenerator(nameof(Coeff4))] public static Pressure operator /(Torque left, Volume right) => new(left._Value * Coeff4 / right._Value); + public static readonly double Coeff4 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Volume.MeterCubic, Pressure._Pascal); + [OperatorsGenerator(nameof(Coeff5))] public static Volume operator /(Torque left, Pressure right) => new(left._Value * Coeff5 / right._Value); + public static readonly double Coeff5 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Pressure._Pascal, Volume.MeterCubic); } -[CollectionsOperatorsGenerator] public readonly partial record struct Frequency // Hertz +public readonly partial record struct Frequency // Hertz { } -[CollectionsOperatorsGenerator] public readonly partial record struct Time +public readonly partial record struct Time { - [CollectionsOperatorsGenerator] public static Speed operator *(Boost left, Time right) => right * left; - [CollectionsOperatorsGenerator] public static Speed operator *(Time left, Boost right) => left.MultiplyProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Boost.MeterPerSecondSquared, Speed.MeterPerSecond); + public static Speed operator *(Boost left, Time right) => right * left; + [OperatorsGenerator(nameof(Coeff1))] public static Speed operator *(Time left, Boost right) => new(left._Value * right._Value * Coeff1); + public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Boost._MeterPerSecondSquared, Speed.MeterPerSecond); - [CollectionsOperatorsGenerator] public static Speed operator /(Length left, Time right) => left.DivideProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.DivideCoefficient(Length.Meter, Time.Second, Speed.MeterPerSecond); + [OperatorsGenerator(nameof(Coeff2))] public static Speed operator /(Length left, Time right) => new(left._Value * Coeff2 / right._Value); + public static readonly double Coeff2 = Coefficients.DivideCoefficient(Length.Meter, Time.Second, Speed.MeterPerSecond); } -[CollectionsOperatorsGenerator] public readonly partial record struct Speed +public readonly partial record struct Speed { - [CollectionsOperatorsGenerator] public static Length operator *(Speed left, Time right) => right * left; - [CollectionsOperatorsGenerator] public static Length operator *(Time left, Speed right) => left.MultiplyProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Speed.MeterPerSecond, Length.Meter); + public static Length operator *(Speed left, Time right) => right * left; + [OperatorsGenerator(nameof(Coeff1))] public static Length operator *(Time left, Speed right) => new(left._Value * right._Value * Coeff1); + public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Speed.MeterPerSecond, Length.Meter); - [CollectionsOperatorsGenerator] public static Boost operator /(Speed left, Time right) => left.DivideProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.DivideCoefficient(Speed.MeterPerSecond, Time.Second, Boost.MeterPerSecondSquared); + [OperatorsGenerator(nameof(Coeff2))] public static Boost operator /(Speed left, Time right) => new(left._Value * Coeff2 / right._Value); + public static readonly double Coeff2 = Coefficients.DivideCoefficient(Speed.MeterPerSecond, Time.Second, Boost._MeterPerSecondSquared); } -[CollectionsOperatorsGenerator] public readonly partial record struct Boost +public readonly partial record struct Boost { - [CollectionsOperatorsGenerator] public static Force operator *(Mass left, Boost right) => right * left; - [CollectionsOperatorsGenerator] public static Force operator *(Boost left, Mass right) => left.MultiplyProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, Mass.KiloGram, Force.Newton); + public static Force operator *(Mass left, Boost right) => right * left; + [OperatorsGenerator(nameof(Coeff1))] public static Force operator *(Boost left, Mass right) => new(left._Value * right._Value * Coeff1); + public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Boost._MeterPerSecondSquared, Mass.KiloGram, Force._Newton); - [CollectionsOperatorsGenerator] public static ForceLinear operator *(MassLinear left, Boost right) => right * left; - [CollectionsOperatorsGenerator] public static ForceLinear operator *(Boost left, MassLinear right) => left.MultiplyProtected(right, Coeff2); - static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, MassLinear.KiloGramPerMilliMeter, ForceLinear._NewtonPerMilliMeter); + public static ForceLinear operator *(MassLinear left, Boost right) => right * left; + [OperatorsGenerator(nameof(Coeff2))] public static ForceLinear operator *(Boost left, MassLinear right) => new(left._Value * right._Value * Coeff2); + public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Boost._MeterPerSecondSquared, MassLinear.KiloGramPerMilliMeter, ForceLinear._NewtonPerMilliMeter); - [CollectionsOperatorsGenerator] public static ForceVolumetric operator *(Density left, Boost right) => right * left; - [CollectionsOperatorsGenerator] public static ForceVolumetric operator *(Boost left, Density right) => left.MultiplyProtected(right, Coeff3); - static readonly double Coeff3 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic, ForceVolumetric._NewtonPerMilliMeterCubic); + public static ForceVolumetric operator *(Density left, Boost right) => right * left; + [OperatorsGenerator(nameof(Coeff3))] public static ForceVolumetric operator *(Boost left, Density right) => new(left._Value * right._Value * Coeff3); + public static readonly double Coeff3 = Coefficients.MultiplyCoefficient(Boost._MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic, ForceVolumetric._NewtonPerMilliMeterCubic); - [CollectionsOperatorsGenerator] public static MassLinear operator /(ForceLinear left, Boost right) => left.DivideProtected(right, Coeff4); - static readonly double Coeff4 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, Boost.MeterPerSecondSquared, MassLinear.KiloGramPerMilliMeter); + [OperatorsGenerator(nameof(Coeff4))] public static MassLinear operator /(ForceLinear left, Boost right) => new(left._Value * Coeff4 / right._Value); + public static readonly double Coeff4 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, Boost._MeterPerSecondSquared, MassLinear.KiloGramPerMilliMeter); - [CollectionsOperatorsGenerator] public static Density operator /(ForceVolumetric left, Boost right) => left.DivideProtected(right, Coeff5); - static readonly double Coeff5 = Coefficients.DivideCoefficient(ForceVolumetric._NewtonPerMilliMeterCubic, Boost.MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic); + [OperatorsGenerator(nameof(Coeff5))] public static Density operator /(ForceVolumetric left, Boost right) => new(left._Value * Coeff5 / right._Value); + public static readonly double Coeff5 = Coefficients.DivideCoefficient(ForceVolumetric._NewtonPerMilliMeterCubic, Boost._MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic); - [CollectionsOperatorsGenerator] public static MassPerSquare operator /(Pressure left, Boost right) => left.DivideProtected(right, Coeff6); - static readonly double Coeff6 = Coefficients.DivideCoefficient(Pressure.Pascal, Boost.MeterPerSecondSquared, MassPerSquare.KiloGramPerMeterSquared); + [OperatorsGenerator] public static MassPerSquare operator /(Pressure left, Boost right) => new(left._Value / right._Value); } -[CollectionsOperatorsGenerator] public readonly partial record struct MassPerSquare +public readonly partial record struct MassPerSquare { - [CollectionsOperatorsGenerator] public static Pressure operator *(Boost left, MassPerSquare right) => right * left; - [CollectionsOperatorsGenerator] public static Pressure operator *(MassPerSquare left, Boost right) => left.MultiplyProtected(right, Coeff1); - static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MassPerSquare.KiloGramPerMeterSquared, Boost.MeterPerSecondSquared, Pressure.Pascal); + public static Pressure operator *(Boost left, MassPerSquare right) => right * left; + [OperatorsGenerator] public static Pressure operator *(MassPerSquare left, Boost right) => new(left._Value * right._Value); } -//[CollectionsOperatorsGenerator] public readonly partial record struct LinearForce : Pogon -//{ +public readonly partial record struct MassLinear +{ + [OperatorsGenerator(nameof(Coeff1))] public static Boost operator /(ForceLinear left, MassLinear right) => new(left._Value * Coeff1 / right._Value); -//} - -//[CollectionsOperatorsGenerator] public readonly partial record struct MassLinear : Pogon -//{ -// [CollectionsOperatorsGenerator] public static Boost operator /(LinearForce left, MassLinear right) => left.DivideProtected(right, Coeff1); - -// static readonly double Coeff1 = Coefficients.DivideCoefficient(a => a.PerMilliMeter.Newtons = 1, b => b.PerMilliMeter.KiloGrams = 1, Boost.MeterPerSecondSquared); -//} - -//[CollectionsOperatorsGenerator] public readonly partial record struct ForceVolumetric : Udel -//{ - - -//} \ No newline at end of file + public static readonly double Coeff1 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, MassLinear.KiloGramPerMilliMeter, Boost._MeterPerSecondSquared); +} \ No newline at end of file diff --git a/QWERTYkez.Mensura/Units/Angle.cs b/QWERTYkez.Mensura/Units/Angle.cs index 148fd50..8084096 100644 --- a/QWERTYkez.Mensura/Units/Angle.cs +++ b/QWERTYkez.Mensura/Units/Angle.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("Radians = {Radians.ToString(\"0.###\")}, Degrees = {Degrees.ToString(\"0.###\")}")] public readonly partial record struct Angle { - public static Angle Second { get; } = new() { _Seconds = 1 }; + public static Angle _Second { get; } = new() { _Seconds = 1 }; [NotMapped, JsonIgnore] public double _Seconds { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Area.cs b/QWERTYkez.Mensura/Units/Area.cs index 8b07815..d6be498 100644 --- a/QWERTYkez.Mensura/Units/Area.cs +++ b/QWERTYkez.Mensura/Units/Area.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("mm2 = {_MilliMetersSquared.ToString(\"0.###\")}, m2 = {MetersSquared.ToString(\"0.###\")}")] public readonly partial record struct Area { - public static Area MilliMeterSquared { get; } = new() { _MilliMetersSquared = 1 }; + public static Area _MilliMeterSquared { get; } = new() { _MilliMetersSquared = 1 }; [NotMapped, JsonIgnore] public double _MilliMetersSquared { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Boost.cs b/QWERTYkez.Mensura/Units/Boost.cs index b2dc2c6..ef92cc2 100644 --- a/QWERTYkez.Mensura/Units/Boost.cs +++ b/QWERTYkez.Mensura/Units/Boost.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("m/s2 = {_MetersPerSecondSquared.ToString(\"0.###\")}")] public readonly partial record struct Boost { - public static Boost MeterPerSecondSquared { get; } = new() { _MetersPerSecondSquared = 1 }; + public static Boost _MeterPerSecondSquared { get; } = new() { _MetersPerSecondSquared = 1 }; [NotMapped, JsonIgnore] public double _MetersPerSecondSquared { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Gen.cs b/QWERTYkez.Mensura/Units/Complex/.LinearXXXXXXXX.Gen.cs similarity index 100% rename from QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Gen.cs rename to QWERTYkez.Mensura/Units/Complex/.LinearXXXXXXXX.Gen.cs diff --git a/QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Ref.cs b/QWERTYkez.Mensura/Units/Complex/.LinearXXXXXXXX.Ref.cs similarity index 100% rename from QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Ref.cs rename to QWERTYkez.Mensura/Units/Complex/.LinearXXXXXXXX.Ref.cs diff --git a/QWERTYkez.Mensura/Units/Complex/ForceLinear.cs b/QWERTYkez.Mensura/Units/Complex/ForceLinear.cs index 9ec525e..a21ece3 100644 --- a/QWERTYkez.Mensura/Units/Complex/ForceLinear.cs +++ b/QWERTYkez.Mensura/Units/Complex/ForceLinear.cs @@ -1,4 +1,4 @@ -namespace QWERTYkez.Mensura.Units.Complex; +namespace QWERTYkez.Mensura.Units; [ComplexUnitGenerator(nameof(Force), nameof(Length), nameof(ForceLinear))] public readonly partial record struct ForceLinear { @@ -56,23 +56,4 @@ init => _Value = value._Value / LengthConv.KiloMeters.Multiplicator; } -} - - - - - -//namespace MetricSystem; - -//[DebuggerDisplay("N/m = {PerMeter._Newtons.ToString(\"0.###\")}, kgf/m = {PerMeter.KiloGramXXXXXXXXs.ToString(\"0.###\")}")] -//public readonly partial record struct PogonXXXXXXXX -//{ - - -//} - -//public partial class Length : Metric -//{ -// [CollectionsOperatorsGenerator] public static PogonXXXXXXXX operator /(XXXXXXXX left, Length right) => left.DivideProtected(right, PogonXXXXXXXXCoeff); -// static readonly double PogonXXXXXXXXCoeff = Coefficients.DivideCoefficient(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1); -//} \ No newline at end of file +} \ No newline at end of file diff --git a/QWERTYkez.Mensura/Units/Complex/ForceVolumetric.cs b/QWERTYkez.Mensura/Units/Complex/ForceVolumetric.cs index eaa2d57..bf5ae2f 100644 --- a/QWERTYkez.Mensura/Units/Complex/ForceVolumetric.cs +++ b/QWERTYkez.Mensura/Units/Complex/ForceVolumetric.cs @@ -1,4 +1,4 @@ -namespace QWERTYkez.Mensura.Units.Complex; +namespace QWERTYkez.Mensura.Units; [ComplexUnitGenerator(nameof(Force), nameof(Volume), nameof(ForceVolumetric))] public readonly partial record struct ForceVolumetric { @@ -32,25 +32,4 @@ init => _Value = value._Value / VolumeConv.MetersCubic.Multiplicator; } -} - - - - - -//namespace MetricSystem; - -//[Owned, JsonConverter(typeof(MetricFormatter)), DebuggerDisplay("N/(m*mm2) = {PerMeter_PerMilliMeterSquared._Newtons.ToString(\"0.###\")}, kgf/(m*mm2) = {PerMeter_PerMilliMeterSquared.KiloGramForces.ToString(\"0.###\")}")] -//public partial class ForceVolumetric : Udel -//{ -// [CollectionsOperatorsGenerator] public static ForceVolumetric operator *(Area left, ForceVolumetric right) => right * left; - -// [CollectionsOperatorsGenerator] public static ForceVolumetric operator *(ForceVolumetric left, Area right) => left.MultiplyProtected(right, ForceVolumetricCoeff); -// static readonly double ForceVolumetricCoeff = Coefficients.MultiplyCoefficient(a => a._PerMilliMeterCubic.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeter.Value = 1); -//} - -//public partial class Volume : Metric -//{ -// [CollectionsOperatorsGenerator] public static ForceVolumetric operator /(Force left, Volume right) => left.DivideProtected(right, ForceVolumetricCoeff); -// static readonly double ForceVolumetricCoeff = Coefficients.DivideCoefficient(a => a.Value = 1, b => b._MilliMetersCubic = 1, r => r._PerMilliMeterCubic.Value = 1); -//} \ No newline at end of file +} \ No newline at end of file diff --git a/QWERTYkez.Mensura/Units/Complex/MassLinear.cs b/QWERTYkez.Mensura/Units/Complex/MassLinear.cs index e3682ad..a4de043 100644 --- a/QWERTYkez.Mensura/Units/Complex/MassLinear.cs +++ b/QWERTYkez.Mensura/Units/Complex/MassLinear.cs @@ -1,4 +1,4 @@ -namespace QWERTYkez.Mensura.Units.Complex; +namespace QWERTYkez.Mensura.Units; [ComplexUnitGenerator(nameof(Mass), nameof(Length), nameof(MassLinear))] public readonly partial record struct MassLinear { @@ -56,27 +56,4 @@ init => _Value = value._Value / LengthConv.KiloMeters.Multiplicator; } -} - - - - - - - - - - - -//[Owned, JsonConverter(typeof(MetricFormatter)), DebuggerDisplay("gr/m = {PerMeter._Grams.ToString(\"0.###\")}, kg/m = {PerMeter.KiloGrams.ToString(\"0.###\")}")] -//public partial class MassLinear : Pogon -//{ -// [CollectionsOperatorsGenerator] public static Density operator /(MassLinear left, Area right) => left.DivideProtected(right, UdelMassCoeff); -// static readonly double UdelMassCoeff = Coefficients.DivideCoefficient(a => a._PerMilliMeter.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeterCubic.Value = 1); -//} - -//public partial class Length : Metric -//{ -// [CollectionsOperatorsGenerator] public static MassLinear operator /(Mass left, Length right) => left.DivideProtected(right, MassLinearCoeff); -// static readonly double MassLinearCoeff = Coefficients.DivideCoefficient(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1); -//} \ No newline at end of file +} \ No newline at end of file diff --git a/QWERTYkez.Mensura/Units/Complex/MassVolumetric (Density).cs b/QWERTYkez.Mensura/Units/Complex/MassVolumetric (Density).cs index c096ea1..a102c91 100644 --- a/QWERTYkez.Mensura/Units/Complex/MassVolumetric (Density).cs +++ b/QWERTYkez.Mensura/Units/Complex/MassVolumetric (Density).cs @@ -1,4 +1,4 @@ -namespace QWERTYkez.Mensura.Units.Complex; +namespace QWERTYkez.Mensura.Units; [ComplexUnitGenerator(nameof(Mass), nameof(Volume), nameof(Density))] public readonly partial record struct Density { @@ -32,28 +32,4 @@ init => _Value = value._Value / VolumeConv.MetersCubic.Multiplicator; } -} - - - - - - - - -//namespace MetricSystem; - -//[Owned, JsonConverter(typeof(MetricFormatter)), DebuggerDisplay("gr/(m*mm2) = {PerMeterCubic_PerMilliMetersCubicquared._Grams.ToString(\"0.###\")}, kg/(m*mm2) = {PerMeterCubic_PerMilliMetersCubicquared.KiloGrams.ToString(\"0.###\")}")] -//public partial class Density : Udel -//{ -// [CollectionsOperatorsGenerator] public static PogonMass operator *(Area left, Density right) => right * left; - -// [CollectionsOperatorsGenerator] public static PogonMass operator *(Density left, Area right) => left.MultiplyProtected(right, PogonMassCoeff); -// static readonly double PogonMassCoeff = Coefficients.MultiplyCoefficient(a => a._PerMilliMeterCubicCubic.Value = 1, b => b._MilliMetersCubicSquared = 1, r => r._PerMilliMeterCubic.Value = 1); -//} - -//public partial class Volume : Metric -//{ -// [CollectionsOperatorsGenerator] public static Density operator /(Mass left, Volume right) => left.DivideProtected(right, DensityCoeff); -// static readonly double DensityCoeff = Coefficients.DivideCoefficient(a => a.Value = 1, b => b._MilliMetersCubicCubic = 1, r => r._PerMilliMeterCubicCubic.Value = 1); -//} \ No newline at end of file +} \ No newline at end of file diff --git a/QWERTYkez.Mensura/Units/Force.cs b/QWERTYkez.Mensura/Units/Force.cs index 499135a..089a22e 100644 --- a/QWERTYkez.Mensura/Units/Force.cs +++ b/QWERTYkez.Mensura/Units/Force.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("N = {_Newtons.ToString(\"0.###\")}, kgf = {KiloGramForces.ToString(\"0.###\")}")] public readonly partial record struct Force { - public static Force Newton { get; } = new() { _Newtons = 1 }; + public static Force _Newton { get; } = new() { _Newtons = 1 }; [NotMapped, JsonIgnore] public double _Newtons { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Frequency.cs b/QWERTYkez.Mensura/Units/Frequency.cs index 15c72ce..f9fad51 100644 --- a/QWERTYkez.Mensura/Units/Frequency.cs +++ b/QWERTYkez.Mensura/Units/Frequency.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("Hz = {_Hertz.ToString(\"0.###\")}")] public readonly partial record struct Frequency { - public static Frequency OneHertz { get; } = new() { _Hertz = 1 }; + public static Frequency _OneHertz { get; } = new() { _Hertz = 1 }; [NotMapped, JsonIgnore] public double _Hertz { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Length.cs b/QWERTYkez.Mensura/Units/Length.cs index 5c7fc06..d18fd6f 100644 --- a/QWERTYkez.Mensura/Units/Length.cs +++ b/QWERTYkez.Mensura/Units/Length.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("mm = {_MilliMeters.ToString(\"0.###\")}, m = {Meters.ToString(\"0.###\")}")] public readonly partial record struct Length { - public static Length MilliMeter { get; } = new(1); + public static Length _MilliMeter { get; } = new(1); [NotMapped, JsonIgnore] public double _MilliMeters { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Mass.cs b/QWERTYkez.Mensura/Units/Mass.cs index 9eae302..f9cabf1 100644 --- a/QWERTYkez.Mensura/Units/Mass.cs +++ b/QWERTYkez.Mensura/Units/Mass.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("gr = {_Grams.ToString(\"0.###\")}, kg = {KiloGrams.ToString(\"0.###\")}")] public readonly partial record struct Mass { - public static Mass Gram { get; } = new() { _Grams = 1 }; + public static Mass _Gram { get; } = new() { _Grams = 1 }; [NotMapped, JsonIgnore] public double _Grams { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/MassPerSquare.cs b/QWERTYkez.Mensura/Units/MassPerSquare.cs index 97294ae..b215eea 100644 --- a/QWERTYkez.Mensura/Units/MassPerSquare.cs +++ b/QWERTYkez.Mensura/Units/MassPerSquare.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("kg/m2 = {_KiloGramsPerMeterSquared.ToString(\"0.###\")}, kg/mm2 = {KiloGramsPerMilliMeterSquared.ToString(\"0.###\")}")] public readonly partial record struct MassPerSquare { - public static MassPerSquare KiloGramPerMeterSquared { get; } = new() { _KiloGramsPerMeterSquared = 1 }; + public static MassPerSquare _KiloGramPerMeterSquared { get; } = new() { _KiloGramsPerMeterSquared = 1 }; [NotMapped, JsonIgnore] public double _KiloGramsPerMeterSquared { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Pogon/.Pogon.cs b/QWERTYkez.Mensura/Units/Pogon/.Pogon.cs deleted file mode 100644 index 62f5124..0000000 --- a/QWERTYkez.Mensura/Units/Pogon/.Pogon.cs +++ /dev/null @@ -1,149 +0,0 @@ -//namespace MetricSystem; - -///// -///// Base value is PerMilliMeter -///// -//public abstract class Pogon -//{ - - -// internal T PerValue { get; init; } - - - - - - - -// [NotMapped, JsonIgnore] internal T PerValue -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value -// }; -// } -// set -// { -// Value = value.Value; -// } -// } -// [NotMapped, JsonIgnore] public T _PerMilliMeter -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value -// }; -// } -// set -// { -// Value = value.Value; -// } -// } - - -// [NotMapped, JsonIgnore] public T PerMilliMeter -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value -// }; -// } -// set -// { -// Value = value.Value; -// } -// } -// [NotMapped, JsonIgnore] public T PerCentiMeter -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * LengthConv.CentiMeters.Multiplicator, -// BaseContainerMultiplicator = LengthConv.CentiMeters.Multiplicator, -// }; -// } -// set -// { -// Value = value.Value / LengthConv.CentiMeters.Multiplicator; -// } -// } -// [NotMapped, JsonIgnore] public T PerDeciMeter -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * LengthConv.DeciMeters.Multiplicator, -// BaseContainerMultiplicator = LengthConv.DeciMeters.Multiplicator, -// }; -// } -// set -// { -// Value = value.Value / LengthConv.DeciMeters.Multiplicator; -// } -// } -// [NotMapped, JsonIgnore] public T PerMeter -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * LengthConv.Meters.Multiplicator, -// BaseContainerMultiplicator = LengthConv.Meters.Multiplicator, -// }; -// } -// set -// { -// Value = value.Value / LengthConv.Meters.Multiplicator; -// } -// } -// [NotMapped, JsonIgnore] public T PerKiloMeter -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * LengthConv.KiloMeters.Multiplicator, -// BaseContainerMultiplicator = LengthConv.KiloMeters.Multiplicator, -// }; -// } -// set -// { -// Value = value.Value / LengthConv.KiloMeters.Multiplicator; -// } -// } - -// public static T operator *(Pogon left, Length right) => ((U)left).Protect()._PerMilliMeter * right.Protect()._MilliMeters; -// public static MetricCollection operator *(Pogon left, MetricCollection right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); -// public static MetricArray operator *(Pogon left, MetricArray right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); -// public static MetricList operator *(Pogon left, MetricList right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); -// public static MetricObservableCollection operator *(Pogon left, MetricObservableCollection right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); - - -// public static T operator *(Length left, Pogon right) => ((U)right).Protect()._PerMilliMeter * left.Protect()._MilliMeters; -// public static MetricCollection operator *(MetricCollection left, Pogon right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); -// public static MetricArray operator *(MetricArray left, Pogon right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); -// public static MetricList operator *(MetricList left, Pogon right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); -// public static MetricObservableCollection operator *(MetricObservableCollection left, Pogon right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); - - -// public static Length operator /(T left, Pogon right) => new() { _MilliMeters = left.Protect() / ((U)right).Protect()._PerMilliMeter }; -// public static MetricCollection operator *(MetricCollection left, Pogon right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -// public static MetricArray operator *(MetricArray left, Pogon right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -// public static MetricList operator *(MetricList left, Pogon right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -// public static MetricObservableCollection operator *(MetricObservableCollection left, Pogon right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -//} \ No newline at end of file diff --git a/QWERTYkez.Mensura/Units/Pressure.cs b/QWERTYkez.Mensura/Units/Pressure.cs index 54d9098..4763d99 100644 --- a/QWERTYkez.Mensura/Units/Pressure.cs +++ b/QWERTYkez.Mensura/Units/Pressure.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("Pa, N/m2 = {NewtonsPerMeterSquared.ToString(\"0.###\")}, kgf/mm2 = {KiloGramForcesPerMilliMeterSquared.ToString(\"0.###\")}")] public readonly partial record struct Pressure { - public static Pressure Pascal { get; } = new() { _Pascals = 1 }; + public static Pressure _Pascal { get; } = new() { _Pascals = 1 }; [NotMapped, JsonIgnore] public double _Pascals { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Speed.cs b/QWERTYkez.Mensura/Units/Speed.cs index 2a03450..995e83d 100644 --- a/QWERTYkez.Mensura/Units/Speed.cs +++ b/QWERTYkez.Mensura/Units/Speed.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("km/h = {_KiloMetersPerHour.ToString(\"0.###\")}, m/s = {MetersPerSecond.ToString(\"0.###\")}")] public readonly partial record struct Speed { - public static Speed KiloMeterPerHour { get; } = new() { _KiloMetersPerHour = 1 }; + public static Speed _KiloMeterPerHour { get; } = new() { _KiloMetersPerHour = 1 }; [NotMapped, JsonIgnore] public double _KiloMetersPerHour { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Time.cs b/QWERTYkez.Mensura/Units/Time.cs index d110dcd..2cb3f21 100644 --- a/QWERTYkez.Mensura/Units/Time.cs +++ b/QWERTYkez.Mensura/Units/Time.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("ms = {_MilliSeconds.ToString(\"0.###\")}, s = {Seconds.ToString(\"0.###\")}")] public readonly partial record struct Time { - public static Time MilliSecond { get; } = new() { _MilliSeconds = 1 }; + public static Time _MilliSecond { get; } = new() { _MilliSeconds = 1 }; [NotMapped, JsonIgnore] public double _MilliSeconds { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Torque.cs b/QWERTYkez.Mensura/Units/Torque.cs index c08327b..f02bfbc 100644 --- a/QWERTYkez.Mensura/Units/Torque.cs +++ b/QWERTYkez.Mensura/Units/Torque.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("N*m = {_Newton_Meters.ToString(\"0.###\")}, kgf*m = {KiloGramForce_Meters.ToString(\"0.###\")}")] public readonly partial record struct Torque { - public static Torque Newton_Meter { get; } = new() { _Newton_Meters = 1 }; + public static Torque _Newton_Meter { get; } = new() { _Newton_Meters = 1 }; [NotMapped, JsonIgnore] public double _Newton_Meters { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Udel/.Udel.cs b/QWERTYkez.Mensura/Units/Udel/.Udel.cs deleted file mode 100644 index 2da194b..0000000 --- a/QWERTYkez.Mensura/Units/Udel/.Udel.cs +++ /dev/null @@ -1,175 +0,0 @@ -//namespace MetricSystem; - -///// -///// Base value is PerMilliMeterCubic -///// -//[Owned] -//public abstract class Udel : Metric> -// where U : Udel, new() -// where T : Metric, new() -//{ -// protected override void OnValueChanged() -// { -// OnPropertyChanged(nameof(PerMeter_PerMilliMeterSquared)); -// OnPropertyChanged(nameof(PerMilliMeterCubic)); -// OnPropertyChanged(nameof(PerCentiMeterCubic)); -// OnPropertyChanged(nameof(PerDeciMeterCubic)); -// OnPropertyChanged(nameof(PerMeterCubic)); -// OnPropertyChanged(nameof(PerKiloMeterCubic)); -// } - -// [NotMapped, JsonIgnore] internal T PerValue -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value, -// }; -// } -// set -// { -// Value = value.Value; -// OnPropertyChanged(nameof(PerValue)); -// } -// } -// [NotMapped, JsonIgnore] public T _PerMilliMeterCubic -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value, -// }; -// } -// set -// { -// Value = value.Value; -// OnPropertyChanged(nameof(_PerMilliMeterCubic)); -// } -// } - - -// [NotMapped, JsonIgnore] public T PerMilliMeterCubic -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value, -// }; -// } -// set -// { -// Value = value.Value; -// OnPropertyChanged(nameof(PerMilliMeterCubic)); -// } -// } -// [NotMapped, JsonIgnore] public T PerMeter_PerMilliMeterSquared -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * LengthConv.Meters.Multiplicator * Math.Pow(LengthConv.MilliMeters.Multiplicator, 2), -// BaseContainerMultiplicator = LengthConv.Meters.Multiplicator * Math.Pow(LengthConv.MilliMeters.Multiplicator, 2), -// }; -// } -// set -// { -// Value = value.Value / (LengthConv.Meters.Multiplicator * Math.Pow(LengthConv.MilliMeters.Multiplicator, 2)); -// OnPropertyChanged(nameof(PerMeter_PerMilliMeterSquared)); -// } -// } -// [NotMapped, JsonIgnore] public T PerCentiMeterCubic -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * Math.Pow(LengthConv.CentiMeters.Multiplicator, 3), -// BaseContainerMultiplicator = Math.Pow(LengthConv.CentiMeters.Multiplicator, 3), -// }; -// } -// set -// { -// Value = value.Value / Math.Pow(LengthConv.CentiMeters.Multiplicator, 3); -// OnPropertyChanged(nameof(PerCentiMeterCubic)); -// } -// } -// [NotMapped, JsonIgnore] public T PerDeciMeterCubic -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * Math.Pow(LengthConv.DeciMeters.Multiplicator, 3), -// BaseContainerMultiplicator = Math.Pow(LengthConv.DeciMeters.Multiplicator, 3), -// }; -// } -// set -// { -// Value = value.Value / Math.Pow(LengthConv.DeciMeters.Multiplicator, 3); -// OnPropertyChanged(nameof(PerDeciMeterCubic)); -// } -// } -// [NotMapped, JsonIgnore] public T PerMeterCubic -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * Math.Pow(LengthConv.Meters.Multiplicator, 3), -// BaseContainerMultiplicator = Math.Pow(LengthConv.Meters.Multiplicator, 3), -// }; -// } -// set -// { -// Value = value.Value / Math.Pow(LengthConv.Meters.Multiplicator, 3); -// OnPropertyChanged(nameof(PerMeterCubic)); -// } -// } -// [NotMapped, JsonIgnore] public T PerKiloMeterCubic -// { -// get -// { -// return new() -// { -// BaseContainer = this, -// SilentValueSetter = Value * Math.Pow(LengthConv.KiloMeters.Multiplicator, 3), -// BaseContainerMultiplicator = Math.Pow(LengthConv.KiloMeters.Multiplicator, 3), -// }; -// } -// set -// { -// Value = value.Value / Math.Pow(LengthConv.KiloMeters.Multiplicator, 3); -// OnPropertyChanged(nameof(PerKiloMeterCubic)); -// } -// } - - -// public static T operator *(Udel left, Volume right) => ((U)left).Protect()._PerMilliMeterCubic * right.Protect()._MilliMetersCubic; -// public static MetricCollection operator *(Udel left, MetricCollection right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); -// public static MetricArray operator *(Udel left, MetricArray right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); -// public static MetricList operator *(Udel left, MetricList right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); -// public static MetricObservableCollection operator *(Udel left, MetricObservableCollection right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect()); - -// public static T operator *(Volume left, Udel right) => ((U)right).Protect()._PerMilliMeterCubic * left.Protect()._MilliMetersCubic; -// public static MetricCollection operator *(MetricCollection left, Udel right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); -// public static MetricArray operator *(MetricArray left, Udel right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); -// public static MetricList operator *(MetricList left, Udel right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); -// public static MetricObservableCollection operator *(MetricObservableCollection left, Udel right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect()); - -// public static Volume operator /(T left, Udel right) => new() { _MilliMetersCubic = left.Protect() / ((U)right).Protect()._PerMilliMeterCubic }; -// public static MetricCollection operator *(MetricCollection left, Udel right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -// public static MetricArray operator *(MetricArray left, Udel right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -// public static MetricList operator *(MetricList left, Udel right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -// public static MetricObservableCollection operator *(MetricObservableCollection left, Udel right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect()); -//} \ No newline at end of file diff --git a/QWERTYkez.Mensura/Units/Voltage.cs b/QWERTYkez.Mensura/Units/Voltage.cs index 1e93a08..31864c9 100644 --- a/QWERTYkez.Mensura/Units/Voltage.cs +++ b/QWERTYkez.Mensura/Units/Voltage.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("V = {_Volts.ToString(\"0.###\")}")] public readonly partial record struct Voltage { - public static Voltage Volt { get; } = new() { _Volts = 1 }; + public static Voltage _Volt { get; } = new() { _Volts = 1 }; [NotMapped, JsonIgnore] public double _Volts { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/Units/Volume.cs b/QWERTYkez.Mensura/Units/Volume.cs index 8ac83fb..eabdeda 100644 --- a/QWERTYkez.Mensura/Units/Volume.cs +++ b/QWERTYkez.Mensura/Units/Volume.cs @@ -6,7 +6,7 @@ [UnitGenerator, DebuggerDisplay("mm3 = {_MilliMetersCubic.ToString(\"0.###\")}, m3 = {MetersCubic.ToString(\"0.###\")}")] public readonly partial record struct Volume { - public static Volume MilliMeterCubic { get; } = new() { _MilliMetersCubic = 1 }; + public static Volume _MilliMeterCubic { get; } = new() { _MilliMetersCubic = 1 }; [NotMapped, JsonIgnore] public double _MilliMetersCubic { get => _Value; init => _Value = value; } diff --git a/QWERTYkez.Mensura/globals.cs b/QWERTYkez.Mensura/globals.cs index fd61be9..27b3634 100644 --- a/QWERTYkez.Mensura/globals.cs +++ b/QWERTYkez.Mensura/globals.cs @@ -12,5 +12,4 @@ global using System.Text.Json; global using System.Text.Json.Serialization; global using QWERTYkez.Mensura; global using QWERTYkez.Mensura.Extensions; -global using QWERTYkez.Mensura.Units; -global using QWERTYkez.Mensura.Units.Complex; \ No newline at end of file +global using QWERTYkez.Mensura.Units; \ No newline at end of file