From f73cbc7ebbf4643a7b999285cc4ce2e6628170e1 Mon Sep 17 00:00:00 2001 From: Koen Bekkenutte <2912652+kbekkenutte@users.noreply.github.com> Date: Sun, 12 Dec 2021 19:56:07 +0800 Subject: [PATCH] Added fix for inherited members --- .../ExpressionSyntaxRewriter.cs | 8 ++++++-- ...orkCore.Projectables.Generator.Tests.csproj | 5 ----- ...eneratorTests.InheritedMembers.received.txt | 18 ------------------ 3 files changed, 6 insertions(+), 25 deletions(-) delete mode 100644 tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.InheritedMembers.received.txt diff --git a/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs b/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs index e60f9b5..5d79a38 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/ExpressionSyntaxRewriter.cs @@ -98,7 +98,7 @@ namespace EntityFrameworkCore.Projectables.Generator { var symbolInfo = _semanticModel.GetSymbolInfo(node); - if (symbolInfo.Symbol is not null && SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol)) + if (symbolInfo.Symbol is not null) { var scopedNode = node.ChildNodes().FirstOrDefault(); if (scopedNode is ThisExpressionSyntax) @@ -127,7 +127,7 @@ namespace EntityFrameworkCore.Projectables.Generator if (symbolInfo.Symbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod) { } - else if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field && SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol)) + else if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field /*&& SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol)*/) { bool rewrite = true; @@ -138,6 +138,10 @@ namespace EntityFrameworkCore.Projectables.Generator { rewrite = false; } + if (targetSymbolInfo.Symbol?.ContainingType is not null && !_context.Compilation.HasImplicitConversion(targetSymbolInfo.Symbol.ContainingType, _targetTypeSymbol)) + { + rewrite = false; + } } else if (node.Parent.IsKind(SyntaxKind.SimpleAssignmentExpression)) { diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj index 759c58a..f9a5ec9 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj @@ -23,11 +23,6 @@ - - - - - diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.InheritedMembers.received.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.InheritedMembers.received.txt deleted file mode 100644 index e9bd765..0000000 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.InheritedMembers.received.txt +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using EntityFrameworkCore.Projectables; -using Foo; - -namespace EntityFrameworkCore.Projectables.Generated -#nullable disable -{ - public static class Foo_Bar_ProjectedId - { - public static System.Linq.Expressions.Expression> Expression() - { - return (global::Foo.Bar @this) => - Id; - } - } -} \ No newline at end of file