Skip to content

Commit 8babbb9

Browse files
committed
Small update to generated output
1 parent fc6f73d commit 8babbb9

File tree

83 files changed

+264
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+264
-361
lines changed

src/AutoCtor.Shared/AutoConstructSourceGenerator/Emitter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ private static (SourceText?, ParameterList?) GenerateSource(
108108

109109
using (source.StartPartialType(type))
110110
{
111-
source.AddCompilerGeneratedAttribute().AddGeneratedCodeAttribute();
111+
source
112+
.AddCompilerGeneratedAttribute()
113+
.AddGeneratedCodeAttribute()
114+
.AddDebuggerNonUserCodeAttribute();
112115

113116
source.AppendIndent()
114117
.Append($"public {type.Name}({parameters})")

src/AutoCtor.Shared/Helpers/CodeBuilder.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ public CodeBuilder CloseBlock()
8787
public char IndentChar { get; set; } = '\t';
8888
public string Indent => new(IndentChar, _indent);
8989

90-
public CodeBuilder AddCompilerGeneratedAttribute() => AppendLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]");
90+
public CodeBuilder AddCompilerGeneratedAttribute() => AppendLine(
91+
"[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]");
92+
93+
public CodeBuilder AddDebuggerNonUserCodeAttribute() => AppendLine(
94+
"[global::System.Diagnostics.DebuggerNonUserCodeAttribute]");
9195

9296
public CodeBuilder AddGeneratedCodeAttribute() => AppendLine($"[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{s_assemblyName}\", \"{s_version}\")]");
9397

@@ -97,9 +101,6 @@ public CodeBuilder AppendHeader() =>
97101
.AppendLine($"// This code was generated by {s_packageProjectUrl}")
98102
.AppendLine($"// Version: {s_version}")
99103
.AppendLine($"// SHA: {s_gitSha}")
100-
.AppendLine($"//")
101-
.AppendLine($"// Changes to this file may cause incorrect behavior and will be lost if")
102-
.AppendLine($"// the code is regenerated.")
103104
.AppendLine($"// </auto-generated>")
104105
.AppendLine($"//------------------------------------------------------------------------------");
105106

src/AutoCtor.Tests/ExampleTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ public static TheoryData<CodeFileTheoryData> GetExamples()
9595

9696
var data = new TheoryData<CodeFileTheoryData>();
9797

98-
var exampleCode = File.ReadAllText(Path.Combine(BaseDir.FullName, "IExampleInterfaces.cs"));
99-
10098
foreach (var example in GetExamplesFiles("Examples"))
10199
{
102-
data.Add(new CodeFileTheoryData(example, exampleCode) with
100+
data.Add(new CodeFileTheoryData(example) with
103101
{
104102
IgnoredCompileDiagnostics = ["CS0414", "CS0169"] // Ignore unused fields
105103
});
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
using AutoCtor;
1+
public interface IService { }
22

3-
[AutoConstruct]
3+
[AutoCtor.AutoConstruct]
44
public partial class AllParametersAreSameTypeTest : BaseClass
55
{
6-
private readonly IA a;
6+
private readonly IService _service;
77

8-
[AutoPostConstruct]
9-
private void Initialize(IA a)
8+
[AutoCtor.AutoPostConstruct]
9+
private void Initialize(IService service)
1010
{
1111
}
1212
}
1313

1414
public abstract class BaseClass
1515
{
16-
public BaseClass(IA a)
16+
public BaseClass(IService baseService)
1717
{
1818
}
1919
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
[AutoCtor.AutoConstruct]
1+
public interface IService { }
2+
public interface IAnotherService { }
3+
4+
[AutoCtor.AutoConstruct]
25
public partial class AmbiguousMarkedMethods
36
{
4-
private readonly IA a;
7+
private readonly IService _service;
58

69
[AutoCtor.AutoPostConstruct]
710
private void Initialize()
811
{
912
}
1013

1114
[AutoCtor.AutoPostConstruct]
12-
private void Initialize(IB b)
15+
private void Initialize(IAnotherService anotherService)
1316
{
1417
}
1518
}

src/AutoCtor.Tests/Examples/ComflicingNames.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public interface IServiceA { }
2+
public interface IServiceB { }
3+
public interface IServiceC { }
4+
5+
[AutoCtor.AutoConstruct]
6+
public partial class AClass
7+
{
8+
private readonly IServiceA _service;
9+
}
10+
11+
[AutoCtor.AutoConstruct]
12+
public partial class BClass : AClass
13+
{
14+
private readonly IServiceB _service;
15+
}
16+
17+
[AutoCtor.AutoConstruct]
18+
public partial class CClass : BClass
19+
{
20+
private readonly IServiceC _service;
21+
}
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
using AutoCtor;
1+
public interface IServiceA { }
2+
public interface IServiceB { }
23

3-
[AutoConstruct]
4+
[AutoCtor.AutoConstruct]
45
public partial class GenericBase<T>
56
{
67
protected readonly T _t;
78
}
89

9-
[AutoConstruct]
10-
public partial class ConcreteClass : GenericBase<IExampleA>
10+
[AutoCtor.AutoConstruct]
11+
public partial class ConcreteClass : GenericBase<IServiceA>
1112
{
1213
}
1314

14-
[AutoConstruct]
15+
[AutoCtor.AutoConstruct]
1516
public partial class ConcreteClassWithGenericArg<T2> : GenericBase<T2>
1617
{
1718
}
1819

19-
[AutoConstruct]
20+
[AutoCtor.AutoConstruct]
2021
public partial class ConcreteClassWithAnotherField : ConcreteClass
2122
{
22-
protected readonly IExampleB exampleB;
23+
protected readonly IServiceB _serviceb;
2324
}
2425

25-
[AutoConstruct]
26+
[AutoCtor.AutoConstruct]
2627
public partial class GenericBase2<T1, T2>
2728
{
2829
protected readonly T1 _t1;
2930
protected readonly T2 _t2;
3031
}
3132

32-
[AutoConstruct]
33-
public partial class ConcreteClass1<T> : GenericBase2<IExampleA, T>
33+
[AutoCtor.AutoConstruct]
34+
public partial class ConcreteClass1<T> : GenericBase2<IServiceA, T>
3435
{
3536
}
3637

37-
[AutoConstruct]
38-
public partial class ConcreteClass2 : ConcreteClass1<IExampleB>
38+
[AutoCtor.AutoConstruct]
39+
public partial class ConcreteClass2 : ConcreteClass1<IServiceB>
3940
{
4041
}

src/AutoCtor.Tests/Examples/InheritanceTest.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
using AutoCtor;
1+
public interface IServiceA { }
2+
public interface IServiceB { }
3+
public interface IServiceC { }
4+
public interface IServiceD { }
5+
public interface IServiceE { }
26

3-
[AutoConstruct]
7+
[AutoCtor.AutoConstruct]
48
public partial class A : B
59
{
6-
private readonly IA a;
10+
private readonly IServiceA _serviceA;
711
}
812

9-
[AutoConstruct]
13+
[AutoCtor.AutoConstruct]
1014
public partial class B : C
1115
{
12-
private readonly IB b;
16+
private readonly IServiceB _serviceB;
1317
}
1418

15-
[AutoConstruct]
19+
[AutoCtor.AutoConstruct]
1620
public partial class C : D
1721
{
18-
private readonly IC c;
22+
private readonly IServiceC _serviceC;
1923
}
2024

21-
[AutoConstruct]
25+
[AutoCtor.AutoConstruct]
2226
public partial class D : E
2327
{
24-
private readonly ID d;
28+
private readonly IServiceD _serviceD;
2529
}
2630

27-
[AutoConstruct]
31+
[AutoCtor.AutoConstruct]
2832
public partial class E : F
2933
{
30-
private readonly IE e;
34+
private readonly IServiceE _serviceE;
3135
}
3236

3337
public class F
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
using AutoCtor;
1+
public interface IServiceA { }
2+
public interface IServiceB { }
3+
public interface IServiceC { }
4+
public interface IServiceD { }
5+
public interface IServiceE { }
6+
public interface IServiceF { }
27

3-
[AutoConstruct]
8+
[AutoCtor.AutoConstruct]
49
public partial class Generic<TA, TB>
510
{
611
protected readonly TA a;
712
protected readonly TB b;
813
}
914

10-
[AutoConstruct]
11-
public partial class Example1 : Generic<IA, IB>
15+
[AutoCtor.AutoConstruct]
16+
public partial class Example1 : Generic<IServiceA, IServiceB>
1217
{
13-
private readonly IC c;
18+
private readonly IServiceC c;
1419
}
1520

16-
[AutoConstruct]
17-
public partial class Example2 : Generic<ID, IE>
21+
[AutoCtor.AutoConstruct]
22+
public partial class Example2 : Generic<IServiceD, IServiceE>
1823
{
19-
private readonly IF f;
24+
private readonly IServiceF f;
2025
}

0 commit comments

Comments
 (0)