@@ -615,10 +615,21 @@ public bool HasSpecialVars(string varName)
615
615
public Dictionary < string , LinkedList < Tuple < int , int > > > GetRuleSuppression ( Ast ast )
616
616
{
617
617
List < RuleSuppression > ruleSuppressionList = new List < RuleSuppression > ( ) ;
618
+
619
+ // Get rule suppression from functions
618
620
IEnumerable < FunctionDefinitionAst > funcAsts = ast . FindAll ( item => item is FunctionDefinitionAst , true ) . Cast < FunctionDefinitionAst > ( ) ;
621
+
619
622
foreach ( var funcAst in funcAsts )
620
623
{
621
- ruleSuppressionList . AddRange ( GetSuppressionFunction ( funcAst ) ) ;
624
+ ruleSuppressionList . AddRange ( GetSuppressionsFunction ( funcAst ) ) ;
625
+ }
626
+
627
+ // Get rule suppression from classes
628
+ IEnumerable < TypeDefinitionAst > typeAsts = ast . FindAll ( item => item is TypeDefinitionAst , true ) . Cast < TypeDefinitionAst > ( ) ;
629
+
630
+ foreach ( var typeAst in typeAsts )
631
+ {
632
+ ruleSuppressionList . AddRange ( GetSuppressionsClass ( typeAst ) ) ;
622
633
}
623
634
624
635
Dictionary < string , LinkedList < Tuple < int , int > > > results = new Dictionary < string , LinkedList < Tuple < int , int > > > ( StringComparer . OrdinalIgnoreCase ) ;
@@ -664,24 +675,48 @@ public Dictionary<string, LinkedList<Tuple<int, int>>> GetRuleSuppression(Ast as
664
675
/// </summary>
665
676
/// <param name="funcAst"></param>
666
677
/// <returns></returns>
667
- internal List < RuleSuppression > GetSuppressionFunction ( FunctionDefinitionAst funcAst )
678
+ internal List < RuleSuppression > GetSuppressionsFunction ( FunctionDefinitionAst funcAst )
668
679
{
669
680
List < RuleSuppression > result = new List < RuleSuppression > ( ) ;
670
681
671
682
if ( funcAst != null && funcAst . Body != null
672
683
&& funcAst . Body . ParamBlock != null && funcAst . Body . ParamBlock . Attributes != null )
673
684
{
674
- IEnumerable < AttributeAst > suppressionAttribute = funcAst . Body . ParamBlock . Attributes . Where (
675
- item => item . TypeName . GetReflectionType ( ) == typeof ( System . Diagnostics . CodeAnalysis . SuppressMessageAttribute ) ) ;
685
+ result . AddRange ( RuleSuppression . GetSuppressions ( funcAst . Body . ParamBlock . Attributes , funcAst . Extent . StartOffset , funcAst . Extent . EndOffset ) ) ;
686
+ }
687
+
688
+ return result ;
689
+ }
690
+
691
+ /// <summary>
692
+ /// Returns a list of rule suppression from the class
693
+ /// </summary>
694
+ /// <param name="typeAst"></param>
695
+ /// <returns></returns>
696
+ internal List < RuleSuppression > GetSuppressionsClass ( TypeDefinitionAst typeAst )
697
+ {
698
+ List < RuleSuppression > result = new List < RuleSuppression > ( ) ;
699
+
700
+ if ( typeAst != null && typeAst . Attributes != null && typeAst . Attributes . Count != 0 )
701
+ {
702
+ result . AddRange ( RuleSuppression . GetSuppressions ( typeAst . Attributes , typeAst . Extent . StartOffset , typeAst . Extent . EndOffset ) ) ;
703
+ }
676
704
677
- foreach ( var attributeAst in suppressionAttribute )
705
+ if ( typeAst . Members == null )
706
+ {
707
+ return result ;
708
+ }
709
+
710
+ foreach ( var member in typeAst . Members )
711
+ {
712
+ FunctionMemberAst funcMemb = member as FunctionMemberAst ;
713
+
714
+ if ( funcMemb == null )
678
715
{
679
- RuleSuppression ruleSupp = new RuleSuppression ( attributeAst , funcAst . Extent . StartOffset , funcAst . Extent . EndOffset ) ;
680
- if ( String . IsNullOrWhiteSpace ( ruleSupp . Error ) )
681
- {
682
- result . Add ( ruleSupp ) ;
683
- }
716
+ continue ;
684
717
}
718
+
719
+ result . AddRange ( RuleSuppression . GetSuppressions ( funcMemb . Attributes , funcMemb . Extent . StartOffset , funcMemb . Extent . EndOffset ) ) ;
685
720
}
686
721
687
722
return result ;
@@ -844,6 +879,16 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
844
879
return null ;
845
880
}
846
881
882
+ /// <summary>
883
+ /// Do nothing
884
+ /// </summary>
885
+ /// <param name="baseCtorInvokeMemberExpressionAst"></param>
886
+ /// <returns></returns>
887
+ public object VisitBaseCtorInvokeMemberExpression ( BaseCtorInvokeMemberExpressionAst baseCtorInvokeMemberExpressionAst )
888
+ {
889
+ return null ;
890
+ }
891
+
847
892
/// <summary>
848
893
/// Do nothing
849
894
/// </summary>
0 commit comments