Skip to content

Commit e796074

Browse files
authored
Merge pull request #66 from Ted-Jin-Lab/development
Display
2 parents 4144ab6 + cd0a309 commit e796074

6 files changed

Lines changed: 48 additions & 3 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<PropertyGroup>
4-
<Version>2025.11.20.3</Version>
4+
<Version>2025.11.20.4</Version>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<LangVersion>preview</LangVersion>

Tests/TedToolkit.Console/Absorptance.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ public static void Test()
1313
double d = a;
1414
AbsorbedDose e = 10.0;
1515
}
16+
}
17+
18+
[QuantityDisplayUnit<DimensionlessUnit>(DimensionlessUnit.Number)]
19+
partial struct Dimensionless
20+
{
1621

1722
}

Tests/TedToolkit.Console/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
[assembly: NumberExtension<int, Angle>]
99
[assembly: NumberExtension<double, Angle>]
1010

11-
[assembly:Quantities<double>(QuantitySystems.SI, "AbsorbedDose")]
11+
[assembly:Quantities<double>(QuantitySystems.ALL, "AbsorbedDose", "Dimensionless", "DimensionlessRatio")]

src/analyzers/TedToolkit.Quantities.Analyzer/QuantityStructGenerator.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void GenerateCode(SourceProductionContext context)
5050
.WithAttributeLists([
5151
GeneratedCodeAttribute(typeof(QuantityStructGenerator))
5252
])
53+
.WithXmlComment()
5354
.WithParameterList(ParameterList(
5455
[
5556
Parameter(Identifier("left")).WithType(IdentifierName(leftType.Name)),
@@ -203,6 +204,7 @@ public void GenerateCode(SourceProductionContext context)
203204
PropertyDeclaration(IdentifierName(quantity.Name), Identifier("Zero"))
204205
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
205206
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
207+
.WithXmlCommentInheritDoc((string?)null)
206208
.WithExpressionBody(ArrowExpressionClause(CastExpression(
207209
IdentifierName(quantity.Name),
208210
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)))))
@@ -211,6 +213,7 @@ public void GenerateCode(SourceProductionContext context)
211213
PropertyDeclaration(IdentifierName(quantity.Name), Identifier("One"))
212214
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
213215
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
216+
.WithXmlCommentInheritDoc((string?)null)
214217
.WithExpressionBody(ArrowExpressionClause(CastExpression(
215218
IdentifierName(quantity.Name),
216219
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1)))))
@@ -773,6 +776,7 @@ public void GenerateCode(SourceProductionContext context)
773776
OperatorDeclaration(IdentifierName(quantity.Name), Token(SyntaxKind.MinusToken))
774777
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
775778
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
779+
.WithXmlComment()
776780
.WithParameterList(ParameterList(
777781
[
778782
Parameter(Identifier("value")).WithType(IdentifierName(quantity.Name))
@@ -786,6 +790,7 @@ public void GenerateCode(SourceProductionContext context)
786790
OperatorDeclaration(IdentifierName(quantity.Name), Token(SyntaxKind.PlusToken))
787791
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
788792
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
793+
.WithXmlComment()
789794
.WithParameterList(ParameterList(
790795
[
791796
Parameter(Identifier("left")).WithType(IdentifierName(quantity.Name)),
@@ -806,6 +811,7 @@ public void GenerateCode(SourceProductionContext context)
806811
OperatorDeclaration(IdentifierName(quantity.Name), Token(SyntaxKind.PercentToken))
807812
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
808813
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
814+
.WithXmlComment()
809815
.WithParameterList(ParameterList(
810816
[
811817
Parameter(Identifier("left")).WithType(IdentifierName(quantity.Name)),
@@ -827,6 +833,7 @@ public void GenerateCode(SourceProductionContext context)
827833
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword),
828834
Token(SyntaxKind.StaticKeyword)))
829835
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
836+
.WithXmlComment()
830837
.WithParameterList(ParameterList(
831838
[
832839
Parameter(Identifier("left")).WithType(IdentifierName(quantity.Name)),
@@ -847,6 +854,7 @@ public void GenerateCode(SourceProductionContext context)
847854
.WithAttributeLists([
848855
GeneratedCodeAttribute(typeof(QuantityStructGenerator))
849856
])
857+
.WithXmlComment()
850858
.WithParameterList(ParameterList(
851859
[
852860
Parameter(Identifier("left")).WithType(IdentifierName(quantity.Name)),
@@ -863,6 +871,7 @@ public void GenerateCode(SourceProductionContext context)
863871
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword),
864872
Token(SyntaxKind.StaticKeyword)))
865873
.WithAttributeLists([GeneratedCodeAttribute(typeof(QuantityStructGenerator))])
874+
.WithXmlComment()
866875
.WithParameterList(ParameterList(
867876
[
868877
Parameter(Identifier("left")).WithType(IdentifierName(typeName.FullName)),
@@ -941,6 +950,28 @@ private ExpressionSyntax GetSystemUnitName()
941950
Literal(quantity.Name));
942951
}
943952

953+
if (quantitySymbol?.GetAttributes().FirstOrDefault(a =>
954+
a.AttributeClass is { IsGenericType: true } attributeClass
955+
&& attributeClass.ConstructUnboundGenericType().GetName().FullName is
956+
"global::TedToolkit.Quantities.QuantityDisplayUnitAttribute<>") is { } displayUnitAttribute)
957+
{
958+
var syntax = displayUnitAttribute.ApplicationSyntaxReference?.GetSyntax()
959+
as AttributeSyntax;
960+
var argSyntax = syntax?.ArgumentList?.Arguments[0].Expression;
961+
var argText = argSyntax?.ToString();
962+
if (argText is not null)
963+
return InvocationExpression(
964+
MemberAccessExpression(
965+
SyntaxKind.SimpleMemberAccessExpression,
966+
IdentifierName(argText),
967+
IdentifierName("ToString")))
968+
.WithArgumentList(ArgumentList(
969+
[
970+
Argument(IdentifierName("index")),
971+
Argument(IdentifierName("formatProvider"))
972+
]));
973+
}
974+
944975
if (quantity.IsNoDimensions)
945976
{
946977
var memberName = allUnits

src/libraries/TedToolkit.Quantities/IQuantity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IQuantity<TQuantity, TValue, in TUnit> :
1717
#endif
1818
IConvertible
1919
where TQuantity : struct, IQuantity<TQuantity, TValue, TUnit>
20-
where TUnit : Enum
20+
where TUnit : struct, Enum
2121
{
2222
#if NET7_0_OR_GREATER
2323
/// <summary/>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TedToolkit.Quantities;
2+
3+
/// <summary>
4+
/// The Quantity Display Unit Attribute.
5+
/// </summary>
6+
/// <param name="enum"></param>
7+
[AttributeUsage(AttributeTargets.Struct)]
8+
public sealed class QuantityDisplayUnitAttribute<TEnum>(TEnum @enum) : Attribute
9+
where TEnum : struct, Enum;

0 commit comments

Comments
 (0)