From 389eec39653abeeac6b596fbf508378a9bc34f65 Mon Sep 17 00:00:00 2001 From: Koen Bekkenutte <2912652+kbekkenutte@users.noreply.github.com> Date: Mon, 14 Jun 2021 22:27:25 +0800 Subject: [PATCH] Perf tweak --- src/ScenarioTests.Generator/ScenarioTestGenerator.cs | 2 +- src/ScenarioTests.Generator/SyntaxReceiver.cs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ScenarioTests.Generator/ScenarioTestGenerator.cs b/src/ScenarioTests.Generator/ScenarioTestGenerator.cs index 1fe9a30..a5126d3 100644 --- a/src/ScenarioTests.Generator/ScenarioTestGenerator.cs +++ b/src/ScenarioTests.Generator/ScenarioTestGenerator.cs @@ -24,7 +24,7 @@ public void Initialize(GeneratorInitializationContext context) => public void Execute(GeneratorExecutionContext context) { // retrieve the populated receiver - if (context.SyntaxReceiver is not SyntaxReceiver receiver) + if (context.SyntaxReceiver is not SyntaxReceiver receiver || receiver.ScenarioCandidates is null) { return; } diff --git a/src/ScenarioTests.Generator/SyntaxReceiver.cs b/src/ScenarioTests.Generator/SyntaxReceiver.cs index 5c24401..4614488 100644 --- a/src/ScenarioTests.Generator/SyntaxReceiver.cs +++ b/src/ScenarioTests.Generator/SyntaxReceiver.cs @@ -7,7 +7,7 @@ namespace ScenarioTests.Generator { public class SyntaxReceiver : ISyntaxReceiver { - public List ScenarioCandidates { get; } = new List(); + public List ScenarioCandidates { get; private set; } public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { @@ -20,6 +20,11 @@ public void OnVisitSyntaxNode(SyntaxNode syntaxNode) if (hasScenarioAttribute) { + if (ScenarioCandidates is null) + { + ScenarioCandidates = new(); + } + ScenarioCandidates.Add(methodDeclarationSyntax); } }