@@ -75,41 +75,37 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
7575 {
7676 String resourceName = null ;
7777
78- // Obtain class based resource name
79- IEnumerable < Ast > typeDefinitionAsts = ( ast . FindAll ( dscAst => dscAst is TypeDefinitionAst , true ) ) ;
80- foreach ( TypeDefinitionAst typeDefinitionAst in typeDefinitionAsts )
78+ IEnumerable < Ast > dscClasses = ast . FindAll ( item =>
79+ item is TypeDefinitionAst
80+ && ( ( item as TypeDefinitionAst ) . IsClass )
81+ && ( item as TypeDefinitionAst ) . Attributes . Any ( attr => String . Equals ( "DSCResource" , attr . TypeName . FullName , StringComparison . OrdinalIgnoreCase ) ) , true ) ;
82+
83+ foreach ( TypeDefinitionAst dscClass in dscClasses )
8184 {
82- var attributes = typeDefinitionAst . Attributes ;
83- foreach ( var attribute in attributes )
85+ resourceName = dscClass . Name ;
86+
87+ String examplesQuery = "*" + resourceName + "*" ;
88+ Boolean examplesPresent = false ;
89+ String expectedExamplesPath = fileName + "\\ ..\\ Examples" ;
90+
91+ // Verify examples are present
92+ if ( Directory . Exists ( expectedExamplesPath ) )
8493 {
85- if ( attribute . TypeName . FullName . Equals ( "DscResource" ) )
94+ DirectoryInfo examplesFolder = new DirectoryInfo ( expectedExamplesPath ) ;
95+ FileInfo [ ] exampleFiles = examplesFolder . GetFiles ( examplesQuery ) ;
96+ if ( exampleFiles . Length != 0 )
8697 {
87- resourceName = typeDefinitionAst . Name ;
98+ examplesPresent = true ;
8899 }
89100 }
90- }
91-
92- String examplesQuery = "*" + resourceName + "*" ;
93- Boolean examplesPresent = false ;
94- String expectedExamplesPath = fileName + "\\ ..\\ Examples" ;
95101
96- // Verify examples are present
97- if ( Directory . Exists ( expectedExamplesPath ) )
98- {
99- DirectoryInfo examplesFolder = new DirectoryInfo ( expectedExamplesPath ) ;
100- FileInfo [ ] exampleFiles = examplesFolder . GetFiles ( examplesQuery ) ;
101- if ( exampleFiles . Length != 0 )
102+ // Return error if no examples present
103+ if ( ! examplesPresent )
102104 {
103- examplesPresent = true ;
105+ yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . DscExamplesPresentNoExamplesError , resourceName ) ,
106+ null , GetName ( ) , DiagnosticSeverity . Information , fileName ) ;
104107 }
105- }
106-
107- // Return error if no examples present
108- if ( ! examplesPresent )
109- {
110- yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . DscExamplesPresentNoExamplesError , resourceName ) ,
111- null , GetName ( ) , DiagnosticSeverity . Information , fileName ) ;
112- }
108+ }
113109 }
114110
115111 /// <summary>
0 commit comments