@@ -36,8 +36,18 @@ public IEnumerable<IQuickFix> QuickFixes(IInspectionResult result)
3636 return _quickFixes [ result . Inspection . GetType ( ) ] ;
3737 }
3838
39+ private bool CanFix ( IQuickFix fix , Type inspection )
40+ {
41+ return _quickFixes . ContainsKey ( inspection ) && _quickFixes [ inspection ] . Contains ( fix ) ;
42+ }
43+
3944 public void Fix ( IQuickFix fix , IInspectionResult result )
4045 {
46+ if ( ! CanFix ( fix , result . Inspection . GetType ( ) ) )
47+ {
48+ throw new ArgumentException ( "Fix does not support this inspection." , nameof ( result ) ) ;
49+ }
50+
4151 fix . Fix ( result ) ;
4252 _state . GetRewriter ( result . QualifiedSelection . QualifiedName ) . Rewrite ( ) ;
4353 _state . OnParseRequested ( this ) ;
@@ -46,11 +56,21 @@ public void Fix(IQuickFix fix, IInspectionResult result)
4656 public void FixInProcedure ( IQuickFix fix , QualifiedSelection selection , Type inspectionType ,
4757 IEnumerable < IInspectionResult > results )
4858 {
59+ if ( ! CanFix ( fix , inspectionType ) )
60+ {
61+ throw new ArgumentException ( "Fix does not support this inspection." , nameof ( inspectionType ) ) ;
62+ }
63+
4964 throw new NotImplementedException ( "A qualified selection does not state which proc we are in, so we could really only use this on inspection results that expose a Declaration." ) ;
5065 }
5166
5267 public void FixInModule ( IQuickFix fix , QualifiedSelection selection , Type inspectionType , IEnumerable < IInspectionResult > results )
5368 {
69+ if ( ! CanFix ( fix , inspectionType ) )
70+ {
71+ throw new ArgumentException ( "Fix does not support this inspection." , nameof ( inspectionType ) ) ;
72+ }
73+
5474 var filteredResults = results
5575 . Where ( result => result . Inspection . GetType ( ) == inspectionType
5676 && result . QualifiedSelection . QualifiedName == selection . QualifiedName )
@@ -71,6 +91,11 @@ public void FixInModule(IQuickFix fix, QualifiedSelection selection, Type inspec
7191 public void FixInProject ( IQuickFix fix , QualifiedSelection selection , Type inspectionType ,
7292 IEnumerable < IInspectionResult > results )
7393 {
94+ if ( ! CanFix ( fix , inspectionType ) )
95+ {
96+ throw new ArgumentException ( "Fix does not support this inspection." , nameof ( inspectionType ) ) ;
97+ }
98+
7499 var filteredResults = results
75100 . Where ( result => result . Inspection . GetType ( ) == inspectionType
76101 && result . QualifiedSelection . QualifiedName . ProjectId == selection . QualifiedName . ProjectId )
@@ -95,6 +120,11 @@ public void FixInProject(IQuickFix fix, QualifiedSelection selection, Type inspe
95120
96121 public void FixAll ( IQuickFix fix , Type inspectionType , IEnumerable < IInspectionResult > results )
97122 {
123+ if ( ! CanFix ( fix , inspectionType ) )
124+ {
125+ throw new ArgumentException ( "Fix does not support this inspection." , nameof ( inspectionType ) ) ;
126+ }
127+
98128 var filteredResults = results . Where ( result => result . Inspection . GetType ( ) == inspectionType ) ;
99129
100130 foreach ( var result in filteredResults )
0 commit comments