Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>2025.11.19.5</Version>
<Version>2025.11.19.6</Version>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
Expand Down
2 changes: 2 additions & 0 deletions Tests/TedToolkit.Console/Absorptance.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace TedToolkit.Quantities;

[QuantityImplicitToValueType]
[QuantityOperator<AbsorbedDose, AbsorbedDose, double>(Operator.Divide)]
partial struct AbsorbedDose
{
Expand All @@ -8,5 +9,6 @@ public static void Test()
var a = new AbsorbedDose(10, AbsorbedDoseUnit.Centigray);
var b = new AbsorbedDose(10, AbsorbedDoseUnit.Centigray);
var c = a / b;
double d = a;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@ public void GenerateCode(SourceProductionContext context)
{
List<MemberDeclarationSyntax> operators = [];

if (!quantity.IsNoDimensions)
{
operators.Add(
OperatorDeclaration(IdentifierName(quantity.Name), Token(SyntaxKind.AsteriskToken))
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword),
Token(SyntaxKind.StaticKeyword)))
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
.WithParameterList(ParameterList(
[
Parameter(Identifier("left")).WithType(IdentifierName(typeName.FullName)),
Parameter(Identifier("right")).WithType(IdentifierName(quantity.Name)),
]))
.WithExpressionBody(ArrowExpressionClause(
BinaryExpression(SyntaxKind.MultiplyExpression,
IdentifierName("right"),
IdentifierName("left"))))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)));
}

if (quantitySymbol is not null)
{
foreach (var attributeData in quantitySymbol.GetAttributes()
Expand Down Expand Up @@ -461,7 +442,8 @@ public void GenerateCode(SourceProductionContext context)
#region Conversions

ConversionOperatorDeclaration(
Token(quantity.IsNoDimensions
Token(quantitySymbol?.GetAttributes().Any(a => a.AttributeClass?.GetName().FullName
is "global::TedToolkit.Quantities.QuantityImplicitToValueTypeAttribute") ?? false
? SyntaxKind.ImplicitKeyword
: SyntaxKind.ExplicitKeyword),
IdentifierName(typeName.FullName)).WithModifiers(TokenList(
Expand Down Expand Up @@ -670,7 +652,7 @@ public void GenerateCode(SourceProductionContext context)
])),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)))))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),

OperatorDeclaration(PredefinedType(Token(SyntaxKind.BoolKeyword)),
Token(SyntaxKind.LessThanToken))
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
Expand Down Expand Up @@ -714,7 +696,7 @@ public void GenerateCode(SourceProductionContext context)
])),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)))))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),

OperatorDeclaration(PredefinedType(Token(SyntaxKind.BoolKeyword)),
Token(SyntaxKind.LessThanEqualsToken))
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
Expand All @@ -736,6 +718,7 @@ public void GenerateCode(SourceProductionContext context)
])),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)))))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),

#endregion

#region Operators
Expand Down Expand Up @@ -829,6 +812,21 @@ public void GenerateCode(SourceProductionContext context)
IdentifierName("right"))))))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),

OperatorDeclaration(IdentifierName(quantity.Name), Token(SyntaxKind.AsteriskToken))
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword),
Token(SyntaxKind.StaticKeyword)))
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
.WithParameterList(ParameterList(
[
Parameter(Identifier("left")).WithType(IdentifierName(typeName.FullName)),
Parameter(Identifier("right")).WithType(IdentifierName(quantity.Name)),
]))
.WithExpressionBody(ArrowExpressionClause(
BinaryExpression(SyntaxKind.MultiplyExpression,
IdentifierName("right"),
IdentifierName("left"))))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),

..operators,

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace TedToolkit.Quantities;
[AttributeUsage(AttributeTargets.Struct)]
[SuppressMessage("ReSharper", "UnusedTypeParameter")]
public sealed class QuantityImplicitToValueTypeAttribute: Attribute;