Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDunn committed Oct 21, 2024
1 parent 0b31eb3 commit 9b1c1b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
19 changes: 4 additions & 15 deletions src/Vogen/Rules/DoNotCompareWithPrimitivesInEfCoreAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void AnalyzeInvocation(SyntaxNodeAnalysisContext context)
return;
}

if (!IsAMemberOfDbSet(context, memberAccessExpr)) return;
if (!IsAMemberOfDbSet(context, memberAccessExpr.Expression)) return;

foreach (ArgumentSyntax eachArgument in invocationExpr.ArgumentList.Arguments.Where(e => e.Expression is LambdaExpressionSyntax))
{
Expand All @@ -75,7 +75,7 @@ private static void AnalyzeQieryExpression(SyntaxNodeAnalysisContext context)
var whereClauses = queryExpr.Body.DescendantNodes().OfType<WhereClauseSyntax>();
var fromClause = queryExpr.FromClause;

if (!IsAMemberOfDbSet(context, fromClause)) return;
if (!IsAMemberOfDbSet(context, fromClause.Expression)) return;

foreach (var eachArgument in whereClauses)
{
Expand All @@ -95,21 +95,10 @@ private static void AnalyzeQieryExpression(SyntaxNodeAnalysisContext context)
}
}

private static bool IsAMemberOfDbSet(SyntaxNodeAnalysisContext context, MemberAccessExpressionSyntax memberAccessExpr)
private static bool IsAMemberOfDbSet(SyntaxNodeAnalysisContext context, ExpressionSyntax expressionSyntax)
{
var symbolInfo = context.SemanticModel.GetSymbolInfo(memberAccessExpr.Expression);
if (symbolInfo.Symbol is not IPropertySymbol ps) return false;

var dbSetType = context.SemanticModel.Compilation.GetTypeByMetadataName("Microsoft.EntityFrameworkCore.DbSet`1");

if (dbSetType is null) return false;
var symbolInfo = context.SemanticModel.GetSymbolInfo(expressionSyntax);

return InheritsFrom(ps.Type, dbSetType);
}

private static bool IsAMemberOfDbSet(SyntaxNodeAnalysisContext context, FromClauseSyntax fromClauseSyntax)
{
var symbolInfo = context.SemanticModel.GetSymbolInfo(fromClauseSyntax.Expression);
if (symbolInfo.Symbol is not IPropertySymbol ps) return false;

var dbSetType = context.SemanticModel.Compilation.GetTypeByMetadataName("Microsoft.EntityFrameworkCore.DbSet`1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ private static async Task<string[]> CombineUserAndGeneratedSource(string userSou

var strippedSource = _placeholderPattern.Replace(userSource, string.Empty).Replace("|}", string.Empty);

NuGetPackage[] packages = [new("Microsoft.EntityFrameworkCore", "8.0.10", string.Empty)];

(ImmutableArray<Diagnostic> Diagnostics, SyntaxTree[] GeneratedSources) output = await new ProjectBuilder()
.WithUserSource(strippedSource)
//.WithNugetPackages(packages)
Expand Down

0 comments on commit 9b1c1b2

Please sign in to comment.