diff --git a/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs b/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs index 7fc3a8f..3eab520 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs @@ -22,7 +22,7 @@ namespace EntityFrameworkCore.Projectables.Generator return; } - if (receiver.Candidates.Count > 0) + if (receiver.Candidates?.Count > 0) { var projectables = receiver.Candidates .Select(x => ProjectableInterpreter.GetDescriptor(x, context)) diff --git a/src/EntityFrameworkCore.Projectables.Generator/SyntaxReceiver.cs b/src/EntityFrameworkCore.Projectables.Generator/SyntaxReceiver.cs index 111dfa0..f205f96 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/SyntaxReceiver.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/SyntaxReceiver.cs @@ -10,7 +10,7 @@ namespace EntityFrameworkCore.Projectables.Generator { public class SyntaxReceiver : ISyntaxReceiver { - public List Candidates { get; } = new List(); + public List? Candidates { get; private set; } public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { @@ -22,6 +22,11 @@ namespace EntityFrameworkCore.Projectables.Generator if (hasProjectableAttribute) { + if (Candidates == null) + { + Candidates = new(); + } + Candidates.Add(memberDeclarationSyntax); } }