diff --git a/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs b/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs index f3ebaf3..1afaed8 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs @@ -136,7 +136,7 @@ namespace EntityFrameworkCore.Projectables.Generator if (node.Parent is MemberAccessExpressionSyntax parentMemberAccessNode) { var targetSymbolInfo = _semanticModel.GetSymbolInfo(parentMemberAccessNode.Expression); - if (targetSymbolInfo.Symbol is { Kind: SymbolKind.Parameter }) + if (targetSymbolInfo.Symbol is { Kind: SymbolKind.Parameter or SymbolKind.NamedType }) { rewrite = false; } diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.EnumAccessor.received.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.EnumAccessor.received.txt new file mode 100644 index 0000000..366603d --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.EnumAccessor.received.txt @@ -0,0 +1,14 @@ +using EntityFrameworkCore.Projectables; + +namespace EntityFrameworkCore.Projectables.Generated +#nullable disable +{ + public static class _SomeExtensions_Test + { + public static System.Linq.Expressions.Expression> Expression() + { + return (global::SomeFlag f) => + f == global::SomeFlag.Foo; + } + } +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.EnumAccessor.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.EnumAccessor.verified.txt new file mode 100644 index 0000000..366603d --- /dev/null +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.EnumAccessor.verified.txt @@ -0,0 +1,14 @@ +using EntityFrameworkCore.Projectables; + +namespace EntityFrameworkCore.Projectables.Generated +#nullable disable +{ + public static class _SomeExtensions_Test + { + public static System.Linq.Expressions.Expression> Expression() + { + return (global::SomeFlag f) => + f == global::SomeFlag.Foo; + } + } +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs index eea6d27..c6d06bf 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs @@ -1019,6 +1019,32 @@ namespace Foos { return Verifier.Verify(result.GeneratedTrees[0].ToString()); } + [Fact] + public Task EnumAccessor() + { + var compilation = CreateCompilation(@" +using EntityFrameworkCore.Projectables; + +public enum SomeFlag +{ + Foo +} + +public static class SomeExtensions +{ + [Projectable] + public static bool Test(this SomeFlag f) => f == SomeFlag.Foo; +} +"); + + var result = RunGenerator(compilation); + + Assert.Empty(result.Diagnostics); + Assert.Single(result.GeneratedTrees); + + return Verifier.Verify(result.GeneratedTrees[0].ToString()); + } + #region Helpers Compilation CreateCompilation(string source, bool expectedToCompile = true)