This commit is contained in:
melekhin
2026-06-05 12:13:35 +07:00
parent 96bbbbd292
commit 4ff3cc7042
30 changed files with 1875 additions and 1478 deletions

View File

@@ -0,0 +1,638 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using System.Text;
namespace G;
[Generator]
public class ComplexUnitGenerator : IIncrementalGenerator
{
private const string AttributeName = "ComplexUnitGenerator";
public void Initialize(IncrementalGeneratorInitializationContext context)
{
// 1. Генерируем определение атрибута
context.RegisterPostInitializationOutput(ctx =>
{
string attributeSource = @"
namespace QWERTYkez.Mensura
{
[System.AttributeUsage(System.AttributeTargets.Struct, AllowMultiple = false)]
public sealed class ComplexUnitGeneratorAttribute : System.Attribute
{
public string TypeNameA { get; }
public string TypeNameB { get; }
public string TypeNameZ { get; }
public ComplexUnitGeneratorAttribute(string typeNameA, string typeNameB, string typeNameZ)
{
TypeNameA = typeNameA;
TypeNameB = typeNameB;
TypeNameZ = typeNameZ;
}
}
}";
ctx.AddSource(".ComplexUnitGeneratorAttribute.g.cs", SourceText.From(attributeSource, Encoding.UTF8));
});
// 2. Ищем все readonly partial record struct с этим атрибутом
var structsProvider = context.SyntaxProvider
.CreateSyntaxProvider(
predicate: static (node, _) => IsTargetStruct(node),
transform: static (ctx, _) => GetStructInfo(ctx))
.Where(info => info.HasValue)
.Select((info, _) => info!.Value)
.Collect();
// 3. Регистрируем вывод для каждой найденной структуры
context.RegisterSourceOutput(structsProvider, (spc, structs) =>
{
foreach (var structInfo in structs)
{
string generatedCode = GeneratePartial(structInfo.TypeName, structInfo.Namespace,
structInfo.TypeNameA, structInfo.TypeNameB, structInfo.TypeNameZ);
spc.AddSource($"{structInfo.TypeName}.g.cs", SourceText.From(generatedCode, Encoding.UTF8));
}
});
}
private static bool IsTargetStruct(SyntaxNode node)
{
if (node is not RecordDeclarationSyntax record)
return false;
// Должен быть record struct с модификаторами readonly и partial
if (!record.Modifiers.Any(SyntaxKind.ReadOnlyKeyword) ||
!record.Modifiers.Any(SyntaxKind.PartialKeyword) ||
!record.Keyword.IsKind(SyntaxKind.RecordKeyword) ||
!record.ClassOrStructKeyword.IsKind(SyntaxKind.StructKeyword))
return false;
// Проверяем наличие атрибута [ComplexUnitGenerator] или [ComplexUnitGeneratorAttribute]
foreach (var attrList in record.AttributeLists)
foreach (var attr in attrList.Attributes)
{
string name = attr.Name.ToString();
if (name == AttributeName || name == AttributeName + "Attribute")
return true;
}
return false;
}
private static StructInfo? GetStructInfo(GeneratorSyntaxContext context)
{
var record = (RecordDeclarationSyntax)context.Node;
var semanticModel = context.SemanticModel;
if (semanticModel.GetDeclaredSymbol(record) is not INamedTypeSymbol typeSymbol)
return null;
string namespaceName = typeSymbol.ContainingNamespace?.ToString() ?? "";
if (string.IsNullOrEmpty(namespaceName))
return null;
// Извлекаем аргументы атрибута
string typeNameA = null;
string typeNameB = null;
string typeNameZ = null;
foreach (var attrList in record.AttributeLists)
foreach (var attr in attrList.Attributes)
{
string name = attr.Name.ToString();
if (name == AttributeName || name == AttributeName + "Attribute")
{
// Ищем аргументы конструктора
var args = attr.ArgumentList?.Arguments;
if (args.HasValue && args.Value.Count >= 3)
{
typeNameA = GetStringFromExpression(args.Value[0].Expression, semanticModel);
typeNameB = GetStringFromExpression(args.Value[1].Expression, semanticModel);
typeNameZ = GetStringFromExpression(args.Value[2].Expression, semanticModel);
}
break;
}
}
if (typeNameA == null || typeNameB == null || typeNameZ == null)
return null;
return new StructInfo(namespaceName, typeSymbol.Name, typeNameA, typeNameB, typeNameZ);
}
private static string GetStringFromExpression(ExpressionSyntax expr, SemanticModel semanticModel)
{
// Поддерживаем строковые литералы и константы
if (expr is LiteralExpressionSyntax literal && literal.IsKind(SyntaxKind.StringLiteralExpression))
return literal.Token.ValueText;
// Если это доступ к константе, пытаемся вычислить через семантику
var constantValue = semanticModel.GetConstantValue(expr);
if (constantValue.HasValue && constantValue.Value is string s)
return s;
return null;
}
private static string GeneratePartial(string typeName, string ns, string typeNameA, string typeNameB, string typeNameZ)
{
// Шаблон, который вы вставите сами.
// В нём используйте {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};
using System.Globalization;
using System.Runtime.Serialization;
namespace QWERTYkez.Mensura.Units
{
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());
// === 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<T> ===
[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<T> ===
[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)));
// === 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<T> ===
[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<T> ===
[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<T> ===
[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<T> ===
[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)));
// === 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<T> ===
[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<T> ===
[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
{
[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<T> ===
[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<T> ===
[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<T> ===
[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<T> ===
[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;
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);
}
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 template
.Replace("{ns}", ns)
.Replace("{typeName}", typeName)
.Replace("{typeNameA}", typeNameA)
.Replace("{typeNameB}", typeNameB)
.Replace("{typeNameZ}", typeNameZ);
}
private readonly struct StructInfo(string ns, string name, string a, string b, string z)
{
public string Namespace { get; } = ns;
public string TypeName { get; } = name;
public string TypeNameA { get; } = a;
public string TypeNameB { get; } = b;
public string TypeNameZ { get; } = z;
}
}

View File

@@ -1,226 +1,195 @@
//using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
//using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp;
//using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.CSharp.Syntax;
//using System.Collections.Generic; using Microsoft.CodeAnalysis.Text;
//using System.Collections.Immutable; using System.Collections.Immutable;
//using System.Linq; using System.Linq;
//using System.Text; using System.Text;
//namespace QWERTYkez.Mensura.Generator; namespace G;
//[Generator(LanguageNames.CSharp)] [Generator(LanguageNames.CSharp)]
//internal class CollectionsOperatorsGenerator : IIncrementalGenerator public class CollectionsOperatorsGenerator : IIncrementalGenerator
//{ {
// private const string AttributeShortName = "CollectionsOperatorsGenerator"; private const string AttributeShortName = "CollectionsOperatorsGenerator";
// private const string AttributeFullName = AttributeShortName + "Attribute"; private const string AttributeFullName = AttributeShortName + "Attribute";
// private const string AttributeSource = @"namespace QWERTYkez.Mensura; private const string AttributeSource = @"namespace QWERTYkez.Mensura;
//[System.AttributeUsage(System.AttributeTargets.Struct | System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] [System.AttributeUsage(System.AttributeTargets.Struct | System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
//internal sealed class CollectionsOperatorsGeneratorAttribute : System.Attribute { }"; internal sealed class CollectionsOperatorsGeneratorAttribute : System.Attribute { }";
// public void Initialize(IncrementalGeneratorInitializationContext context) // Какие типы коллекций поддерживаем
// { private static readonly (string Type, string Selector)[] CollectionTypes =
// context.RegisterPostInitializationOutput(context => [
// context.AddSource( ("T[]", "array => array.Select(u => left * u).ToArray()"), // но нужно адаптировать под конкретный тип
// $"{AttributeFullName}.g", // Проще генерировать отдельные методы для каждого типа
// SourceText.From(AttributeSource, Encoding.UTF8))); ];
// var operatorsPipeline = public void Initialize(IncrementalGeneratorInitializationContext context)
// context.SyntaxProvider.CreateSyntaxProvider<KeyValuePair<ClassData, ImmutableArray<Operation>>>( {
// (node, _) => context.RegisterPostInitializationOutput(ctx =>
// { ctx.AddSource($"{AttributeFullName}.g", SourceText.From(AttributeSource, Encoding.UTF8)));
// if (node is ClassDeclarationSyntax cds)
// {
// SyntaxNode sn = cds;
// while (sn.Parent is not null &&
// sn.Parent is not FileScopedNamespaceDeclarationSyntax)
// {
// sn = sn.Parent;
// }
// if (sn.Parent is FileScopedNamespaceDeclarationSyntax
// && cds.TypeParameterList is null
// &&
// ((cds.Members.OfType<OperatorDeclarationSyntax>()
// .Where(m => m.AttributeLists.SelectMany(al => al.Attributes)
// .Any(a => a.Name.GetText().ToString().Contains(AttributeShortName)))
// .Any())
// ||
// (cds.Modifiers.Any(m => m.Text == "partial")
// && cds.AttributeLists
// .SelectMany(al => al.Attributes)
// .Any(a => a.Name
// .GetText()
// .ToString()
// .Contains(AttributeShortName)))))
// {
// return true;
// }
// }
// return false;
// },
// (syntax, _) =>
// {
// string nameSpace;
// var cds = (ClassDeclarationSyntax)syntax.Node;
// {
// SyntaxNode sn = cds;
// while (sn.Parent is not FileScopedNamespaceDeclarationSyntax)
// {
// sn = sn.Parent!;
// }
// var nds = (FileScopedNamespaceDeclarationSyntax)sn.Parent;
// nameSpace = nds.Name.ToString();
// }
// var Res = new StringBuilder();
// {
// Res.Append(cds.Modifiers);
// Res.Append(" class ");
// Res.Append(cds.Identifier.Text);
// Res.Append(" ");
// Res.Append(cds.BaseList);
// Res.Append(" ");
// Res.Append(cds.ConstraintClauses);
// }
// var operators = cds.Members.OfType<OperatorDeclarationSyntax>() var operatorsPipeline = context.SyntaxProvider
// .Where(m => m.AttributeLists .CreateSyntaxProvider(
// .SelectMany(al => al.Attributes) predicate: static (node, _) => IsTargetType(node),
// .Any(a => a.Name.GetText().ToString().Contains(AttributeShortName))) transform: static (ctx, _) => GetTypeInfo(ctx))
// .Where(mb => mb.ParameterList.Parameters.Count == 2) .Where(info => info.HasValue) // использование nullable value type
// .Select(mb => new Operation() .Select((info, _) => info!.Value)
// { .Collect();
// ReturnType = mb.ReturnType.ToString(),
// OperatorToken = mb.OperatorToken.Text,
// TypeA = mb.ParameterList.Parameters[0].Type!.ToString(),
// TypeB = mb.ParameterList.Parameters[1].Type!.ToString(),
// });
// return new(new(nameSpace, cds.Identifier.Text, Res.ToString()), [.. operators]);
// })
// .Collect();
// context.RegisterSourceOutput(operatorsPipeline, GenerateOperators); context.RegisterSourceOutput(operatorsPipeline, GenerateOperators);
// } }
// readonly static string[] CollectionTypes = ["MetricArray", "MetricList", "MetricObservableCollection"]; private static bool IsTargetType(SyntaxNode node)
// static void GenerateOperators(SourceProductionContext context, ImmutableArray<KeyValuePair<ClassData, ImmutableArray<Operation>>> pairs) {
// { if (node is not TypeDeclarationSyntax typeDecl)
// foreach (var ng in pairs.GroupBy(c => c.Key.NameSpace)) return false;
// {
// StringBuilder document = new("namespace ");
// document.Append(ng.Key);
// document.Append(";");
// var classes = ng.ToList().Select(c => (ClassData?)c.Key).ToList(); // Должен быть partial и не generic
// var operations = ng.ToList().SelectMany(c => c.Value).ToList(); if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword))
// var multiplications = operations.Where(op => op.OperatorToken == "*").ToList(); return false;
// var divisions = operations.Where(op => op.OperatorToken == "/").ToList(); if (typeDecl.TypeParameterList != null)
return false;
// foreach (var ops in multiplications.GroupBy(op => op.TypeA)) // Проверяем наличие атрибута на самом типе
// { foreach (var attrList in typeDecl.AttributeLists)
// var Class = classes.FirstOrDefault(cl => cl!.Value.ClassName == ops.Key); foreach (var attr in attrList.Attributes)
// if (Class is not null) {
// { string name = attr.Name.ToString();
// document.AppendLine(); if (name == AttributeShortName || name == AttributeFullName)
// document.AppendLine(); return true;
// document.AppendLine(Class.Value.ClassHeader); }
// document.AppendLine("{");
// foreach (var op in ops)
// foreach (var ct in CollectionTypes)
// {
// document.AppendLine(@$"
// public static {ct}<{op.ReturnType}> operator *({op.TypeA} left, {ct}<{op.TypeB}> right) => right.MetricSelect(UU => left * UU);
// public static {ct}<{op.ReturnType}> operator *({ct}<{op.TypeB}> left, {op.TypeA} right) => left.MetricSelect(UU => UU * right);
//");
// }
// document.Append("}");
// }
// else
// {
// context.ReportDiagnostic(Diagnostic.Create(new(
// "MSG0001",
// "Need a class with an attribute",
// $"It is necessary to have a empty partial class \"{ops.Key}\" with the attribute \"{AttributeShortName}\"",
// "category",
// DiagnosticSeverity.Error,
// true), null, ops.Key));
// }
// }
// foreach (var ops in divisions.GroupBy(op => op.TypeA)) // Или на операторах внутри
// { foreach (var member in typeDecl.Members)
// var Class = classes.FirstOrDefault(cl => cl!.Value.ClassName == ops.Key); {
// if (Class is not null) if (member is OperatorDeclarationSyntax opDecl &&
// { opDecl.AttributeLists.SelectMany(al => al.Attributes)
// document.AppendLine(); .Any(a => a.Name.ToString().Contains(AttributeShortName)))
// document.AppendLine(); return true;
// document.AppendLine(Class.Value.ClassHeader); }
// document.AppendLine("{"); return false;
// foreach (var op in ops) }
// foreach (var ct in CollectionTypes)
// {
// document.AppendLine(@$"
// public static {ct}<{op.ReturnType}> operator /({op.TypeA} left, {ct}<{op.TypeB}> right) => right.MetricSelect(UU => left / UU);
//");
// }
// document.Append("}");
// }
// else
// {
// context.ReportDiagnostic(Diagnostic.Create(new(
// "MSG0001",
// "Need a class with an attribute",
// $"It is necessary to have a empty partial class \"{ops.Key}\" with the attribute \"{AttributeShortName}\"",
// "category",
// DiagnosticSeverity.Error,
// true), null, ops.Key));
// }
// }
// foreach (var ops in divisions.GroupBy(op => op.TypeB))
// {
// var Class = classes.FirstOrDefault(cl => cl!.Value.ClassName == ops.Key);
// if (Class is not null)
// {
// document.AppendLine();
// document.AppendLine();
// document.AppendLine(Class.Value.ClassHeader);
// document.AppendLine("{");
// foreach (var op in ops)
// foreach (var ct in CollectionTypes)
// {
// document.AppendLine(@$"
// public static {ct}<{op.ReturnType}> operator /({ct}<{op.TypeA}> left, {op.TypeB} right) => left.MetricSelect(UU => UU / right);
//");
// }
// document.Append("}");
// }
// else
// {
// context.ReportDiagnostic(Diagnostic.Create(new(
// "MSG0001",
// "Need a class with an attribute",
// $"It is necessary to have a empty partial class \"{ops.Key}\" with the attribute \"{AttributeShortName}\"",
// "category",
// DiagnosticSeverity.Error,
// true), null, ops.Key));
// }
// }
// context.AddSource($"operations.{ng.Key}.g", document.ToString()); private static TypeInfoData? GetTypeInfo(GeneratorSyntaxContext ctx)
// } {
// } var typeDecl = (TypeDeclarationSyntax)ctx.Node;
//} var semanticModel = ctx.SemanticModel;
//public struct ClassData(string nameSpace, string className, string classHeader) var symbol = semanticModel.GetDeclaredSymbol(typeDecl);
//{ if (symbol == null) return null;
// public string NameSpace = nameSpace;
// public string ClassName = className; string namespaceName = symbol.ContainingNamespace?.ToString() ?? "";
// public string ClassHeader = classHeader;
//} // Формируем заголовок (для отладочных целей)
//public struct Operation(string operatorToken, string typeA, string typeB, string returnType) var headerBuilder = new StringBuilder();
//{ foreach (var modifier in typeDecl.Modifiers)
// public string ReturnType = returnType; headerBuilder.Append(modifier.Text).Append(' ');
// public string OperatorToken = operatorToken; if (typeDecl is RecordDeclarationSyntax)
// public string TypeA = typeA; headerBuilder.Append("record ");
// public string TypeB = typeB; headerBuilder.Append(typeDecl.Identifier.Text);
//} string header = headerBuilder.ToString();
// Собираем операторы
var operators = ImmutableArray.CreateBuilder<Operation>();
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<TypeInfoData> types)
{
foreach (var group in types.GroupBy(t => t.Namespace))
{
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());
}
}
private readonly struct TypeInfoData(string ns, string name, string header, ImmutableArray<Operation> ops)
{
public string Namespace { get; } = ns;
public string TypeName { get; } = name;
public string Header { get; } = header;
public ImmutableArray<Operation> Operators { get; } = ops;
}
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;
}
}

View File

@@ -4,14 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup> <NoWarn>1701;1702;IDE0079;MVVMTK0034;IDE0130</NoWarn>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;IDE0079;MVVMTK0034</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;IDE0079;MVVMTK0034</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -4,12 +4,12 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
using System.Text; using System.Text;
namespace QWERTYkez.Mensura.Generator; namespace G;
[Generator] [Generator]
public class UnitOperatorsGenerator : IIncrementalGenerator public class UnitGenerator : IIncrementalGenerator
{ {
private const string AttributeName = "UnitOperatorsGenerator"; private const string AttributeName = "UnitGenerator";
public void Initialize(IncrementalGeneratorInitializationContext context) public void Initialize(IncrementalGeneratorInitializationContext context)
{ {
@@ -20,9 +20,9 @@ public class UnitOperatorsGenerator : IIncrementalGenerator
namespace QWERTYkez.Mensura namespace QWERTYkez.Mensura
{ {
[System.AttributeUsage(System.AttributeTargets.Struct, AllowMultiple = false)] [System.AttributeUsage(System.AttributeTargets.Struct, AllowMultiple = false)]
public sealed class UnitOperatorsGeneratorAttribute : System.Attribute { } public sealed class UnitGeneratorAttribute : System.Attribute { }
}"; }";
ctx.AddSource("UnitOperatorsGeneratorAttribute.g.cs", SourceText.From(attributeSource, Encoding.UTF8)); ctx.AddSource(".UnitGeneratorAttribute.g.cs", SourceText.From(attributeSource, Encoding.UTF8));
}); });
// Ищем все readonly partial record struct с атрибутом // Ищем все readonly partial record struct с атрибутом
@@ -39,7 +39,7 @@ namespace QWERTYkez.Mensura
foreach (var structInfo in structs) foreach (var structInfo in structs)
{ {
string generatedCode = GeneratePartial(structInfo); string generatedCode = GeneratePartial(structInfo);
spc.AddSource($"{structInfo.TypeName}.Generated.g.cs", SourceText.From(generatedCode, Encoding.UTF8)); spc.AddSource($"{structInfo.TypeName}.g.cs", SourceText.From(generatedCode, Encoding.UTF8));
} }
}); });
} }
@@ -56,7 +56,7 @@ namespace QWERTYkez.Mensura
!record.ClassOrStructKeyword.IsKind(SyntaxKind.StructKeyword)) !record.ClassOrStructKeyword.IsKind(SyntaxKind.StructKeyword))
return false; return false;
// Проверяем наличие атрибута [UnitOperatorsGenerator] // Проверяем наличие атрибута [UnitGenerator]
foreach (var attrList in record.AttributeLists) foreach (var attrList in record.AttributeLists)
foreach (var attr in attrList.Attributes) foreach (var attr in attrList.Attributes)
{ {

View File

@@ -1,231 +1,216 @@
//namespace QWERTYkez.Mensura.Units; namespace QWERTYkez.Mensura.Units;
//internal static class OperationsExtension internal static class OperationsExtension
{
internal static TResult MultiplyProtected<T1, T2, TResult>(this T1 t1, T2 t2)
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
=> (t1.ToDouble() * t2.ToDouble()).ToUnit<TResult>();
internal static TResult MultiplyProtected<T1, T2, TResult>(this T1 t1, T2 t2, double multiplicator)
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
=> (t1.ToDouble() * t2.ToDouble() * multiplicator).ToUnit<TResult>();
internal static TResult DivideProtected<T1, T2, TResult>(this T1 t1, T2 t2)
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
=> (t1.ToDouble() / t2.ToDouble()).ToUnit<TResult>();
internal static TResult DivideProtected<T1, T2, TResult>(this T1 t1, T2 t2, double multiplicator)
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
=> (t1.ToDouble() * multiplicator / t2.ToDouble()).ToUnit<TResult>();
}
internal static class Coefficients
{
internal static double MultiplyCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
=> r.ToDouble() / (a.ToDouble() * b.ToDouble());
internal static double DivideCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
=> r.ToDouble() * b.ToDouble() / a.ToDouble();
}
[CollectionsOperatorsGenerator] public readonly partial record struct Length
{
[CollectionsOperatorsGenerator] public static Area operator *(Length left, Length right)
=> left.MultiplyProtected<Length, Length, Area>(right, Coeff1);
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MilliMeter, MilliMeter, Area.MilliMeterSquared);
[CollectionsOperatorsGenerator] public static Volume operator *(Area left, Length right) => right * left;
[CollectionsOperatorsGenerator] public static Volume operator *(Length left, Area right)
=> left.MultiplyProtected<Length, Area, Volume>(right, Coeff2);
static readonly double Coeff2 = Coefficients.MultiplyCoefficient(MilliMeter, Area.MilliMeterSquared, Volume.MilliMeterCubic);
[CollectionsOperatorsGenerator] public static Pressure operator *(Length left, ForceVolumetric right) => right * left;
[CollectionsOperatorsGenerator] public static Pressure operator *(ForceVolumetric left, Length right) => left.MultiplyProtected<ForceVolumetric, Length, Pressure>(right, Coeff3);
static readonly double Coeff3 = 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<Length, Force, Torque>(right, Coeff6);
static readonly double Coeff6 = Coefficients.MultiplyCoefficient(Length.Meter, Force.Newton, Torque.Newton_Meter);
}
[CollectionsOperatorsGenerator] public readonly partial record struct Mass // Grams
{
}
[CollectionsOperatorsGenerator] public readonly partial record struct Pressure // Pascals
{
[CollectionsOperatorsGenerator] public static Length operator /(Pressure left, ForceVolumetric right) => left.DivideProtected<Pressure, ForceVolumetric, Length>(right, Coeff1);
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<Area, Pressure, Force>(right, Coeff2);
static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Area.MeterSquared, Pressure.Pascal, Force.Newton);
[CollectionsOperatorsGenerator] public static Length operator /(ForceLinear left, Pressure right) => left.DivideProtected<ForceLinear, Pressure, Length>(right, Coeff3);
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<Length, Pressure, ForceLinear>(right, Coeff4);
static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length.MilliMeter, Pressure.NewtonPerMilliMeterSquared, ForceLinear._NewtonPerMilliMeter);
}
[CollectionsOperatorsGenerator] 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<Area, ForceLinear, Torque>(right, Coeff1);
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Area.MeterSquared, ForceLinear.NewtonPerMeter, Torque.Newton_Meter);
[CollectionsOperatorsGenerator] public static Length operator /(Area left, Length right) => left.DivideProtected<Area, Length, Length>(right, Coeff2);
static readonly double Coeff2 = Coefficients.DivideCoefficient(Area.MilliMeterSquared, Length.MilliMeter, Length.MilliMeter);
}
[CollectionsOperatorsGenerator] 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<Volume, Pressure, Torque>(right, Coeff2);
static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Volume.MeterCubic, Pressure.Pascal, Torque.Newton_Meter);
[CollectionsOperatorsGenerator] public static Area operator /(Volume left, Length right) => left.DivideProtected<Volume, Length, Area>(right);
[CollectionsOperatorsGenerator] public static Length operator /(Volume left, Area right) => left.DivideProtected<Volume, Area, Length>(right, Coeff3);
static readonly double Coeff3 = Coefficients.DivideCoefficient(Volume.MilliMeterCubic, Length.MilliMeter, Area.MilliMeterSquared);
}
[CollectionsOperatorsGenerator] public readonly partial record struct Force // Newtons
{
[CollectionsOperatorsGenerator] public static Area operator /(Force left, Pressure right) => left.DivideProtected<Force, Pressure, Area>(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<Force, Area, Pressure>(right, Coeff2);
static readonly double Coeff2 = Coefficients.DivideCoefficient(Force.Newton, Area.MeterSquared, Pressure.Pascal);
}
[CollectionsOperatorsGenerator] public readonly partial record struct Torque // NewtonMeters
{
[CollectionsOperatorsGenerator] public static Length operator /(Torque left, Force right) => left.DivideProtected<Torque, Force, Length>(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<Torque, Length, Force>(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<Torque, Area, ForceLinear>(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<Torque, Volume, Pressure>(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<Torque, Pressure, Volume>(right, Coeff5);
static readonly double Coeff5 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Pressure.Pascal, Volume.MeterCubic);
}
[CollectionsOperatorsGenerator] public readonly partial record struct Frequency // Hertz
{
}
[CollectionsOperatorsGenerator] 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<Time, Boost, Speed>(right, Coeff1);
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Boost.MeterPerSecondSquared, Speed.MeterPerSecond);
[CollectionsOperatorsGenerator] public static Speed operator /(Length left, Time right) => left.DivideProtected<Length, Time, Speed>(right, Coeff2);
static readonly double Coeff2 = Coefficients.DivideCoefficient(Length.Meter, Time.Second, Speed.MeterPerSecond);
}
[CollectionsOperatorsGenerator] 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<Time, Speed, Length>(right, Coeff1);
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Speed.MeterPerSecond, Length.Meter);
[CollectionsOperatorsGenerator] public static Boost operator /(Speed left, Time right) => left.DivideProtected<Speed, Time, Boost>(right, Coeff2);
static readonly double Coeff2 = Coefficients.DivideCoefficient(Speed.MeterPerSecond, Time.Second, Boost.MeterPerSecondSquared);
}
[CollectionsOperatorsGenerator] 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<Boost, Mass, Force>(right, Coeff1);
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<Boost, MassLinear, ForceLinear>(right, Coeff2);
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<Boost, Density, ForceVolumetric>(right, Coeff3);
static readonly double Coeff3 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic, ForceVolumetric._NewtonPerMilliMeterCubic);
[CollectionsOperatorsGenerator] public static MassLinear operator /(ForceLinear left, Boost right) => left.DivideProtected<ForceLinear, Boost, MassLinear>(right, Coeff4);
static readonly double Coeff4 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, Boost.MeterPerSecondSquared, MassLinear.KiloGramPerMilliMeter);
[CollectionsOperatorsGenerator] public static Density operator /(ForceVolumetric left, Boost right) => left.DivideProtected<ForceVolumetric, Boost, Density>(right, Coeff5);
static readonly double Coeff5 = Coefficients.DivideCoefficient(ForceVolumetric._NewtonPerMilliMeterCubic, Boost.MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic);
[CollectionsOperatorsGenerator] public static MassPerSquare operator /(Pressure left, Boost right) => left.DivideProtected<Pressure, Boost, MassPerSquare>(right, Coeff6);
static readonly double Coeff6 = Coefficients.DivideCoefficient(Pressure.Pascal, Boost.MeterPerSecondSquared, MassPerSquare.KiloGramPerMeterSquared);
}
[CollectionsOperatorsGenerator] 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<MassPerSquare, Boost, Pressure>(right, Coeff1);
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MassPerSquare.KiloGramPerMeterSquared, Boost.MeterPerSecondSquared, Pressure.Pascal);
}
//[CollectionsOperatorsGenerator] public readonly partial record struct LinearForce : Pogon<LinearForce, Force>
//{ //{
// internal static TResult MultiplyProtected<T1, T2, TResult>(this T1 t1, T2 t2)
// where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
// where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
// where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
// => new() { Value = t1.Value * t2.Value };
// internal static TResult MultiplyProtected<T1, T2, TResult>(this T1 t1, T2 t2, double multiplicator)
// where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
// where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
// where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
// => new() { Value = t1.Value * t2.Value * multiplicator };
// internal static TResult DivideProtected<T1, T2, TResult>(this T1 t1, T2 t2)
// where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
// where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
// where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
// => new() { Value = t1.Value / t2.Value };
// internal static TResult DivideProtected<T1, T2, TResult>(this T1 t1, T2 t2, double multiplicator)
// where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
// where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
// where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
// => new() { Value = t1.Value * multiplicator / t2.Value };
//}
//internal static class Coefficients
//{
// internal static double MultiplyCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
// where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
// where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
// where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
// => r.Value / (a.Value * b.Value);
// internal static double DivideCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
// where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
// where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
// where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
// => r.Value * b.Value / a.Value;
//}
//[CollectionsOperatorsGenerator] public readonly partial record struct Length
//{
// [CollectionsOperatorsGenerator] public static Area operator *(Length left, Length right)
// => left.MultiplyProtected<Length, Length, Area>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MilliMeter, MilliMeter, Area.MilliMeterSquared);
// [CollectionsOperatorsGenerator] public static Volume operator *(Area left, Length right) => right * left;
// [CollectionsOperatorsGenerator] public static Volume operator *(Length left, Area right)
// => left.MultiplyProtected<Length, Area, Volume>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.MultiplyCoefficient(MilliMeter, Area.MilliMeterSquared, Volume.MilliMeterCubic);
// [CollectionsOperatorsGenerator] public static Pressure operator *(Length left, UdelForce right) => right * left;
// [CollectionsOperatorsGenerator] public static Pressure operator *(UdelForce left, Length right) => left.MultiplyProtected<UdelForce, Length, Pressure>(right, Coeff3);
// static readonly double Coeff3 = Coefficients.MultiplyCoefficient(a => a.PerMeterCubic.Newtons = 1, Length.Meter, Pressure.NewtonPerMeterSquared);
// [CollectionsOperatorsGenerator] public static Force operator *(PogonForce left, Length right) => right * left;
// [CollectionsOperatorsGenerator] public static Force operator *(Length left, PogonForce right) => left.MultiplyProtected<Length, PogonForce, Force>(right, Coeff4);
// static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length.Meter, b => b.PerMeter.Newtons = 1, Force.Newton);
// [CollectionsOperatorsGenerator] public static Torque operator *(Force left, Length right) => right * left;
// [CollectionsOperatorsGenerator] public static Torque operator *(Length left, Force right) => left.MultiplyProtected<Length, Force, Torque>(right, Coeff6);
// static readonly double Coeff6 = Coefficients.MultiplyCoefficient(Length.Meter, Force.Newton, Torque.Newton_Meter);
//}
//[CollectionsOperatorsGenerator] public readonly partial record struct Mass // Grams
//{
//} //}
//[CollectionsOperatorsGenerator] public readonly partial record struct Pressure // Pascals //[CollectionsOperatorsGenerator] public readonly partial record struct MassLinear : Pogon<MassLinear, Mass>
//{ //{
// [CollectionsOperatorsGenerator] public static Length operator /(Pressure left, UdelForce right) => left.DivideProtected<Pressure, UdelForce, Length>(right, Coeff1); // [CollectionsOperatorsGenerator] public static Boost operator /(LinearForce left, MassLinear right) => left.DivideProtected<LinearForce, MassLinear, Boost>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.DivideCoefficient(Pressure.Pascal, b => b.PerMeterCubic.Newtons = 1, Length.Meter);
// [CollectionsOperatorsGenerator] public static Force operator *(Pressure left, Area right) => right * left; // static readonly double Coeff1 = Coefficients.DivideCoefficient(a => a.PerMilliMeter.Newtons = 1, b => b.PerMilliMeter.KiloGrams = 1, Boost.MeterPerSecondSquared);
// [CollectionsOperatorsGenerator] public static Force operator *(Area left, Pressure right) => left.MultiplyProtected<Area, Pressure, Force>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Area.MeterSquared, Pressure.Pascal, Force.Newton);
// [CollectionsOperatorsGenerator] public static Length operator /(PogonForce left, Pressure right) => left.DivideProtected<PogonForce, Pressure, Length>(right, Coeff3);
// static readonly double Coeff3 = Coefficients.DivideCoefficient(a => a._PerMilliMeter.Newtons = 1, Pressure.NewtonPerMilliMeterSquared, Length.MilliMeter);
// [CollectionsOperatorsGenerator] public static PogonForce operator *(Pressure left, Length right) => right * left;
// [CollectionsOperatorsGenerator] public static PogonForce operator *(Length left, Pressure right) => left.MultiplyProtected<Length, Pressure, PogonForce>(right, Coeff4);
// static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length.MilliMeter, Pressure.NewtonPerMilliMeterSquared, r => r._PerMilliMeter.Newtons = 1);
//} //}
//[CollectionsOperatorsGenerator] public readonly partial record struct Area // MilliMetersSquared //[CollectionsOperatorsGenerator] public readonly partial record struct ForceVolumetric : Udel<ForceVolumetric, Force>
//{
// [CollectionsOperatorsGenerator] public static Torque operator *(PogonForce left, Area right) => right * left;
// [CollectionsOperatorsGenerator] public static Torque operator *(Area left, PogonForce right) => left.MultiplyProtected<Area, PogonForce, Torque>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Area.MeterSquared, b => b.PerMeter.Newtons = 1, Torque.Newton_Meter);
// [CollectionsOperatorsGenerator] public static Length operator /(Area left, Length right) => left.DivideProtected<Area, Length, Length>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.DivideCoefficient(Area.MilliMeterSquared, Length.MilliMeter, Length.MilliMeter);
//}
//[CollectionsOperatorsGenerator] public readonly partial record struct Volume // MillimetersCubic
//{
// [CollectionsOperatorsGenerator] public static Mass operator *(Density left, Volume right) => right * left;
// [CollectionsOperatorsGenerator] public static Mass operator *(Volume left, Density right) => left.MultiplyProtected<Volume, Density, Mass>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Volume.MilliMeterCubic, b => b.PerMilliMeterCubic.Grams = 1, Time.Gram);
// [CollectionsOperatorsGenerator] public static Torque operator *(Pressure left, Volume right) => right * left;
// [CollectionsOperatorsGenerator] public static Torque operator *(Volume left, Pressure right) => left.MultiplyProtected<Volume, Pressure, Torque>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Volume.MeterCubic, Pressure.Pascal, Torque.Newton_Meter);
// [CollectionsOperatorsGenerator] public static Area operator /(Volume left, Length right) => left.DivideProtected<Volume, Length, Area>(right);
// [CollectionsOperatorsGenerator] public static Length operator /(Volume left, Area right) => left.DivideProtected<Volume, Area, Length>(right, Coeff3);
// static readonly double Coeff3 = Coefficients.DivideCoefficient(Volume.MilliMeterCubic, Length.MilliMeter, Area.MilliMeterSquared);
//}
//[CollectionsOperatorsGenerator] public readonly partial record struct Force // Newtons
//{
// [CollectionsOperatorsGenerator] public static Area operator /(Force left, Pressure right) => left.DivideProtected<Force, Pressure, Area>(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<Force, Area, Pressure>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.DivideCoefficient(Force.Newton, Area.MeterSquared, Pressure.Pascal);
//}
//[CollectionsOperatorsGenerator] public readonly partial record struct Torque // NewtonMeters
//{
// [CollectionsOperatorsGenerator] public static Length operator /(Torque left, Force right) => left.DivideProtected<Torque, Force, Length>(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<Torque, Length, Force>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Length.Meter, Force.Newton);
// [CollectionsOperatorsGenerator] public static PogonForce operator /(Torque left, Area right) => left.DivideProtected<Torque, Area, PogonForce>(right, Coeff3);
// static readonly double Coeff3 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Area.MilliMeterSquared, r => r.PerMilliMeter.KiloNewtons = 1);
// [CollectionsOperatorsGenerator] public static Pressure operator /(Torque left, Volume right) => left.DivideProtected<Torque, Volume, Pressure>(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<Torque, Pressure, Volume>(right, Coeff5);
// static readonly double Coeff5 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Pressure.Pascal, Volume.MeterCubic);
//}
//[CollectionsOperatorsGenerator] public readonly partial record struct Frequency // Hertz
//{ //{
//} //}
//[CollectionsOperatorsGenerator] 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<Time, Boost, Speed>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Boost.MeterPerSecondSquared, Speed.MeterPerSecond);
// [CollectionsOperatorsGenerator] public static Speed operator /(Length left, Time right) => left.DivideProtected<Length, Time, Speed>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.DivideCoefficient(Length.Meter, Time.Second, Speed.MeterPerSecond);
//}
//[CollectionsOperatorsGenerator] 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<Time, Speed, Length>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Speed.MeterPerSecond, Length.Meter);
// [CollectionsOperatorsGenerator] public static Boost operator /(Speed left, Time right) => left.DivideProtected<Speed, Time, Boost>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.DivideCoefficient(Speed.MeterPerSecond, Time.Second, Boost.MeterPerSecondSquared);
//}
//[CollectionsOperatorsGenerator] 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<Boost, Mass, Force>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, Time.KiloGram, Force.Newton);
// [CollectionsOperatorsGenerator] public static PogonForce operator *(PogonMass left, Boost right) => right * left;
// [CollectionsOperatorsGenerator] public static PogonForce operator *(Boost left, PogonMass right) => left.MultiplyProtected<Boost, PogonMass, PogonForce>(right, Coeff2);
// static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, b => b.PerMilliMeter.KiloGrams = 1, r => r.PerMilliMeter.Newtons = 1);
// [CollectionsOperatorsGenerator] public static UdelForce operator *(Density left, Boost right) => right * left;
// [CollectionsOperatorsGenerator] public static UdelForce operator *(Boost left, Density right) => left.MultiplyProtected<Boost, Density, UdelForce>(right, Coeff3);
// static readonly double Coeff3 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, b => b.PerMilliMeterCubic.KiloGrams = 1, r => r.PerMilliMeterCubic.Newtons = 1);
// [CollectionsOperatorsGenerator] public static PogonMass operator /(PogonForce left, Boost right) => left.DivideProtected<PogonForce, Boost, PogonMass>(right, Coeff4);
// static readonly double Coeff4 = Coefficients.DivideCoefficient(a => a.PerMilliMeter.Newtons = 1, Boost.MeterPerSecondSquared, r => r.PerMilliMeter.KiloGrams = 1);
// [CollectionsOperatorsGenerator] public static Density operator /(UdelForce left, Boost right) => left.DivideProtected<UdelForce, Boost, Density>(right, Coeff5);
// static readonly double Coeff5 = Coefficients.DivideCoefficient(a => a.PerMilliMeterCubic.Newtons = 1, Boost.MeterPerSecondSquared, r => r.PerMilliMeterCubic.KiloGrams = 1);
// [CollectionsOperatorsGenerator] public static MassPerSquare operator /(Pressure left, Boost right) => left.DivideProtected<Pressure, Boost, MassPerSquare>(right, Coeff6);
// static readonly double Coeff6 = Coefficients.DivideCoefficient(Pressure.Pascal, Boost.MeterPerSecondSquared, MassPerSquare.KiloGramPerMeterSquared);
//}
//[CollectionsOperatorsGenerator] 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<MassPerSquare, Boost, Pressure>(right, Coeff1);
// static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MassPerSquare.KiloGramPerMeterSquared, Boost.MeterPerSecondSquared, Pressure.Pascal);
//}
////[CollectionsOperatorsGenerator] public readonly partial record struct PogonForce : Pogon<PogonForce, Force>
////{
////}
////[CollectionsOperatorsGenerator] public readonly partial record struct PogonMass : Pogon<PogonMass, Mass>
////{
//// [CollectionsOperatorsGenerator] public static Boost operator /(PogonForce left, PogonMass right) => left.DivideProtected<PogonForce, PogonMass, Boost>(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 UdelForce : Udel<UdelForce, Force>
////{
////}
////[CollectionsOperatorsGenerator] public readonly partial record struct Density : Udel<Density, Mass>
////{
////}

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is Seconds /// Base value is Seconds
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("Radians = {Radians.ToString(\"0.###\")}, Degrees = {Degrees.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("Radians = {Radians.ToString(\"0.###\")}, Degrees = {Degrees.ToString(\"0.###\")}")]
public readonly partial record struct Angle public readonly partial record struct Angle
{ {
[NotMapped, JsonIgnore] public double _Seconds { get => Seconds; init => Seconds = value; } public static Angle Second { get; } = new() { _Seconds = 1 };
[NotMapped, JsonIgnore] public double _Seconds { get => _Value; init => _Value = value; }
public static Angle Second { get; } = new() { Seconds = 1 };
[NotMapped, JsonIgnore] public double Seconds
{
get => _Value;
init
{
_Value = value;
}
}
public static Angle Minute { get; } = new() { Minutes = 1 }; public static Angle Minute { get; } = new() { Minutes = 1 };
[NotMapped, JsonIgnore] public double Minutes [NotMapped, JsonIgnore] public double Minutes

View File

@@ -3,20 +3,13 @@
/// <summary> /// <summary>
/// Base value is MilliMetersSquared /// Base value is MilliMetersSquared
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("mm2 = {_MilliMetersSquared.ToString(\"0.###\")}, m2 = {MetersSquared.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("mm2 = {_MilliMetersSquared.ToString(\"0.###\")}, m2 = {MetersSquared.ToString(\"0.###\")}")]
public readonly partial record struct Area public readonly partial record struct Area
{ {
[NotMapped, JsonIgnore] public double _MilliMetersSquared { get => MilliMetersSquared; init => MilliMetersSquared = value; } public static Area MilliMeterSquared { get; } = new() { _MilliMetersSquared = 1 };
[NotMapped, JsonIgnore] public double _MilliMetersSquared { get => _Value; init => _Value = value; }
public static Area MilliMeterSquared { get; } = new() { MilliMetersSquared = 1 };
[NotMapped, JsonIgnore] public double MilliMetersSquared
{
get => _Value;
init
{
_Value = value;
}
}
public static Area CentiMeterSquared { get; } = new() { CentiMetersSquared = 1 }; public static Area CentiMeterSquared { get; } = new() { CentiMetersSquared = 1 };
[NotMapped, JsonIgnore] public double CentiMetersSquared [NotMapped, JsonIgnore] public double CentiMetersSquared
{ {

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is MetersPerSecondSquared /// Base value is MetersPerSecondSquared
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("m/s2 = {_MetersPerSecondSquared.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("m/s2 = {_MetersPerSecondSquared.ToString(\"0.###\")}")]
public readonly partial record struct Boost public readonly partial record struct Boost
{ {
[NotMapped, JsonIgnore] public double _MetersPerSecondSquared { get => MetersPerSecondSquared; init => MetersPerSecondSquared = value; } public static Boost MeterPerSecondSquared { get; } = new() { _MetersPerSecondSquared = 1 };
[NotMapped, JsonIgnore] public double _MetersPerSecondSquared { get => _Value; init => _Value = value; }
public static Boost MeterPerSecondSquared { get; } = new() { MetersPerSecondSquared = 1 };
[NotMapped, JsonIgnore] public double MetersPerSecondSquared
{
get => _Value;
init
{
_Value = value;
}
}
public static Boost KiloMeterPerSecondSquared { get; } = new() { KiloMetersPerSecondSquared = 1 }; public static Boost KiloMeterPerSecondSquared { get; } = new() { KiloMetersPerSecondSquared = 1 };
[NotMapped, JsonIgnore] public double KiloMetersPerSecondSquared [NotMapped, JsonIgnore] public double KiloMetersPerSecondSquared
@@ -28,7 +20,7 @@ public readonly partial record struct Boost
} }
} }
public static Boost G { get; } = new() { MetersPerSecondSquared = Constants.g }; public static Boost G { get; } = new() { _MetersPerSecondSquared = Constants.g };
public Boost AddMetersPerSecondSquared(double value) => new(_Value + value); public Boost AddMetersPerSecondSquared(double value) => new(_Value + value);
public Boost AddKiloMetersPerSecondSquared(double value) => new(_Value + BoostConv.KiloMetersPerSecondSquared.To(value)); public Boost AddKiloMetersPerSecondSquared(double value) => new(_Value + BoostConv.KiloMetersPerSecondSquared.To(value));

View File

@@ -0,0 +1,78 @@
namespace QWERTYkez.Mensura.Units.Complex;
[ComplexUnitGenerator(nameof(Force), nameof(Length), nameof(ForceLinear))] public readonly partial record struct ForceLinear
{
public static ForceLinear _NewtonPerMilliMeter { get; } = new() { _PerMilliMeter = new() { _Newtons = 1 } };
public static ForceLinear KiloGramForcePerMilliMeter { get; } = new() { _PerMilliMeter = new() { KiloGramForces = 1 } };
public static ForceLinear KiloNewtonPerMilliMeter { get; } = new() { _PerMilliMeter = new() { KiloNewtons = 1 } };
public static ForceLinear TonForcePerMilliMeter { get; } = new() { _PerMilliMeter = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force _PerMilliMeter
{ get => (Force)_Value; init => _Value = (double)value; }
public static ForceLinear NewtonPerCentiMeter { get; } = new() { PerCentiMeter = new() { _Newtons = 1 } };
public static ForceLinear KiloGramForcePerCentiMeter { get; } = new() { PerCentiMeter = new() { KiloGramForces = 1 } };
public static ForceLinear KiloNewtonPerCentiMeter { get; } = new() { PerCentiMeter = new() { KiloNewtons = 1 } };
public static ForceLinear TonForcePerCentiMeter { get; } = new() { PerCentiMeter = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force PerCentiMeter
{
get => new(_Value * LengthConv.CentiMeters.Multiplicator);
init => _Value = value._Value / LengthConv.CentiMeters.Multiplicator;
}
public static ForceLinear NewtonPerDeciMeter { get; } = new() { PerDeciMeter = new() { _Newtons = 1 } };
public static ForceLinear KiloGramForcePerDeciMeter { get; } = new() { PerDeciMeter = new() { KiloGramForces = 1 } };
public static ForceLinear KiloNewtonPerDeciMeter { get; } = new() { PerDeciMeter = new() { KiloNewtons = 1 } };
public static ForceLinear TonForcePerDeciMeter { get; } = new() { PerDeciMeter = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force PerDeciMeter
{
get => new(_Value * LengthConv.DeciMeters.Multiplicator);
init => _Value = value._Value / LengthConv.DeciMeters.Multiplicator;
}
public static ForceLinear NewtonPerMeter { get; } = new() { PerMeter = new() { _Newtons = 1 } };
public static ForceLinear KiloGramForcePerMeter { get; } = new() { PerMeter = new() { KiloGramForces = 1 } };
public static ForceLinear KiloNewtonPerMeter { get; } = new() { PerMeter = new() { KiloNewtons = 1 } };
public static ForceLinear TonForcePerMeter { get; } = new() { PerMeter = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force PerMeter
{
get => new(_Value * LengthConv.Meters.Multiplicator);
init => _Value = value._Value / LengthConv.Meters.Multiplicator;
}
public static ForceLinear NewtonPerKiloMeter { get; } = new() { PerKiloMeter = new() { _Newtons = 1 } };
public static ForceLinear KiloGramForcePerKiloMeter { get; } = new() { PerKiloMeter = new() { KiloGramForces = 1 } };
public static ForceLinear KiloNewtonPerKiloMeter { get; } = new() { PerKiloMeter = new() { KiloNewtons = 1 } };
public static ForceLinear TonForcePerKiloMeter { get; } = new() { PerKiloMeter = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force PerKiloMeter
{
get => new(_Value * LengthConv.KiloMeters.Multiplicator);
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<Length, Length>
//{
// [CollectionsOperatorsGenerator] public static PogonXXXXXXXX operator /(XXXXXXXX left, Length right) => left.DivideProtected<XXXXXXXX, Length, PogonXXXXXXXX>(right, PogonXXXXXXXXCoeff);
// static readonly double PogonXXXXXXXXCoeff = Coefficients.DivideCoefficient<XXXXXXXX, Length, PogonXXXXXXXX>(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1);
//}

View File

@@ -0,0 +1,56 @@
namespace QWERTYkez.Mensura.Units.Complex;
[ComplexUnitGenerator(nameof(Force), nameof(Volume), nameof(ForceVolumetric))] public readonly partial record struct ForceVolumetric
{
public static ForceVolumetric _NewtonPerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { _Newtons = 1 } };
public static ForceVolumetric KiloGramForcePerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { KiloGramForces = 1 } };
public static ForceVolumetric KiloNewtonPerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { KiloNewtons = 1 } };
public static ForceVolumetric TonForcePerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force _PerMilliMeterCubic
{ get => (Force)_Value; init => _Value = (double)value; }
public static ForceVolumetric NewtonPerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { _Newtons = 1 } };
public static ForceVolumetric KiloGramForcePerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { KiloGramForces = 1 } };
public static ForceVolumetric KiloNewtonPerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { KiloNewtons = 1 } };
public static ForceVolumetric TonForcePerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force PerCentiMeterCubic
{
get => new(_Value * VolumeConv.CentiMetersCubic.Multiplicator);
init => _Value = value._Value / VolumeConv.CentiMetersCubic.Multiplicator;
}
public static ForceVolumetric NewtonPerMeterCubic { get; } = new() { PerMeterCubic = new() { _Newtons = 1 } };
public static ForceVolumetric KiloGramForcePerMeterCubic { get; } = new() { PerMeterCubic = new() { KiloGramForces = 1 } };
public static ForceVolumetric KiloNewtonPerMeterCubic { get; } = new() { PerMeterCubic = new() { KiloNewtons = 1 } };
public static ForceVolumetric TonForcePerMeterCubic { get; } = new() { PerMeterCubic = new() { TonForces = 1 } };
[NotMapped, JsonIgnore] public Force PerMeterCubic
{
get => new(_Value * VolumeConv.MetersCubic.Multiplicator);
init => _Value = value._Value / VolumeConv.MetersCubic.Multiplicator;
}
}
//namespace MetricSystem;
//[Owned, JsonConverter(typeof(MetricFormatter<ForceVolumetric>)), DebuggerDisplay("N/(m*mm2) = {PerMeter_PerMilliMeterSquared._Newtons.ToString(\"0.###\")}, kgf/(m*mm2) = {PerMeter_PerMilliMeterSquared.KiloGramForces.ToString(\"0.###\")}")]
//public partial class ForceVolumetric : Udel<ForceVolumetric, Force>
//{
// [CollectionsOperatorsGenerator] public static ForceVolumetric operator *(Area left, ForceVolumetric right) => right * left;
// [CollectionsOperatorsGenerator] public static ForceVolumetric operator *(ForceVolumetric left, Area right) => left.MultiplyProtected<ForceVolumetric, Area, ForceVolumetric>(right, ForceVolumetricCoeff);
// static readonly double ForceVolumetricCoeff = Coefficients.MultiplyCoefficient<ForceVolumetric, Area, ForceVolumetric>(a => a._PerMilliMeterCubic.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeter.Value = 1);
//}
//public partial class Volume : Metric<Volume, Volume>
//{
// [CollectionsOperatorsGenerator] public static ForceVolumetric operator /(Force left, Volume right) => left.DivideProtected<Force, Volume, ForceVolumetric>(right, ForceVolumetricCoeff);
// static readonly double ForceVolumetricCoeff = Coefficients.DivideCoefficient<Force, Volume, ForceVolumetric>(a => a.Value = 1, b => b._MilliMetersCubic = 1, r => r._PerMilliMeterCubic.Value = 1);
//}

View File

@@ -0,0 +1,82 @@
namespace QWERTYkez.Mensura.Units.Complex;
[ComplexUnitGenerator(nameof(Mass), nameof(Length), nameof(MassLinear))] public readonly partial record struct MassLinear
{
public static MassLinear _GramPerMilliMeter { get; } = new() { _PerMilliMeter = new() { _Grams = 1 } };
public static MassLinear KiloGramPerMilliMeter { get; } = new() { _PerMilliMeter = new() { KiloGrams = 1 } };
public static MassLinear CentnerPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Centners = 1 } };
public static MassLinear TonPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass _PerMilliMeter
{ get => (Mass)_Value; init => _Value = (double)value; }
public static MassLinear GramPerCentiMeter { get; } = new() { PerCentiMeter = new() { _Grams = 1 } };
public static MassLinear KiloGramPerCentiMeter { get; } = new() { PerCentiMeter = new() { KiloGrams = 1 } };
public static MassLinear CentnerPerCentiMeter { get; } = new() { PerCentiMeter = new() { Centners = 1 } };
public static MassLinear TonPerCentiMeter { get; } = new() { PerCentiMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerCentiMeter
{
get => new(_Value * LengthConv.CentiMeters.Multiplicator);
init => _Value = value._Value / LengthConv.CentiMeters.Multiplicator;
}
public static MassLinear GramPerDeciMeter { get; } = new() { PerDeciMeter = new() { _Grams = 1 } };
public static MassLinear KiloGramPerDeciMeter { get; } = new() { PerDeciMeter = new() { KiloGrams = 1 } };
public static MassLinear CentnerPerDeciMeter { get; } = new() { PerDeciMeter = new() { Centners = 1 } };
public static MassLinear TonPerDeciMeter { get; } = new() { PerDeciMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerDeciMeter
{
get => new(_Value * LengthConv.DeciMeters.Multiplicator);
init => _Value = value._Value / LengthConv.DeciMeters.Multiplicator;
}
public static MassLinear GramPerMeter { get; } = new() { PerMeter = new() { _Grams = 1 } };
public static MassLinear KiloGramPerMeter { get; } = new() { PerMeter = new() { KiloGrams = 1 } };
public static MassLinear CentnerPerMeter { get; } = new() { PerMeter = new() { Centners = 1 } };
public static MassLinear TonPerMeter { get; } = new() { PerMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerMeter
{
get => new(_Value * LengthConv.Meters.Multiplicator);
init => _Value = value._Value / LengthConv.Meters.Multiplicator;
}
public static MassLinear GramPerKiloMeter { get; } = new() { PerKiloMeter = new() { _Grams = 1 } };
public static MassLinear KiloGramPerKiloMeter { get; } = new() { PerKiloMeter = new() { KiloGrams = 1 } };
public static MassLinear CentnerPerKiloMeter { get; } = new() { PerKiloMeter = new() { Centners = 1 } };
public static MassLinear TonPerKiloMeter { get; } = new() { PerKiloMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerKiloMeter
{
get => new(_Value * LengthConv.KiloMeters.Multiplicator);
init => _Value = value._Value / LengthConv.KiloMeters.Multiplicator;
}
}
//[Owned, JsonConverter(typeof(MetricFormatter<MassLinear>)), DebuggerDisplay("gr/m = {PerMeter._Grams.ToString(\"0.###\")}, kg/m = {PerMeter.KiloGrams.ToString(\"0.###\")}")]
//public partial class MassLinear : Pogon<MassLinear, Mass>
//{
// [CollectionsOperatorsGenerator] public static Density operator /(MassLinear left, Area right) => left.DivideProtected<MassLinear, Area, Density>(right, UdelMassCoeff);
// static readonly double UdelMassCoeff = Coefficients.DivideCoefficient<MassLinear, Area, Density>(a => a._PerMilliMeter.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeterCubic.Value = 1);
//}
//public partial class Length : Metric<Length, Length>
//{
// [CollectionsOperatorsGenerator] public static MassLinear operator /(Mass left, Length right) => left.DivideProtected<Mass, Length, MassLinear>(right, MassLinearCoeff);
// static readonly double MassLinearCoeff = Coefficients.DivideCoefficient<Mass, Length, MassLinear>(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1);
//}

View File

@@ -0,0 +1,59 @@
namespace QWERTYkez.Mensura.Units.Complex;
[ComplexUnitGenerator(nameof(Mass), nameof(Volume), nameof(Density))] public readonly partial record struct Density
{
public static Density _GramPerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { _Grams = 1 } };
public static Density KiloGramPerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { KiloGrams = 1 } };
public static Density CentnerPerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { Centners = 1 } };
public static Density TonPerMilliMeterCubic { get; } = new() { _PerMilliMeterCubic = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass _PerMilliMeterCubic
{ get => (Mass)_Value; init => _Value = (double)value; }
public static Density GramPerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { _Grams = 1 } };
public static Density KiloGramPerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { KiloGrams = 1 } };
public static Density CentnerPerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { Centners = 1 } };
public static Density TonPerCentiMeterCubic { get; } = new() { PerCentiMeterCubic = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerCentiMeterCubic
{
get => new(_Value * VolumeConv.CentiMetersCubic.Multiplicator);
init => _Value = value._Value / VolumeConv.CentiMetersCubic.Multiplicator;
}
public static Density GramPerMeterCubic { get; } = new() { PerMeterCubic = new() { _Grams = 1 } };
public static Density KiloGramPerMeterCubic { get; } = new() { PerMeterCubic = new() { KiloGrams = 1 } };
public static Density CentnerPerMeterCubic { get; } = new() { PerMeterCubic = new() { Centners = 1 } };
public static Density TonPerMeterCubic { get; } = new() { PerMeterCubic = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerMeterCubic
{
get => new(_Value * VolumeConv.MetersCubic.Multiplicator);
init => _Value = value._Value / VolumeConv.MetersCubic.Multiplicator;
}
}
//namespace MetricSystem;
//[Owned, JsonConverter(typeof(MetricFormatter<Density>)), DebuggerDisplay("gr/(m*mm2) = {PerMeterCubic_PerMilliMetersCubicquared._Grams.ToString(\"0.###\")}, kg/(m*mm2) = {PerMeterCubic_PerMilliMetersCubicquared.KiloGrams.ToString(\"0.###\")}")]
//public partial class Density : Udel<Density, Mass>
//{
// [CollectionsOperatorsGenerator] public static PogonMass operator *(Area left, Density right) => right * left;
// [CollectionsOperatorsGenerator] public static PogonMass operator *(Density left, Area right) => left.MultiplyProtected<Density, Area, PogonMass>(right, PogonMassCoeff);
// static readonly double PogonMassCoeff = Coefficients.MultiplyCoefficient<Density, Area, PogonMass>(a => a._PerMilliMeterCubicCubic.Value = 1, b => b._MilliMetersCubicSquared = 1, r => r._PerMilliMeterCubic.Value = 1);
//}
//public partial class Volume : Metric<Volume, Volume>
//{
// [CollectionsOperatorsGenerator] public static Density operator /(Mass left, Volume right) => left.DivideProtected<Mass, Volume, Density>(right, DensityCoeff);
// static readonly double DensityCoeff = Coefficients.DivideCoefficient<Mass, Volume, Density>(a => a.Value = 1, b => b._MilliMetersCubicCubic = 1, r => r._PerMilliMeterCubicCubic.Value = 1);
//}

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is Newtons /// Base value is Newtons
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("N = {_Newtons.ToString(\"0.###\")}, kgf = {KiloGramForces.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("N = {_Newtons.ToString(\"0.###\")}, kgf = {KiloGramForces.ToString(\"0.###\")}")]
public readonly partial record struct Force public readonly partial record struct Force
{ {
[NotMapped, JsonIgnore] public double _Newtons { get => Newtons; init => Newtons = value; } public static Force Newton { get; } = new() { _Newtons = 1 };
[NotMapped, JsonIgnore] public double _Newtons { get => _Value; init => _Value = value; }
public static Force Newton { get; } = new() { Newtons = 1 };
[NotMapped, JsonIgnore] public double Newtons
{
get => _Value;
init
{
_Value = value;
}
}
public static Force KiloGramForce { get; } = new() { KiloGramForces = 1 }; public static Force KiloGramForce { get; } = new() { KiloGramForces = 1 };
[NotMapped, JsonIgnore] public double KiloGramForces [NotMapped, JsonIgnore] public double KiloGramForces

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is Hertz /// Base value is Hertz
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("Hz = {_Hertz.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("Hz = {_Hertz.ToString(\"0.###\")}")]
public readonly partial record struct Frequency public readonly partial record struct Frequency
{ {
[NotMapped, JsonIgnore] public double _Hertz { get => Hertz; init => Hertz = value; } public static Frequency OneHertz { get; } = new() { _Hertz = 1 };
[NotMapped, JsonIgnore] public double _Hertz { get => _Value; init => _Value = value; }
public static Frequency OneHertz { get; } = new() { Hertz = 1 };
[NotMapped, JsonIgnore] public double Hertz
{
get => _Value;
init
{
_Value = value;
}
}
public static Frequency OneKiloHertz { get; } = new() { KiloHertz = 1 }; public static Frequency OneKiloHertz { get; } = new() { KiloHertz = 1 };
[NotMapped, JsonIgnore] public double KiloHertz [NotMapped, JsonIgnore] public double KiloHertz

View File

@@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Base value is MilliMeters /// Base value is MilliMeters
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("mm = {_MilliMeters.ToString(\"0.###\")}, m = {Meters.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("mm = {_MilliMeters.ToString(\"0.###\")}, m = {Meters.ToString(\"0.###\")}")]
public readonly partial record struct Length public readonly partial record struct Length
{ {
public static Length MilliMeter { get; } = new(1); public static Length MilliMeter { get; } = new(1);
@@ -15,18 +15,7 @@ public readonly partial record struct Length
public double CentiMeters public double CentiMeters
{ {
get => LengthConv.CentiMeters.From(_Value); get => LengthConv.CentiMeters.From(_Value);
init init => _Value = LengthConv.CentiMeters.To(value);
{
Length aaa = new();
Length bbb = new();
if (aaa != bbb || aaa == bbb)
{
}
_Value = LengthConv.CentiMeters.To(value);
}
} }
public static Length DeciMeter { get; } = new(LengthConv.DeciMeters.To(1)); public static Length DeciMeter { get; } = new(LengthConv.DeciMeters.To(1));

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is Grams /// Base value is Grams
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("gr = {_Grams.ToString(\"0.###\")}, kg = {KiloGrams.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("gr = {_Grams.ToString(\"0.###\")}, kg = {KiloGrams.ToString(\"0.###\")}")]
public readonly partial record struct Mass public readonly partial record struct Mass
{ {
[NotMapped, JsonIgnore] public double _Grams { get => Grams; init => Grams = value; } public static Mass Gram { get; } = new() { _Grams = 1 };
[NotMapped, JsonIgnore] public double _Grams { get => _Value; init => _Value = value; }
public static Mass Gram { get; } = new() { Grams = 1 };
[NotMapped, JsonIgnore] public double Grams
{
get => _Value;
init
{
_Value = value;
}
}
public static Mass KiloGram { get; } = new() { KiloGrams = 1 }; public static Mass KiloGram { get; } = new() { KiloGrams = 1 };
[NotMapped, JsonIgnore] public double KiloGrams [NotMapped, JsonIgnore] public double KiloGrams

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is KiloGramsPerMeterSquared /// Base value is KiloGramsPerMeterSquared
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("kg/m2 = {_KiloGramsPerMeterSquared.ToString(\"0.###\")}, kg/mm2 = {KiloGramsPerMilliMeterSquared.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("kg/m2 = {_KiloGramsPerMeterSquared.ToString(\"0.###\")}, kg/mm2 = {KiloGramsPerMilliMeterSquared.ToString(\"0.###\")}")]
public readonly partial record struct MassPerSquare public readonly partial record struct MassPerSquare
{ {
[NotMapped, JsonIgnore] public double _KiloGramsPerMeterSquared { get => KiloGramsPerMeterSquared; init => KiloGramsPerMeterSquared = value; } public static MassPerSquare KiloGramPerMeterSquared { get; } = new() { _KiloGramsPerMeterSquared = 1 };
[NotMapped, JsonIgnore] public double _KiloGramsPerMeterSquared { get => _Value; init => _Value = value; }
public static MassPerSquare KiloGramPerMeterSquared { get; } = new() { KiloGramsPerMeterSquared = 1 };
[NotMapped, JsonIgnore] public double KiloGramsPerMeterSquared
{
get => _Value;
init
{
_Value = value;
}
}
public static MassPerSquare KiloGramPerMilliMeterSquared { get; } = new() { KiloGramsPerMilliMeterSquared = 1 }; public static MassPerSquare KiloGramPerMilliMeterSquared { get; } = new() { KiloGramsPerMilliMeterSquared = 1 };
[NotMapped, JsonIgnore] public double KiloGramsPerMilliMeterSquared [NotMapped, JsonIgnore] public double KiloGramsPerMilliMeterSquared

View File

@@ -1,14 +0,0 @@
//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<Length, Length>
//{
// [CollectionsOperatorsGenerator] public static PogonXXXXXXXX operator /(XXXXXXXX left, Length right) => left.DivideProtected<XXXXXXXX, Length, PogonXXXXXXXX>(right, PogonXXXXXXXXCoeff);
// static readonly double PogonXXXXXXXXCoeff = Coefficients.DivideCoefficient<XXXXXXXX, Length, PogonXXXXXXXX>(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1);
//}

View File

@@ -1,14 +0,0 @@
//namespace MetricSystem;
//[Owned, JsonConverter(typeof(MetricFormatter<PogonMass>)), DebuggerDisplay("gr/m = {PerMeter._Grams.ToString(\"0.###\")}, kg/m = {PerMeter.KiloGrams.ToString(\"0.###\")}")]
//public partial class PogonMass : Pogon<PogonMass, Mass>
//{
// [CollectionsOperatorsGenerator] public static Density operator /(PogonMass left, Area right) => left.DivideProtected<PogonMass, Area, Density>(right, UdelMassCoeff);
// static readonly double UdelMassCoeff = Coefficients.DivideCoefficient<PogonMass, Area, Density>(a => a._PerMilliMeter.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeterCubic.Value = 1);
//}
//public partial class Length : Metric<Length, Length>
//{
// [CollectionsOperatorsGenerator] public static PogonMass operator /(Mass left, Length right) => left.DivideProtected<Mass, Length, PogonMass>(right, PogonMassCoeff);
// static readonly double PogonMassCoeff = Coefficients.DivideCoefficient<Mass, Length, PogonMass>(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1);
//}

File diff suppressed because it is too large Load Diff

View File

@@ -1,61 +1,65 @@
#if DEBUG //#if DEBUG
namespace QWERTYkez.Mensura.Units.Pogon;
public readonly partial record struct PogonMass //// Reference
{
public static PogonMass GramPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Grams = 1 } }; //namespace QWERTYkez.Mensura.Units.Pogon;
public static PogonMass KiloGramPerMilliMeter { get; } = new() { _PerMilliMeter = new() { KiloGrams = 1 } };
public static PogonMass CentnerPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Centners = 1 } }; //[ComplexUnitGenerator]
public static PogonMass TonPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Tons = 1 } }; //public readonly partial record struct ZZZZZZZZZZZZZZZZ
[NotMapped, JsonIgnore] public Mass _PerMilliMeter //{
{ get => (Mass)_Value; init => _Value = (double)value; } // public static ZZZZZZZZZZZZZZZZ GramPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Grams = 1 } };
// public static ZZZZZZZZZZZZZZZZ KiloGramPerMilliMeter { get; } = new() { _PerMilliMeter = new() { KiloGrams = 1 } };
// public static ZZZZZZZZZZZZZZZZ CentnerPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Centners = 1 } };
// public static ZZZZZZZZZZZZZZZZ TonPerMilliMeter { get; } = new() { _PerMilliMeter = new() { Tons = 1 } };
// [NotMapped, JsonIgnore] public AAAAAAAAAAAAAAAA _PerMilliMeter
// { get => (AAAAAAAAAAAAAAAA)_Value; init => _Value = (double)value; }
public static PogonMass GramPerCentiMeter { get; } = new() { PerCentiMeter = new() { Grams = 1 } }; // public static ZZZZZZZZZZZZZZZZ GramPerCentiMeter { get; } = new() { PerCentiMeter = new() { Grams = 1 } };
public static PogonMass KiloGramPerCentiMeter { get; } = new() { PerCentiMeter = new() { KiloGrams = 1 } }; // public static ZZZZZZZZZZZZZZZZ KiloGramPerCentiMeter { get; } = new() { PerCentiMeter = new() { KiloGrams = 1 } };
public static PogonMass CentnerPerCentiMeter { get; } = new() { PerCentiMeter = new() { Centners = 1 } }; // public static ZZZZZZZZZZZZZZZZ CentnerPerCentiMeter { get; } = new() { PerCentiMeter = new() { Centners = 1 } };
public static PogonMass TonPerCentiMeter { get; } = new() { PerCentiMeter = new() { Tons = 1 } }; // public static ZZZZZZZZZZZZZZZZ TonPerCentiMeter { get; } = new() { PerCentiMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerCentiMeter // [NotMapped, JsonIgnore] public AAAAAAAAAAAAAAAA PerCentiMeter
{ // {
get => new(_Value * LengthConv.CentiMeters.Multiplicator); // get => new(_Value * BBBBBBBBBBBBBBBBConv.CentiMeters.Multiplicator);
init => _Value = value._Value / LengthConv.CentiMeters.Multiplicator; // init => _Value = value._Value / BBBBBBBBBBBBBBBBConv.CentiMeters.Multiplicator;
} // }
public static PogonMass GramPerDeciMeter { get; } = new() { PerDeciMeter = new() { Grams = 1 } }; // public static ZZZZZZZZZZZZZZZZ GramPerDeciMeter { get; } = new() { PerDeciMeter = new() { Grams = 1 } };
public static PogonMass KiloGramPerDeciMeter { get; } = new() { PerDeciMeter = new() { KiloGrams = 1 } }; // public static ZZZZZZZZZZZZZZZZ KiloGramPerDeciMeter { get; } = new() { PerDeciMeter = new() { KiloGrams = 1 } };
public static PogonMass CentnerPerDeciMeter { get; } = new() { PerDeciMeter = new() { Centners = 1 } }; // public static ZZZZZZZZZZZZZZZZ CentnerPerDeciMeter { get; } = new() { PerDeciMeter = new() { Centners = 1 } };
public static PogonMass TonPerDeciMeter { get; } = new() { PerDeciMeter = new() { Tons = 1 } }; // public static ZZZZZZZZZZZZZZZZ TonPerDeciMeter { get; } = new() { PerDeciMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerDeciMeter // [NotMapped, JsonIgnore] public AAAAAAAAAAAAAAAA PerDeciMeter
{ // {
get => new(_Value * LengthConv.DeciMeters.Multiplicator); // get => new(_Value * BBBBBBBBBBBBBBBBConv.DeciMeters.Multiplicator);
init => _Value = value._Value / LengthConv.DeciMeters.Multiplicator; // init => _Value = value._Value / BBBBBBBBBBBBBBBBConv.DeciMeters.Multiplicator;
} // }
public static PogonMass GramPerMeter { get; } = new() { PerMeter = new() { Grams = 1 } }; // public static ZZZZZZZZZZZZZZZZ GramPerMeter { get; } = new() { PerMeter = new() { Grams = 1 } };
public static PogonMass KiloGramPerMeter { get; } = new() { PerMeter = new() { KiloGrams = 1 } }; // public static ZZZZZZZZZZZZZZZZ KiloGramPerMeter { get; } = new() { PerMeter = new() { KiloGrams = 1 } };
public static PogonMass CentnerPerMeter { get; } = new() { PerMeter = new() { Centners = 1 } }; // public static ZZZZZZZZZZZZZZZZ CentnerPerMeter { get; } = new() { PerMeter = new() { Centners = 1 } };
public static PogonMass TonPerMeter { get; } = new() { PerMeter = new() { Tons = 1 } }; // public static ZZZZZZZZZZZZZZZZ TonPerMeter { get; } = new() { PerMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerMeter // [NotMapped, JsonIgnore] public AAAAAAAAAAAAAAAA PerMeter
{ // {
get => new(_Value * LengthConv.Meters.Multiplicator); // get => new(_Value * BBBBBBBBBBBBBBBBConv.Meters.Multiplicator);
init => _Value = value._Value / LengthConv.Meters.Multiplicator; // init => _Value = value._Value / BBBBBBBBBBBBBBBBConv.Meters.Multiplicator;
} // }
public static PogonMass GramPerKiloMeter { get; } = new() { PerKiloMeter = new() { Grams = 1 } }; // public static ZZZZZZZZZZZZZZZZ GramPerKiloMeter { get; } = new() { PerKiloMeter = new() { Grams = 1 } };
public static PogonMass KiloGramPerKiloMeter { get; } = new() { PerKiloMeter = new() { KiloGrams = 1 } }; // public static ZZZZZZZZZZZZZZZZ KiloGramPerKiloMeter { get; } = new() { PerKiloMeter = new() { KiloGrams = 1 } };
public static PogonMass CentnerPerKiloMeter { get; } = new() { PerKiloMeter = new() { Centners = 1 } }; // public static ZZZZZZZZZZZZZZZZ CentnerPerKiloMeter { get; } = new() { PerKiloMeter = new() { Centners = 1 } };
public static PogonMass TonPerKiloMeter { get; } = new() { PerKiloMeter = new() { Tons = 1 } }; // public static ZZZZZZZZZZZZZZZZ TonPerKiloMeter { get; } = new() { PerKiloMeter = new() { Tons = 1 } };
[NotMapped, JsonIgnore] public Mass PerKiloMeter // [NotMapped, JsonIgnore] public AAAAAAAAAAAAAAAA PerKiloMeter
{ // {
get => new(_Value * LengthConv.KiloMeters.Multiplicator); // get => new(_Value * BBBBBBBBBBBBBBBBConv.KiloMeters.Multiplicator);
init => _Value = value._Value / LengthConv.KiloMeters.Multiplicator; // init => _Value = value._Value / BBBBBBBBBBBBBBBBConv.KiloMeters.Multiplicator;
} // }
} //}
#endif //#endif

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is Pascals or NewtonsPerMeterSquared /// Base value is Pascals or NewtonsPerMeterSquared
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("Pa, N/m2 = {NewtonsPerMeterSquared.ToString(\"0.###\")}, kgf/mm2 = {KiloGramForcesPerMilliMeterSquared.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("Pa, N/m2 = {NewtonsPerMeterSquared.ToString(\"0.###\")}, kgf/mm2 = {KiloGramForcesPerMilliMeterSquared.ToString(\"0.###\")}")]
public readonly partial record struct Pressure public readonly partial record struct Pressure
{ {
[NotMapped, JsonIgnore] public double _Pascals { get => Pascals; init => Pascals = value; } public static Pressure Pascal { get; } = new() { _Pascals = 1 };
[NotMapped, JsonIgnore] public double _Pascals { get => _Value; init => _Value = value; }
public static Pressure Pascal { get; } = new() { Pascals = 1 };
[NotMapped, JsonIgnore] public double Pascals
{
get => _Value;
init
{
_Value = value;
}
}
public static Pressure NewtonPerMeterSquared { get; } = new() { NewtonsPerMeterSquared = 1 }; public static Pressure NewtonPerMeterSquared { get; } = new() { NewtonsPerMeterSquared = 1 };
[NotMapped, JsonIgnore] public double NewtonsPerMeterSquared [NotMapped, JsonIgnore] public double NewtonsPerMeterSquared

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is KiloMetersPerHour /// Base value is KiloMetersPerHour
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("km/h = {_KiloMetersPerHour.ToString(\"0.###\")}, m/s = {MetersPerSecond.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("km/h = {_KiloMetersPerHour.ToString(\"0.###\")}, m/s = {MetersPerSecond.ToString(\"0.###\")}")]
public readonly partial record struct Speed public readonly partial record struct Speed
{ {
[NotMapped, JsonIgnore] public double _KiloMetersPerHour { get => KiloMetersPerHour; init => KiloMetersPerHour = value; } public static Speed KiloMeterPerHour { get; } = new() { _KiloMetersPerHour = 1 };
[NotMapped, JsonIgnore] public double _KiloMetersPerHour { get => _Value; init => _Value = value; }
public static Speed KiloMeterPerHour { get; } = new() { KiloMetersPerHour = 1 };
[NotMapped, JsonIgnore] public double KiloMetersPerHour
{
get => _Value;
init
{
_Value = value;
}
}
public static Speed MeterPerSecond { get; } = new() { MetersPerSecond = 1 }; public static Speed MeterPerSecond { get; } = new() { MetersPerSecond = 1 };
[NotMapped, JsonIgnore] public double MetersPerSecond [NotMapped, JsonIgnore] public double MetersPerSecond

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is MilliSeconds /// Base value is MilliSeconds
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("ms = {_MilliSeconds.ToString(\"0.###\")}, s = {Seconds.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("ms = {_MilliSeconds.ToString(\"0.###\")}, s = {Seconds.ToString(\"0.###\")}")]
public readonly partial record struct Time public readonly partial record struct Time
{ {
[NotMapped, JsonIgnore] public double _MilliSeconds { get => MilliSeconds; init => MilliSeconds = value; } public static Time MilliSecond { get; } = new() { _MilliSeconds = 1 };
[NotMapped, JsonIgnore] public double _MilliSeconds { get => _Value; init => _Value = value; }
public static Time MilliSecond { get; } = new() { MilliSeconds = 1 };
[NotMapped, JsonIgnore] public double MilliSeconds
{
get => _Value;
init
{
_Value = value;
}
}
public static Time Second { get; } = new() { Seconds = 1 }; public static Time Second { get; } = new() { Seconds = 1 };
[NotMapped, JsonIgnore] public double Seconds [NotMapped, JsonIgnore] public double Seconds

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is Newton_Meters /// Base value is Newton_Meters
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("N*m = {_Newton_Meters.ToString(\"0.###\")}, kgf*m = {KiloGramForce_Meters.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("N*m = {_Newton_Meters.ToString(\"0.###\")}, kgf*m = {KiloGramForce_Meters.ToString(\"0.###\")}")]
public readonly partial record struct Torque public readonly partial record struct Torque
{ {
[NotMapped, JsonIgnore] public double _Newton_Meters { get => Newton_Meters; init => Newton_Meters = value; } public static Torque Newton_Meter { get; } = new() { _Newton_Meters = 1 };
[NotMapped, JsonIgnore] public double _Newton_Meters { get => _Value; init => _Value = value; }
public static Torque Newton_Meter { get; } = new() { Newton_Meters = 1 };
[NotMapped, JsonIgnore] public double Newton_Meters
{
get => _Value;
init
{
_Value = value;
}
}
public static Torque KiloGramForce_Meter { get; } = new() { KiloGramForce_Meters = 1 }; public static Torque KiloGramForce_Meter { get; } = new() { KiloGramForce_Meters = 1 };
[NotMapped, JsonIgnore] public double KiloGramForce_Meters [NotMapped, JsonIgnore] public double KiloGramForce_Meters

View File

@@ -1,16 +0,0 @@
//namespace MetricSystem;
//[Owned, JsonConverter(typeof(MetricFormatter<UdelForce>)), DebuggerDisplay("N/(m*mm2) = {PerMeter_PerMilliMeterSquared._Newtons.ToString(\"0.###\")}, kgf/(m*mm2) = {PerMeter_PerMilliMeterSquared.KiloGramForces.ToString(\"0.###\")}")]
//public partial class UdelForce : Udel<UdelForce, Force>
//{
// [CollectionsOperatorsGenerator] public static PogonForce operator *(Area left, UdelForce right) => right * left;
// [CollectionsOperatorsGenerator] public static PogonForce operator *(UdelForce left, Area right) => left.MultiplyProtected<UdelForce, Area, PogonForce>(right, PogonForceCoeff);
// static readonly double PogonForceCoeff = Coefficients.MultiplyCoefficient<UdelForce, Area, PogonForce>(a => a._PerMilliMeterCubic.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeter.Value = 1);
//}
//public partial class Volume : Metric<Volume, Volume>
//{
// [CollectionsOperatorsGenerator] public static UdelForce operator /(Force left, Volume right) => left.DivideProtected<Force, Volume, UdelForce>(right, UdelForceCoeff);
// static readonly double UdelForceCoeff = Coefficients.DivideCoefficient<Force, Volume, UdelForce>(a => a.Value = 1, b => b._MilliMetersCubic = 1, r => r._PerMilliMeterCubic.Value = 1);
//}

View File

@@ -1,16 +0,0 @@
//namespace MetricSystem;
//[Owned, JsonConverter(typeof(MetricFormatter<Density>)), DebuggerDisplay("gr/(m*mm2) = {PerMeter_PerMilliMeterSquared._Grams.ToString(\"0.###\")}, kg/(m*mm2) = {PerMeter_PerMilliMeterSquared.KiloGrams.ToString(\"0.###\")}")]
//public partial class Density : Udel<Density, Mass>
//{
// [CollectionsOperatorsGenerator] public static PogonMass operator *(Area left, Density right) => right * left;
// [CollectionsOperatorsGenerator] public static PogonMass operator *(Density left, Area right) => left.MultiplyProtected<Density, Area, PogonMass>(right, PogonMassCoeff);
// static readonly double PogonMassCoeff = Coefficients.MultiplyCoefficient<Density, Area, PogonMass>(a => a._PerMilliMeterCubic.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeter.Value = 1);
//}
//public partial class Volume : Metric<Volume, Volume>
//{
// [CollectionsOperatorsGenerator] public static Density operator /(Mass left, Volume right) => left.DivideProtected<Mass, Volume, Density>(right, DensityCoeff);
// static readonly double DensityCoeff = Coefficients.DivideCoefficient<Mass, Volume, Density>(a => a.Value = 1, b => b._MilliMetersCubic = 1, r => r._PerMilliMeterCubic.Value = 1);
//}

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is Volts /// Base value is Volts
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("V = {_Volts.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("V = {_Volts.ToString(\"0.###\")}")]
public readonly partial record struct Voltage public readonly partial record struct Voltage
{ {
[NotMapped, JsonIgnore] public double _Volts { get => Volts; init => Volts = value; } public static Voltage Volt { get; } = new() { _Volts = 1 };
[NotMapped, JsonIgnore] public double _Volts { get => _Value; init => _Value = value; }
public static Voltage Volt { get; } = new() { Volts = 1 };
[NotMapped, JsonIgnore] public double Volts
{
get => _Value;
init
{
_Value = value;
}
}
public static Voltage KiloVolt { get; } = new() { KiloVolts = 1 }; public static Voltage KiloVolt { get; } = new() { KiloVolts = 1 };
[NotMapped, JsonIgnore] public double KiloVolts [NotMapped, JsonIgnore] public double KiloVolts

View File

@@ -3,20 +3,12 @@
/// <summary> /// <summary>
/// Base value is MilliMetersCubic /// Base value is MilliMetersCubic
/// </summary> /// </summary>
[UnitOperatorsGenerator, DebuggerDisplay("mm3 = {_MilliMetersCubic.ToString(\"0.###\")}, m3 = {MetersCubic.ToString(\"0.###\")}")] [UnitGenerator, DebuggerDisplay("mm3 = {_MilliMetersCubic.ToString(\"0.###\")}, m3 = {MetersCubic.ToString(\"0.###\")}")]
public readonly partial record struct Volume public readonly partial record struct Volume
{ {
[NotMapped, JsonIgnore] public double _MilliMetersCubic { get => MilliMetersCubic; init => MilliMetersCubic = value; } public static Volume MilliMeterCubic { get; } = new() { _MilliMetersCubic = 1 };
[NotMapped, JsonIgnore] public double _MilliMetersCubic { get => _Value; init => _Value = value; }
public static Volume MilliMeterCubic { get; } = new() { MilliMetersCubic = 1 };
[NotMapped, JsonIgnore] public double MilliMetersCubic
{
get => _Value;
init
{
_Value = value;
}
}
public static Volume CentiMeterCubic { get; } = new() { CentiMetersCubic = 1 }; public static Volume CentiMeterCubic { get; } = new() { CentiMetersCubic = 1 };
[NotMapped, JsonIgnore] public double CentiMetersCubic [NotMapped, JsonIgnore] public double CentiMetersCubic

View File

@@ -13,3 +13,4 @@ global using System.Text.Json.Serialization;
global using QWERTYkez.Mensura; global using QWERTYkez.Mensura;
global using QWERTYkez.Mensura.Extensions; global using QWERTYkez.Mensura.Extensions;
global using QWERTYkez.Mensura.Units; global using QWERTYkez.Mensura.Units;
global using QWERTYkez.Mensura.Units.Complex;