UnitGenerator icon indicating copy to clipboard operation
UnitGenerator copied to clipboard

Need option to supress operator +(A value) generation

Open lupin-de-mid opened this issue 2 months ago • 0 comments

I try update my app from unitgenerator 1.4.10 to 2.0.0 for this code

using Speckle.DoubleNumerics;
using UnitGenerator;

[UnitOf(typeof(Vector2))]
public partial struct Speed{}

But Speckle.DoubleNumerics (https://github.com/specklesystems/Speckle.DoubleNumerics) not support Vector2 + unary operator.

UnitArithmeticOperators.Addition generate them all together.

in code https://github.com/Cysharp/UnitGenerator/blob/master/src/UnitGenerator/SourceGenerator2.cs#L284

 if (prop.HasFlag(UnitGenerateOptions.ArithmeticOperator))
        {
            if (prop.HasArithmeticOperator(UnitArithmeticOperators.Addition))
            {
                net7Interfaces.Add($"IAdditionOperators<{unitTypeName}, {unitTypeName}, {unitTypeName}>");
                net7Interfaces.Add($"IUnaryPlusOperators<{unitTypeName}, {unitTypeName}>");
            }

But in readme

| UnitArithmeticOperators.Multiply    | `T operator *(T, T)`,  `T operator +(T)`, `T operator-(T)` |

and in reality

[UnitOf(typeof(Vector2), UnitGenerateOptions.ArithmeticOperator,
	ArithmeticOperators = UnitArithmeticOperators.Addition	)]
public partial struct S
{
}

still generate

 public static S operator +(S value) => new((Speckle.DoubleNumerics.Vector2)(+value.value));

Probably it could be similar to UnitGenerateOptions.WithoutComparisonOperator but for unary addition

lupin-de-mid avatar Oct 08 '25 19:10 lupin-de-mid