@@ -317,10 +317,12 @@ readonly partial struct {{unitTypeName}}
317
317
if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Addition ) )
318
318
{
319
319
net7Interfaces . Add ( $ "IAdditionOperators<{ unitTypeName } , { unitTypeName } , { unitTypeName } >") ;
320
+ net7Interfaces . Add ( $ "IUnaryPlusOperators<{ unitTypeName } , { unitTypeName } >") ;
320
321
}
321
322
if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Subtraction ) )
322
323
{
323
324
net7Interfaces . Add ( $ "ISubtractionOperators<{ unitTypeName } , { unitTypeName } , { unitTypeName } >") ;
325
+ net7Interfaces . Add ( $ "IUnaryNegationOperators<{ unitTypeName } , { unitTypeName } >") ;
324
326
}
325
327
if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Multiply ) )
326
328
{
@@ -330,12 +332,6 @@ readonly partial struct {{unitTypeName}}
330
332
{
331
333
net7Interfaces . Add ( $ "IDivisionOperators<{ unitTypeName } , { unitTypeName } , { unitTypeName } >") ;
332
334
}
333
- if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Multiply ) ||
334
- prop . HasArithmeticOperator ( UnitArithmeticOperators . Division ) )
335
- {
336
- net7Interfaces . Add ( $ "IUnaryPlusOperators<{ unitTypeName } , { unitTypeName } >") ;
337
- net7Interfaces . Add ( $ "IUnaryNegationOperators<{ unitTypeName } , { unitTypeName } >") ;
338
- }
339
335
if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Increment ) )
340
336
{
341
337
net7Interfaces . Add ( $ "IIncrementOperators<{ unitTypeName } >") ;
@@ -773,6 +769,9 @@ public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provid
773
769
}
774
770
}
775
771
772
+ """ ) ;
773
+ sb . AppendLine ( $$ """
774
+ public static {{ unitTypeName }} operator +({{ unitTypeName }} value) => new(({{ innerTypeName }} )(+value.value));
776
775
""" ) ;
777
776
}
778
777
if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Subtraction ) )
@@ -786,17 +785,22 @@ public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provid
786
785
}
787
786
}
788
787
788
+ """ ) ;
789
+ string zero = "" ;
790
+ if ( innerTypeName == "ulong" )
791
+ {
792
+ zero = "0UL " ;
793
+ }
794
+
795
+ sb . AppendLine ( $$ """
796
+ public static {{ unitTypeName }} operator -({{ unitTypeName }} value) => new(({{ innerTypeName }} )({{ zero }} -value.value));
797
+
789
798
""" ) ;
790
799
}
791
800
792
801
if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Multiply ) ||
793
802
prop . HasArithmeticOperator ( UnitArithmeticOperators . Division ) )
794
803
{
795
- sb . AppendLine ( $$ """
796
- public static {{ unitTypeName }} operator +({{ unitTypeName }} value) => new(({{ innerTypeName }} )(+value.value));
797
- public static {{ unitTypeName }} operator -({{ unitTypeName }} value) => new(({{ innerTypeName }} )(-value.value));
798
-
799
- """ ) ;
800
804
if ( prop . HasArithmeticOperator ( UnitArithmeticOperators . Multiply ) )
801
805
{
802
806
sb . AppendLine ( $$ """
0 commit comments