Merge pull request #17 from koenbeuk/issue-16

Ensure that NamedTypeSymbols are not being rewritten
This commit is contained in:
Koen
2022-01-12 00:06:18 +08:00
committed by GitHub
4 changed files with 55 additions and 1 deletions
@@ -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;
}
@@ -0,0 +1,14 @@
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class _SomeExtensions_Test
{
public static System.Linq.Expressions.Expression<System.Func<global::SomeFlag, bool>> Expression()
{
return (global::SomeFlag f) =>
f == global::SomeFlag.Foo;
}
}
}
@@ -0,0 +1,14 @@
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class _SomeExtensions_Test
{
public static System.Linq.Expressions.Expression<System.Func<global::SomeFlag, bool>> Expression()
{
return (global::SomeFlag f) =>
f == global::SomeFlag.Foo;
}
}
}
@@ -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)