Don't rewrite cast expressions

This commit is contained in:
Koen Bekkenutte
2022-01-23 00:40:33 +08:00
parent 7def9c21f0
commit ba5f4972de
4 changed files with 54 additions and 16 deletions
@@ -136,11 +136,15 @@ namespace EntityFrameworkCore.Projectables.Generator
if (node.Parent is MemberAccessExpressionSyntax parentMemberAccessNode)
{
var targetSymbolInfo = _semanticModel.GetSymbolInfo(parentMemberAccessNode.Expression);
if (targetSymbolInfo.Symbol is { Kind: SymbolKind.Parameter or SymbolKind.NamedType })
if (targetSymbolInfo.Symbol is null)
{
rewrite = false;
}
if (targetSymbolInfo.Symbol?.ContainingType is not null)
else if (targetSymbolInfo.Symbol is { Kind: SymbolKind.Parameter or SymbolKind.NamedType })
{
rewrite = false;
}
else if (targetSymbolInfo.Symbol?.ContainingType is not null)
{
if (!_compilation.HasImplicitConversion(targetSymbolInfo.Symbol.ContainingType, _targetTypeSymbol) ||
!SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))