File tree Expand file tree Collapse file tree 1 file changed +13
-19
lines changed
src/Microsoft.OpenApi/Validations Expand file tree Collapse file tree 1 file changed +13
-19
lines changed Original file line number Diff line number Diff line change @@ -118,29 +118,23 @@ IEnumerator IEnumerable.GetEnumerator()
118
118
private static ValidationRuleSet BuildDefaultRuleSet ( )
119
119
{
120
120
ValidationRuleSet ruleSet = new ValidationRuleSet ( ) ;
121
-
122
- IEnumerable < Type > allTypes = typeof ( ValidationRuleSet ) . Assembly . GetTypes ( ) . Where ( t => t . IsClass && t != typeof ( object ) ) ;
123
121
Type validationRuleType = typeof ( ValidationRule ) ;
124
- foreach ( Type type in allTypes )
125
- {
126
- if ( ! type . GetCustomAttributes ( typeof ( OpenApiRuleAttribute ) , false ) . Any ( ) )
127
- {
128
- continue ;
129
- }
130
122
131
- var properties = type . GetProperties ( BindingFlags . Static | BindingFlags . Public ) ;
132
- foreach ( var property in properties )
133
- {
134
- if ( validationRuleType . IsAssignableFrom ( property . PropertyType ) )
123
+ IEnumerable < PropertyInfo > rules = typeof ( ValidationRuleSet ) . Assembly . GetTypes ( )
124
+ . Where ( t => t . IsClass
125
+ && t != typeof ( object )
126
+ && t . GetCustomAttributes ( typeof ( OpenApiRuleAttribute ) , false ) . Any ( ) )
127
+ . SelectMany ( t2 => t2 . GetProperties ( BindingFlags . Static | BindingFlags . Public )
128
+ . Where ( p => validationRuleType . IsAssignableFrom ( p . PropertyType ) ) ) ;
129
+
130
+ foreach ( var property in rules )
131
+ {
132
+ var propertyValue = property . GetValue ( null ) ; // static property
133
+ ValidationRule rule = propertyValue as ValidationRule ;
134
+ if ( rule != null )
135
135
{
136
- var propertyValue = property . GetValue ( null ) ; // static property
137
- ValidationRule rule = propertyValue as ValidationRule ;
138
- if ( rule != null )
139
- {
140
- ruleSet . Add ( rule ) ;
141
- }
136
+ ruleSet . Add ( rule ) ;
142
137
}
143
- }
144
138
}
145
139
146
140
return ruleSet ;
You can’t perform that action at this time.
0 commit comments