This commit is contained in:
melekhin
2026-05-29 16:45:24 +07:00
parent 7ebbeb7855
commit ba77411c4a
31 changed files with 2544 additions and 345 deletions

View File

@@ -16,7 +16,7 @@ internal class CollectionsOperatorsGenerator : IIncrementalGenerator
private const string AttributeSource = @"namespace QWERTYkez.Mensura;
[System.AttributeUsage(System.AttributeTargets.Class | 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 { }";
public void Initialize(IncrementalGeneratorInitializationContext context)

View File

@@ -91,16 +91,21 @@ namespace QWERTYkez.Mensura
// Вы должны скопировать сюда всё содержимое вашего второго файла,
// заменив XXXXXXXXXXXXXX на {typeName}.
string skeleton = @"
global using {typeName} = QWERTYkez.Mensura.Units.{typeName};
global using {typeName}Extensions = QWERTYkez.Mensura.Units.{typeName}Extensions;
global using {typeName}Converter = QWERTYkez.Mensura.Units.{typeName}Converter;
using System.Globalization;
using System.Runtime.Serialization;
namespace QWERTYkez.Mensura.Units;
[JsonConverter(typeof({typeName}Converter))]
public readonly partial record struct {typeName}
public readonly partial record struct {typeName} : IMensuraUnit<{typeName}>, IEquatable<{typeName}>, IMensuraUnit
{
[JsonInclude, DataMember, JsonPropertyName(""v"")] // для JSON / EF на случай сбоев, если пробелма с _Value
internal double Value { get => _Value; init => _Value = value; }
double IMensuraUnit.Value { get => _Value; init => _Value = value; }
internal readonly double _Value;
internal {typeName}(double value) => _Value = value;
@@ -113,8 +118,13 @@ public readonly partial record struct {typeName}
[JsonIgnore, IgnoreDataMember] public bool IsPositive => _Value >= 0;
[JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero => _Value > 0;
[JsonIgnore, IgnoreDataMember] public bool IsNegative => _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 {typeName} Zero { get; } = new(0d);
@@ -298,7 +308,7 @@ public readonly partial record struct {typeName}
}
}
public static class {typeName}Extension
public static class {typeName}Extensions
{
internal static double ToDouble(this {typeName}? unit) => unit is null ? 0d : unit.Value._Value;