1+ using System ;
12using System . Collections . Generic ;
23using System . Collections . Immutable ;
34using System . Linq ;
910using Microsoft . CodeAnalysis . Diagnostics ;
1011
1112using Sql . Analyzer . Extensions ;
13+ using Sql . Analyzer . Parsers ;
1214
1315namespace Sql . Analyzer
1416{
@@ -27,8 +29,6 @@ public class DapperParametersMatchingAnalyzer : DiagnosticAnalyzer
2729
2830 private static readonly string Title = "Parameters mismatching" ;
2931
30- private static readonly Regex SqlParameterRegex = new Regex ( @"@(?<variable>\w+)" , RegexOptions . Compiled ) ;
31-
3232 private static readonly DiagnosticDescriptor CsharpArgumentNotFoundRule = new DiagnosticDescriptor (
3333 DiagnosticId ,
3434 Title ,
@@ -71,8 +71,8 @@ private void ReportDiagnostics(
7171 SyntaxNodeAnalysisContext context ,
7272 InvocationExpressionSyntax invocationExpressionSyntax )
7373 {
74- List < string > sqlVariables = new List < string > ( ) ;
75- List < string > sharpParameters = null ;
74+ ICollection < string > sqlVariables = null ;
75+ ICollection < string > sharpParameters = null ;
7676 foreach ( var argument in invocationExpressionSyntax . ArgumentList . Arguments )
7777 {
7878 var parameter = argument . DetermineParameter ( context . SemanticModel ) ;
@@ -86,11 +86,7 @@ private void ReportDiagnostics(
8686 return ;
8787 }
8888
89- var matches = SqlParameterRegex . Matches ( sourceText ) ;
90- foreach ( Match match in matches )
91- {
92- sqlVariables . Add ( match . Groups [ "variable" ] . Value ) ;
93- }
89+ sqlVariables = SqlParser . FindParameters ( sourceText ) ;
9490
9591 continue ;
9692 }
@@ -102,12 +98,12 @@ private void ReportDiagnostics(
10298 }
10399 }
104100
105- if ( sharpParameters == null )
101+ if ( sharpParameters == null || sqlVariables == null )
106102 {
107103 return ;
108104 }
109105
110- foreach ( var notFoundArgument in sqlVariables . Except ( sharpParameters ) )
106+ foreach ( var notFoundArgument in sqlVariables . Except ( sharpParameters , StringComparer . InvariantCultureIgnoreCase ) )
111107 {
112108 context . ReportDiagnostic (
113109 Diagnostic . Create (
@@ -116,7 +112,7 @@ private void ReportDiagnostics(
116112 notFoundArgument ) ) ;
117113 }
118114
119- foreach ( var notFoundVariable in sharpParameters . Except ( sqlVariables ) )
115+ foreach ( var notFoundVariable in sharpParameters . Except ( sqlVariables , StringComparer . InvariantCultureIgnoreCase ) )
120116 {
121117 context . ReportDiagnostic (
122118 Diagnostic . Create (
0 commit comments