Skip to content

Commit 55aa6fd

Browse files
committed
Renamed attribute to avoid issues with MS version
1 parent 6e96ae5 commit 55aa6fd

File tree

27 files changed

+83
-75
lines changed

27 files changed

+83
-75
lines changed

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ public PostConstructMethod(IService service)
105105

106106
### Keyed Services
107107

108-
When using `Microsoft.Extensions.DependencyInjection` you can mark fields and properties with `[FromKeyedServicesAttribute]` and it will be included in the constructor.
108+
When using `Microsoft.Extensions.DependencyInjection` you can mark fields and properties with `[AutoKeyedService]` and it will be included in the constructor.
109109

110110
<!-- snippet: KeyedService -->
111111
<a id='snippet-KeyedService'></a>
112112
```cs
113113
[AutoConstruct]
114114
public partial class KeyedExampleClass
115115
{
116-
[FromKeyedServices("key")]
116+
[AutoKeyedService("key")]
117117
private readonly IService _keyedService;
118118
}
119119
```

readme.source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ snippet: PostConstructGeneratedCode
3737

3838
### Keyed Services
3939

40-
When using `Microsoft.Extensions.DependencyInjection` you can mark fields and properties with `[FromKeyedServicesAttribute]` and it will be included in the constructor.
40+
When using `Microsoft.Extensions.DependencyInjection` you can mark fields and properties with `[AutoKeyedService]` and it will be included in the constructor.
4141

4242
snippet: KeyedService
4343

src/AutoCtor.Attributes/AutoConstructAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ public sealed class AutoConstructIgnoreAttribute : Attribute;
2626

2727
[AttributeUsage(Field | Property | Parameter, Inherited = false)]
2828
[Conditional("AUTOCTOR_USAGES")]
29-
public sealed class FromKeyedServicesAttribute(object? key) : Attribute;
29+
public sealed class AutoKeyedServiceAttribute(object? key) : Attribute;

src/AutoCtor.Example/BasicExamples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public partial class PropertyExamples
9999
[AutoConstruct]
100100
public partial class KeyedExampleClass
101101
{
102-
[FromKeyedServices("key")]
102+
[AutoKeyedService("key")]
103103
private readonly IService _keyedService;
104104
}
105105

src/AutoCtor.Shared/Helpers/CodeBuilder.InterpolatedStringHandler.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ private void AppendCommaSeparated(IEnumerable<string> items)
5252

5353
private void AppendCommaIndented(IEnumerable<string> items)
5454
{
55-
var count = items.Count();
56-
57-
if (count < 3)
55+
var length = items.Sum(s => s.Length);
56+
if (length < 60)
5857
{
5958
AppendCommaSeparated(items);
6059
return;

src/AutoCtor.Shared/Helpers/GeneratorUtilities.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public static bool IsMethodDeclaration(SyntaxNode node, CancellationToken cancel
7777
public static string? GetServiceKey(ISymbol symbol)
7878
{
7979
var keyedService = symbol.GetAttributes()
80-
.Where(a => a.AttributeClass?.ToDisplayString() == AttributeNames.FromKeyedServices)
80+
.Where(a => a.AttributeClass?.ToDisplayString() == AttributeNames.AutoKeyedService
81+
|| a.AttributeClass?.ToDisplayString() == "Microsoft.Extensions.DependencyInjection.FromKeyedServicesAttribute")
8182
.FirstOrDefault();
8283

8384
if (keyedService != null)

src/AutoCtor.Shared/Models/AttributeNames.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
public const string AutoConstruct = "AutoCtor.AutoConstructAttribute";
44
public const string AutoPostConstruct = "AutoCtor.AutoPostConstructAttribute";
55
public const string AutoConstructIgnore = "AutoCtor.AutoConstructIgnoreAttribute";
6-
public const string FromKeyedServices = "AutoCtor.FromKeyedServicesAttribute";
6+
public const string AutoKeyedService = "AutoCtor.AutoKeyedServiceAttribute";
77
}

src/AutoCtor.Tests/Examples/BaseTest.ExamplesGeneratedCode#TheClass.g.verified.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ partial class TheClass
99
{
1010
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
1111
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
12-
public TheClass(
13-
int number,
14-
string text,
15-
bool flag
16-
) : base(number, text)
12+
public TheClass(int number, string text, bool flag) : base(number, text)
1713
{
1814
this._flag = flag;
1915
}

src/AutoCtor.Tests/Examples/FriendlyParameterNamesTest.ExamplesGeneratedCode#FriendlyParameterNamesTest.g.verified.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ partial class FriendlyParameterNamesTest
99
{
1010
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
1111
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
12-
public FriendlyParameterNamesTest(
13-
int underscorePrefix,
14-
int camelCase,
15-
int PascalCase
16-
)
12+
public FriendlyParameterNamesTest(int underscorePrefix, int camelCase, int PascalCase)
1713
{
1814
this._underscorePrefix = underscorePrefix;
1915
this.camelCase = camelCase;

src/AutoCtor.Tests/Examples/InheritanceTest.ExamplesGeneratedCode#A.g.verified.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ public A(
1515
global::IServiceC serviceC,
1616
global::IServiceB serviceB,
1717
global::IServiceA serviceA
18-
) : base(
19-
serviceE,
20-
serviceD,
21-
serviceC,
22-
serviceB
23-
)
18+
) : base(serviceE, serviceD, serviceC, serviceB)
2419
{
2520
this._serviceA = serviceA;
2621
}

0 commit comments

Comments
 (0)