@@ -21,25 +21,6 @@ public void GenerateCode(SourceProductionContext context)
2121 {
2222 List < MemberDeclarationSyntax > operators = [ ] ;
2323
24- if ( ! quantity . IsNoDimensions )
25- {
26- operators . Add (
27- OperatorDeclaration ( IdentifierName ( quantity . Name ) , Token ( SyntaxKind . AsteriskToken ) )
28- . WithModifiers ( TokenList ( Token ( SyntaxKind . PublicKeyword ) ,
29- Token ( SyntaxKind . StaticKeyword ) ) )
30- . WithAttributeLists ( [ GeneratedCodeAttribute ( typeof ( QuantityStructGenerator ) ) ] )
31- . WithParameterList ( ParameterList (
32- [
33- Parameter ( Identifier ( "left" ) ) . WithType ( IdentifierName ( typeName . FullName ) ) ,
34- Parameter ( Identifier ( "right" ) ) . WithType ( IdentifierName ( quantity . Name ) ) ,
35- ] ) )
36- . WithExpressionBody ( ArrowExpressionClause (
37- BinaryExpression ( SyntaxKind . MultiplyExpression ,
38- IdentifierName ( "right" ) ,
39- IdentifierName ( "left" ) ) ) )
40- . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ) ;
41- }
42-
4324 if ( quantitySymbol is not null )
4425 {
4526 foreach ( var attributeData in quantitySymbol . GetAttributes ( )
@@ -461,7 +442,8 @@ public void GenerateCode(SourceProductionContext context)
461442 #region Conversions
462443
463444 ConversionOperatorDeclaration (
464- Token ( quantity . IsNoDimensions
445+ Token ( quantitySymbol ? . GetAttributes ( ) . Any ( a => a . AttributeClass ? . GetName ( ) . FullName
446+ is "global::TedToolkit.Quantities.QuantityImplicitToValueTypeAttribute" ) ?? false
465447 ? SyntaxKind . ImplicitKeyword
466448 : SyntaxKind . ExplicitKeyword ) ,
467449 IdentifierName ( typeName . FullName ) ) . WithModifiers ( TokenList (
@@ -670,7 +652,7 @@ public void GenerateCode(SourceProductionContext context)
670652 ] ) ) ,
671653 LiteralExpression ( SyntaxKind . NumericLiteralExpression , Literal ( 0 ) ) ) ) )
672654 . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ,
673-
655+
674656 OperatorDeclaration ( PredefinedType ( Token ( SyntaxKind . BoolKeyword ) ) ,
675657 Token ( SyntaxKind . LessThanToken ) )
676658 . WithModifiers ( TokenList ( Token ( SyntaxKind . PublicKeyword ) , Token ( SyntaxKind . StaticKeyword ) ) )
@@ -714,7 +696,7 @@ public void GenerateCode(SourceProductionContext context)
714696 ] ) ) ,
715697 LiteralExpression ( SyntaxKind . NumericLiteralExpression , Literal ( 0 ) ) ) ) )
716698 . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ,
717-
699+
718700 OperatorDeclaration ( PredefinedType ( Token ( SyntaxKind . BoolKeyword ) ) ,
719701 Token ( SyntaxKind . LessThanEqualsToken ) )
720702 . WithModifiers ( TokenList ( Token ( SyntaxKind . PublicKeyword ) , Token ( SyntaxKind . StaticKeyword ) ) )
@@ -736,6 +718,7 @@ public void GenerateCode(SourceProductionContext context)
736718 ] ) ) ,
737719 LiteralExpression ( SyntaxKind . NumericLiteralExpression , Literal ( 0 ) ) ) ) )
738720 . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ,
721+
739722 #endregion
740723
741724 #region Operators
@@ -829,6 +812,21 @@ public void GenerateCode(SourceProductionContext context)
829812 IdentifierName ( "right" ) ) ) ) ) )
830813 . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ,
831814
815+ OperatorDeclaration ( IdentifierName ( quantity . Name ) , Token ( SyntaxKind . AsteriskToken ) )
816+ . WithModifiers ( TokenList ( Token ( SyntaxKind . PublicKeyword ) ,
817+ Token ( SyntaxKind . StaticKeyword ) ) )
818+ . WithAttributeLists ( [ GeneratedCodeAttribute ( typeof ( QuantityStructGenerator ) ) ] )
819+ . WithParameterList ( ParameterList (
820+ [
821+ Parameter ( Identifier ( "left" ) ) . WithType ( IdentifierName ( typeName . FullName ) ) ,
822+ Parameter ( Identifier ( "right" ) ) . WithType ( IdentifierName ( quantity . Name ) ) ,
823+ ] ) )
824+ . WithExpressionBody ( ArrowExpressionClause (
825+ BinaryExpression ( SyntaxKind . MultiplyExpression ,
826+ IdentifierName ( "right" ) ,
827+ IdentifierName ( "left" ) ) ) )
828+ . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ,
829+
832830 ..operators ,
833831
834832 #endregion
0 commit comments