Skip to content

Commit 2a4a7b4

Browse files
committed
Renamed GenerateDelegateAttribute to UseDelegateFromConstructorAttributes
1 parent 7ad1b93 commit 2a4a7b4

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

docs

Submodule docs updated from 4a74d2a to b3e97fa

samples/Thinktecture.Runtime.Extensions.Samples/SmartEnums/SalesCsvImporterType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class SalesCsvImporterType
1212
public int ArticleIdIndex { get; }
1313
public int VolumeIndex { get; }
1414

15-
[GenerateDelegate]
15+
[UseDelegateFromConstructor]
1616
public partial DateTime GetDateTime(CsvReader csvReader);
1717

1818
private static DateTime GetDateTimeForDaily(CsvReader csvReader)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/SmartEnumCodeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public override int GetHashCode()
218218
if (_state.KeyMember is not null && !_state.Settings.SkipToString)
219219
GenerateToString(_state.KeyMember);
220220

221-
GenerateDelegateMethods();
221+
GenerateDelegatedMethods();
222222

223223
var hasSaneNumberOfItems = _state.Items.Count < 1000;
224224

@@ -266,7 +266,7 @@ public override int GetHashCode()
266266
}");
267267
}
268268

269-
private void GenerateDelegateMethods()
269+
private void GenerateDelegatedMethods()
270270
{
271271
foreach (var method in _state.DelegateMethods)
272272
{

src/Thinktecture.Runtime.Extensions.SourceGenerator/Extensions/TypeSymbolExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ public static bool IsValueObjectMemberIgnoreAttribute(this ITypeSymbol? attribut
141141
return attributeType is { Name: "ValueObjectMemberIgnoreAttribute", ContainingNamespace: { Name: "Thinktecture", ContainingNamespace.IsGlobalNamespace: true } };
142142
}
143143

144-
public static bool IsGenerateDelegateAttribute(this ITypeSymbol? attributeType)
144+
public static bool IsUseDelegateFromConstructorAttribute(this ITypeSymbol? attributeType)
145145
{
146146
if (attributeType is null || attributeType.TypeKind == TypeKind.Error)
147147
return false;
148148

149-
return attributeType is { Name: "GenerateDelegateAttribute", ContainingNamespace: { Name: "Thinktecture", ContainingNamespace.IsGlobalNamespace: true } };
149+
return attributeType is { Name: "UseDelegateFromConstructorAttribute", ContainingNamespace: { Name: "Thinktecture", ContainingNamespace.IsGlobalNamespace: true } };
150150
}
151151

152152
public static bool IsEnum(
@@ -690,10 +690,9 @@ public static IReadOnlyList<DelegateMethodState> GetDelegateMethods(
690690
if (!methodSymbol.IsPartialDefinition)
691691
continue;
692692

693-
var generateDelegateAttribute = methodSymbol.FindAttribute(a => a.IsGenerateDelegateAttribute());
694-
;
693+
var useDelegateFromConstructorAttribute = methodSymbol.FindAttribute(a => a.IsUseDelegateFromConstructorAttribute());
695694

696-
if (generateDelegateAttribute == null)
695+
if (useDelegateFromConstructorAttribute == null)
697696
continue;
698697

699698
var methodName = methodSymbol.Name;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Thinktecture;
22

33
/// <summary>
4-
/// Marks a partial method in of a Smart Enum or keyed Value Object to be implemented through a delegate.
4+
/// Marks a partial method of a Smart Enum to be implemented through a delegate.
55
/// The source generator will automatically generate a private delegate field and wire it up through the constructor.
66
/// </summary>
77
/// <example>
@@ -11,12 +11,12 @@ namespace Thinktecture;
1111
/// {
1212
/// public static readonly ImporterType Default = new(ProcessDefault);
1313
///
14-
/// [GenerateDelegate]
15-
/// public partial string Process(object input);
14+
/// [UseDelegateFromConstructor]
15+
/// public partial string Process(int input);
1616
///
17-
/// private static string ProcessDefault(object input) => input.ToString();
17+
/// private static string ProcessDefault(int input) => input.ToString();
1818
/// }
1919
/// </code>
2020
/// </example>
2121
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
22-
public sealed class GenerateDelegateAttribute : Attribute;
22+
public sealed class UseDelegateFromConstructorAttribute : Attribute;

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/EnumSourceGeneratorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ public abstract partial class TestEnum
740740
public static readonly TestEnum Item1 = null!;
741741
public static readonly TestEnum Item2 = null!;
742742
743-
[GenerateDelegate]
743+
[UseDelegateFromConstructor]
744744
public partial Task<string?>? Method1(string? arg1);
745745
}
746746
}
@@ -769,7 +769,7 @@ public abstract partial class TestEnum
769769
public static readonly TestEnum Item1 = null!;
770770
public static readonly TestEnum Item2 = null!;
771771
772-
[GenerateDelegate]
772+
[UseDelegateFromConstructor]
773773
protected partial int Method1();
774774
}
775775
}
@@ -798,7 +798,7 @@ public abstract partial class TestEnum
798798
public static readonly TestEnum Item1 = null!;
799799
public static readonly TestEnum Item2 = null!;
800800
801-
[GenerateDelegate]
801+
[UseDelegateFromConstructor]
802802
partial void Method1(string arg1, int arg2);
803803
}
804804
}
@@ -827,7 +827,7 @@ public abstract partial class TestEnum
827827
public static readonly TestEnum Item1 = null!;
828828
public static readonly TestEnum Item2 = null!;
829829
830-
[GenerateDelegate]
830+
[UseDelegateFromConstructor]
831831
internal partial void Method1();
832832
}
833833
}

test/Thinktecture.Runtime.Extensions.Tests.Shared/TestEnums/TestEnumWithDelegateGeneration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public partial class TestEnumWithDelegateGeneration
66
public static readonly TestEnumWithDelegateGeneration Item1 = new(1, s => $"{s} + 1");
77
public static readonly TestEnumWithDelegateGeneration Item2 = new(2, s => $"{s} + 2");
88

9-
[GenerateDelegate]
9+
[UseDelegateFromConstructor]
1010
public partial string Foo(int bar);
1111
}

0 commit comments

Comments
 (0)