@@ -75,41 +75,37 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
75
75
{
76
76
String resourceName = null ;
77
77
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 )
81
84
{
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 ) )
84
93
{
85
- if ( attribute . TypeName . FullName . Equals ( "DscResource" ) )
94
+ DirectoryInfo examplesFolder = new DirectoryInfo ( expectedExamplesPath ) ;
95
+ FileInfo [ ] exampleFiles = examplesFolder . GetFiles ( examplesQuery ) ;
96
+ if ( exampleFiles . Length != 0 )
86
97
{
87
- resourceName = typeDefinitionAst . Name ;
98
+ examplesPresent = true ;
88
99
}
89
100
}
90
- }
91
-
92
- String examplesQuery = "*" + resourceName + "*" ;
93
- Boolean examplesPresent = false ;
94
- String expectedExamplesPath = fileName + "\\ ..\\ Examples" ;
95
101
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 )
102
104
{
103
- examplesPresent = true ;
105
+ yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . DscExamplesPresentNoExamplesError , resourceName ) ,
106
+ null , GetName ( ) , DiagnosticSeverity . Information , fileName ) ;
104
107
}
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
+ }
113
109
}
114
110
115
111
/// <summary>
0 commit comments