Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit a956836

Browse files
committed
Touch-ups on PR
1 parent c5c79fb commit a956836

File tree

3 files changed

+22
-52
lines changed

3 files changed

+22
-52
lines changed

src/CodeGeneration.Roslyn.Tests.Generators/RichBaseGenerator.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ public RichGenerationContext AddMember(MemberDeclarationSyntax memberDeclaration
8585

8686
public RichGenerationResult CreateResult()
8787
{
88-
return new RichGenerationResult(
89-
SyntaxFactory.List(Members),
90-
SyntaxFactory.List(Usings),
91-
SyntaxFactory.List(AttributeLists),
92-
SyntaxFactory.List(Externs));
88+
return new RichGenerationResult
89+
{
90+
Members = SyntaxFactory.List(Members),
91+
Usings = SyntaxFactory.List(Usings),
92+
AttributeLists = SyntaxFactory.List(AttributeLists),
93+
Externs = SyntaxFactory.List(Externs),
94+
};
9395
}
9496
}
9597
}

src/CodeGeneration.Roslyn/DocumentTransform.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ public static async Task<SyntaxTree> TransformAsync(
8383

8484
var richGenerator = generator as IRichCodeGenerator ?? new EnrichingCodeGeneratorProxy(generator);
8585

86-
var (members, usings, attributeLists, externs) =
87-
await richGenerator.GenerateRichAsync(context, progress, CancellationToken.None);
86+
var emitted = await richGenerator.GenerateRichAsync(context, progress, CancellationToken.None);
8887

89-
emittedExterns = emittedExterns.AddRange(externs);
90-
emittedUsings = emittedUsings.AddRange(usings);
91-
emittedAttributeLists = emittedAttributeLists.AddRange(attributeLists);
92-
emittedMembers = emittedMembers.AddRange(members);
88+
emittedExterns = emittedExterns.AddRange(emitted.Externs);
89+
emittedUsings = emittedUsings.AddRange(emitted.Usings);
90+
emittedAttributeLists = emittedAttributeLists.AddRange(emitted.AttributeLists);
91+
emittedMembers = emittedMembers.AddRange(emitted.Members);
9392
}
9493
}
9594

@@ -211,6 +210,7 @@ private class EnrichingCodeGeneratorProxy : IRichCodeGenerator
211210
{
212211
public EnrichingCodeGeneratorProxy(ICodeGenerator codeGenerator)
213212
{
213+
Requires.NotNull(codeGenerator, nameof(codeGenerator));
214214
CodeGenerator = codeGenerator;
215215
}
216216

@@ -229,7 +229,7 @@ public async Task<RichGenerationResult> GenerateRichAsync(TransformationContext
229229
var generatedMembers = await CodeGenerator.GenerateAsync(context, progress, CancellationToken.None);
230230
// Figure out ancestry for the generated type, including nesting types and namespaces.
231231
var wrappedMembers = context.ProcessingNode.Ancestors().Aggregate(generatedMembers, WrapInAncestor);
232-
return new RichGenerationResult(wrappedMembers);
232+
return new RichGenerationResult { Members = wrappedMembers };
233233
}
234234

235235
private static SyntaxList<MemberDeclarationSyntax> WrapInAncestor(SyntaxList<MemberDeclarationSyntax> generatedMembers, SyntaxNode ancestor)

src/CodeGeneration.Roslyn/RichGenerationResult.cs

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,23 @@ namespace CodeGeneration.Roslyn
1313
public struct RichGenerationResult
1414
{
1515
/// <summary>
16-
/// Creates <see cref="RichGenerationResult"/> with provided arguments as property values.
16+
/// Gets or sets the <see cref="MemberDeclarationSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
1717
/// </summary>
18-
/// <param name="members">Assigned to <see cref="Members"/>.</param>
19-
/// <param name="usings">Assigned to <see cref="Usings"/>.</param>
20-
/// <param name="attributeLists">Assigned to <see cref="AttributeLists"/>.</param>
21-
/// <param name="externs">Assigned to <see cref="Externs"/>.</param>
22-
[DebuggerStepThrough]
23-
public RichGenerationResult(
24-
SyntaxList<MemberDeclarationSyntax> members,
25-
SyntaxList<UsingDirectiveSyntax> usings = default,
26-
SyntaxList<AttributeListSyntax> attributeLists = default,
27-
SyntaxList<ExternAliasDirectiveSyntax> externs = default)
28-
{
29-
Members = members;
30-
Usings = usings;
31-
AttributeLists = attributeLists;
32-
Externs = externs;
33-
}
18+
public SyntaxList<MemberDeclarationSyntax> Members { get; set; }
3419

3520
/// <summary>
36-
/// Gets <see cref="MemberDeclarationSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
21+
/// Gets or sets the <see cref="UsingDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
3722
/// </summary>
38-
public SyntaxList<MemberDeclarationSyntax> Members { get; }
23+
public SyntaxList<UsingDirectiveSyntax> Usings { get; set; }
3924

4025
/// <summary>
41-
/// Gets <see cref="UsingDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
26+
/// Gets or sets the <see cref="ExternAliasDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
4227
/// </summary>
43-
public SyntaxList<UsingDirectiveSyntax> Usings { get; }
28+
public SyntaxList<ExternAliasDirectiveSyntax> Externs { get; set; }
4429

4530
/// <summary>
46-
/// Gets <see cref="ExternAliasDirectiveSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
31+
/// Gets or sets the <see cref="AttributeListSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
4732
/// </summary>
48-
public SyntaxList<ExternAliasDirectiveSyntax> Externs { get; }
49-
50-
/// <summary>
51-
/// Gets <see cref="AttributeListSyntax"/> to add to generated <see cref="CompilationUnitSyntax"/>.
52-
/// </summary>
53-
public SyntaxList<AttributeListSyntax> AttributeLists { get; }
54-
55-
[DebuggerHidden, DebuggerStepThrough]
56-
public void Deconstruct(out SyntaxList<MemberDeclarationSyntax> members,
57-
out SyntaxList<UsingDirectiveSyntax> usings,
58-
out SyntaxList<AttributeListSyntax> attributeLists,
59-
out SyntaxList<ExternAliasDirectiveSyntax> externs)
60-
{
61-
members = Members;
62-
usings = Usings;
63-
attributeLists = AttributeLists;
64-
externs = Externs;
65-
}
33+
public SyntaxList<AttributeListSyntax> AttributeLists { get; set; }
6634
}
6735
}

0 commit comments

Comments
 (0)