diff --git a/src/CodeGeneration.Roslyn.Tests.Generators/RichBaseGenerator.cs b/src/CodeGeneration.Roslyn.Tests.Generators/RichBaseGenerator.cs index 1a8e91ee8..e608e5c18 100644 --- a/src/CodeGeneration.Roslyn.Tests.Generators/RichBaseGenerator.cs +++ b/src/CodeGeneration.Roslyn.Tests.Generators/RichBaseGenerator.cs @@ -85,11 +85,13 @@ public RichGenerationContext AddMember(MemberDeclarationSyntax memberDeclaration public RichGenerationResult CreateResult() { - return new RichGenerationResult( - SyntaxFactory.List(Members), - SyntaxFactory.List(Usings), - SyntaxFactory.List(AttributeLists), - SyntaxFactory.List(Externs)); + return new RichGenerationResult + { + Members = SyntaxFactory.List(Members), + Usings = SyntaxFactory.List(Usings), + AttributeLists = SyntaxFactory.List(AttributeLists), + Externs = SyntaxFactory.List(Externs), + }; } } } diff --git a/src/CodeGeneration.Roslyn/DocumentTransform.cs b/src/CodeGeneration.Roslyn/DocumentTransform.cs index bd507ab53..f86766bd4 100644 --- a/src/CodeGeneration.Roslyn/DocumentTransform.cs +++ b/src/CodeGeneration.Roslyn/DocumentTransform.cs @@ -83,13 +83,12 @@ public static async Task TransformAsync( var richGenerator = generator as IRichCodeGenerator ?? new EnrichingCodeGeneratorProxy(generator); - var (members, usings, attributeLists, externs) = - await richGenerator.GenerateRichAsync(context, progress, CancellationToken.None); + var emitted = await richGenerator.GenerateRichAsync(context, progress, CancellationToken.None); - emittedExterns = emittedExterns.AddRange(externs); - emittedUsings = emittedUsings.AddRange(usings); - emittedAttributeLists = emittedAttributeLists.AddRange(attributeLists); - emittedMembers = emittedMembers.AddRange(members); + emittedExterns = emittedExterns.AddRange(emitted.Externs); + emittedUsings = emittedUsings.AddRange(emitted.Usings); + emittedAttributeLists = emittedAttributeLists.AddRange(emitted.AttributeLists); + emittedMembers = emittedMembers.AddRange(emitted.Members); } } @@ -211,6 +210,7 @@ private class EnrichingCodeGeneratorProxy : IRichCodeGenerator { public EnrichingCodeGeneratorProxy(ICodeGenerator codeGenerator) { + Requires.NotNull(codeGenerator, nameof(codeGenerator)); CodeGenerator = codeGenerator; } @@ -229,7 +229,7 @@ public async Task GenerateRichAsync(TransformationContext var generatedMembers = await CodeGenerator.GenerateAsync(context, progress, CancellationToken.None); // Figure out ancestry for the generated type, including nesting types and namespaces. var wrappedMembers = context.ProcessingNode.Ancestors().Aggregate(generatedMembers, WrapInAncestor); - return new RichGenerationResult(wrappedMembers); + return new RichGenerationResult { Members = wrappedMembers }; } private static SyntaxList WrapInAncestor(SyntaxList generatedMembers, SyntaxNode ancestor) diff --git a/src/CodeGeneration.Roslyn/RichGenerationResult.cs b/src/CodeGeneration.Roslyn/RichGenerationResult.cs index 02789e44b..cba9904f1 100644 --- a/src/CodeGeneration.Roslyn/RichGenerationResult.cs +++ b/src/CodeGeneration.Roslyn/RichGenerationResult.cs @@ -13,55 +13,23 @@ namespace CodeGeneration.Roslyn public struct RichGenerationResult { /// - /// Creates with provided arguments as property values. + /// Gets or sets the to add to generated . /// - /// Assigned to . - /// Assigned to . - /// Assigned to . - /// Assigned to . - [DebuggerStepThrough] - public RichGenerationResult( - SyntaxList members, - SyntaxList usings = default, - SyntaxList attributeLists = default, - SyntaxList externs = default) - { - Members = members; - Usings = usings; - AttributeLists = attributeLists; - Externs = externs; - } + public SyntaxList Members { get; set; } /// - /// Gets to add to generated . + /// Gets or sets the to add to generated . /// - public SyntaxList Members { get; } + public SyntaxList Usings { get; set; } /// - /// Gets to add to generated . + /// Gets or sets the to add to generated . /// - public SyntaxList Usings { get; } + public SyntaxList Externs { get; set; } /// - /// Gets to add to generated . + /// Gets or sets the to add to generated . /// - public SyntaxList Externs { get; } - - /// - /// Gets to add to generated . - /// - public SyntaxList AttributeLists { get; } - - [DebuggerHidden, DebuggerStepThrough] - public void Deconstruct(out SyntaxList members, - out SyntaxList usings, - out SyntaxList attributeLists, - out SyntaxList externs) - { - members = Members; - usings = Usings; - attributeLists = AttributeLists; - externs = Externs; - } + public SyntaxList AttributeLists { get; set; } } }