diff --git a/LiftLog.Ui/Models/Utils.cs b/LiftLog.Ui/Models/Utils.cs index bf2ff3b8..8951f2c8 100644 --- a/LiftLog.Ui/Models/Utils.cs +++ b/LiftLog.Ui/Models/Utils.cs @@ -25,25 +25,11 @@ public static implicit operator DecimalValue(decimal value) return new DecimalValue(units, nanos); } - public static implicit operator decimal?(DecimalValue? grpcDecimal) - { - if (grpcDecimal is null) - { - return null; - } - return grpcDecimal.Units + grpcDecimal.Nanos / NanoFactor; - } + public static implicit operator decimal?(DecimalValue? grpcDecimal) => + grpcDecimal is null ? null : (decimal)grpcDecimal; - public static implicit operator DecimalValue?(decimal? value) - { - if (value is null) - { - return null; - } - var units = decimal.ToInt64(value.Value); - var nanos = decimal.ToInt32((value.Value - units) * NanoFactor); - return new DecimalValue(units, nanos); - } + public static implicit operator DecimalValue?(decimal? value) => + value is null ? null : (DecimalValue)value.Value; } internal partial class DateOnlyDao @@ -60,13 +46,11 @@ public DateOnlyDao(int year, int month, int day) public static implicit operator DateOnlyDao(DateOnly model) => new(model.Year, model.Month, model.Day); - public static implicit operator DateOnlyDao?(DateOnly? model) => - model is null - ? null - : new DateOnlyDao(model.Value.Year, model.Value.Month, model.Value.Day); - public static implicit operator DateOnly?(DateOnlyDao? dao) => - dao is null ? null : new DateOnly(dao.Year, dao.Month, dao.Day); + dao is null ? null : (DateOnly)dao; + + public static implicit operator DateOnlyDao?(DateOnly? value) => + value is null ? null : (DateOnlyDao)value.Value; } internal partial class TimeOnlyDao @@ -85,18 +69,11 @@ public static implicit operator TimeOnly(TimeOnlyDao dao) => public static implicit operator TimeOnlyDao(TimeOnly model) => new(model.Hour, model.Minute, model.Second, model.Millisecond); - public static implicit operator TimeOnlyDao?(TimeOnly? model) => - model is null - ? null - : new TimeOnlyDao( - model.Value.Hour, - model.Value.Minute, - model.Value.Second, - model.Value.Millisecond - ); - public static implicit operator TimeOnly?(TimeOnlyDao? dao) => - dao is null ? null : new TimeOnly(dao.Hour, dao.Minute, dao.Second, dao.Millisecond); + dao is null ? null : (TimeOnly)dao; + + public static implicit operator TimeOnlyDao?(TimeOnly? value) => + value is null ? null : (TimeOnlyDao)value.Value; } internal partial class UUIDDao @@ -111,8 +88,7 @@ public UUIDDao(Guid value) public static implicit operator Guid(UUIDDao dao) => new(dao.Value.ToByteArray()); public static implicit operator UUIDDao?(Guid? value) => - value is null ? null : new UUIDDao(value.Value); + value is null ? null : (UUIDDao)value.Value; - public static implicit operator Guid?(UUIDDao? dao) => - dao is null ? null : new Guid(dao.Value.ToByteArray()); + public static implicit operator Guid?(UUIDDao? dao) => dao is null ? null : (Guid)dao; }