Skip to content

Commit 3fc37a7

Browse files
authored
Merge pull request #62 from Ted-Jin-Lab/development
✨Add Implicit From Attribute.
2 parents 7abd4f8 + d3789e4 commit 3fc37a7

5 files changed

Lines changed: 21 additions & 7 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.0</Version>
4+
<Version>2025.11.20.1</Version>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<LangVersion>preview</LangVersion>

Tests/TedToolkit.Console/Absorptance.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace TedToolkit.Quantities;
22

3+
[QuantityImplicitFromValueType]
34
[QuantityImplicitToValueType]
45
[QuantityOperator<AbsorbedDose, AbsorbedDose, double>(Operator.Divide)]
56
partial struct AbsorbedDose
@@ -10,5 +11,6 @@ public static void Test()
1011
var b = new AbsorbedDose(10, AbsorbedDoseUnit.Centigray);
1112
var c = a / b;
1213
double d = a;
14+
AbsorbedDose e = 10.0;
1315
}
1416
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public void GenerateCode(SourceProductionContext context)
442442
#region Conversions
443443

444444
ConversionOperatorDeclaration(
445-
Token(quantitySymbol?.GetAttributes().Any(a => a.AttributeClass?.GetName().FullName
445+
Token(quantitySymbol?.GetAttributes().Any(a => a.AttributeClass?.GetName().FullName
446446
is "global::TedToolkit.Quantities.QuantityImplicitToValueTypeAttribute") ?? false
447447
? SyntaxKind.ImplicitKeyword
448448
: SyntaxKind.ExplicitKeyword),
@@ -461,7 +461,11 @@ public void GenerateCode(SourceProductionContext context)
461461
IdentifierName("Value"))))
462462
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),
463463

464-
ConversionOperatorDeclaration(Token(SyntaxKind.ExplicitKeyword),
464+
ConversionOperatorDeclaration(
465+
Token(quantitySymbol?.GetAttributes().Any(a => a.AttributeClass?.GetName().FullName
466+
is "global::TedToolkit.Quantities.QuantityImplicitFromValueTypeAttribute") ?? false
467+
? SyntaxKind.ImplicitKeyword
468+
: SyntaxKind.ExplicitKeyword),
465469
IdentifierName(quantity.Name))
466470
.WithModifiers(
467471
TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace TedToolkit.Quantities;
2+
3+
/// <summary>
4+
/// Implicit convert from the value type
5+
/// </summary>
6+
[AttributeUsage(AttributeTargets.Struct)]
7+
public sealed class QuantityImplicitFromValueTypeAttribute: Attribute;
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Diagnostics.CodeAnalysis;
1+
namespace TedToolkit.Quantities;
22

3-
namespace TedToolkit.Quantities;
3+
/// <summary>
4+
/// Implicit convert to the value type
5+
/// </summary>
46
[AttributeUsage(AttributeTargets.Struct)]
5-
[SuppressMessage("ReSharper", "UnusedTypeParameter")]
6-
public sealed class QuantityImplicitToValueTypeAttribute: Attribute;
7+
public sealed class QuantityImplicitToValueTypeAttribute : Attribute;

0 commit comments

Comments
 (0)