From a31752685df483f31699d87b9f57d3f4ca69aabf Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Tue, 27 Jan 2026 10:40:03 +0100 Subject: [PATCH] Refactor SetRangeWithFilterOperators to use constant for method name and improve type checking --- .../Analyzers/UseReturnValueForDatabaseReadMethods.cs | 2 +- .../Analyzers/SetRangeWithFilterOperators.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ALCops.ApplicationCop/Analyzers/UseReturnValueForDatabaseReadMethods.cs b/src/ALCops.ApplicationCop/Analyzers/UseReturnValueForDatabaseReadMethods.cs index 99b352c..1894497 100644 --- a/src/ALCops.ApplicationCop/Analyzers/UseReturnValueForDatabaseReadMethods.cs +++ b/src/ALCops.ApplicationCop/Analyzers/UseReturnValueForDatabaseReadMethods.cs @@ -34,7 +34,7 @@ private void AnalyzeInvocation(OperationAnalysisContext ctx) return; if (invocation.TargetMethod.MethodKind != EnumProvider.MethodKind.BuiltInMethod || - invocation.TargetMethod.ContainingSymbol?.Name != "Table" || + invocation.Instance?.Type.OriginalDefinition.Kind != EnumProvider.SymbolKind.Table || !DatabaseReadMethods.Contains(invocation.TargetMethod.Name)) return; diff --git a/src/ALCops.PlatformCop/Analyzers/SetRangeWithFilterOperators.cs b/src/ALCops.PlatformCop/Analyzers/SetRangeWithFilterOperators.cs index bd1897e..91de825 100644 --- a/src/ALCops.PlatformCop/Analyzers/SetRangeWithFilterOperators.cs +++ b/src/ALCops.PlatformCop/Analyzers/SetRangeWithFilterOperators.cs @@ -11,6 +11,8 @@ namespace ALCops.PlatformCop.Analyzers; [DiagnosticAnalyzer] public sealed class SetRangeWithFilterOperators : DiagnosticAnalyzer { + private const string SetRangeMethodName = "SetRange"; + private readonly Lazy replacementFieldPatternLazy = new Lazy((Func)(() => new Regex(@"%\d+", RegexOptions.Compiled))); private Regex ReplacementFieldPatternLazy => this.replacementFieldPatternLazy.Value; @@ -29,8 +31,8 @@ private void AnalyzeInvocation(OperationAnalysisContext ctx) return; if (operation.TargetMethod.MethodKind != EnumProvider.MethodKind.BuiltInMethod || - operation.TargetMethod.Name != "SetRange" || - operation.TargetMethod.ContainingSymbol?.Name != "Table" || + operation.TargetMethod.Name != SetRangeMethodName || + operation.Instance?.Type.OriginalDefinition.Kind != EnumProvider.SymbolKind.Table || operation.Arguments.Length < 2) return;