Skip to content

Need option to supress operator +(A value) generation #69

@lupin-de-mid

Description

@lupin-de-mid

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions