@@ -216,6 +216,30 @@ internal bool ParseProfile(object profileObject, PathIntrinsics path, IOutputWri
216
216
return true ;
217
217
}
218
218
219
+ private bool TryAddingProfileItem (
220
+ string key ,
221
+ List < string > values ,
222
+ List < string > severityList ,
223
+ List < string > includeRuleList ,
224
+ List < string > excludeRuleList )
225
+ {
226
+ switch ( key . ToLower ( ) )
227
+ {
228
+ case "severity" :
229
+ severityList . AddRange ( values ) ;
230
+ break ;
231
+ case "includerules" :
232
+ includeRuleList . AddRange ( values ) ;
233
+ break ;
234
+ case "excluderules" :
235
+ excludeRuleList . AddRange ( values ) ;
236
+ break ;
237
+ default :
238
+ return false ;
239
+ }
240
+ return true ;
241
+ }
242
+
219
243
private bool ParseProfileHashtable ( Hashtable profile , PathIntrinsics path , IOutputWriter writer ,
220
244
List < string > severityList , List < string > includeRuleList , List < string > excludeRuleList )
221
245
{
@@ -238,7 +262,7 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp
238
262
hasError = true ;
239
263
continue ;
240
264
}
241
-
265
+
242
266
// checks whether it falls into list of valid keys
243
267
if ( ! validKeys . Contains ( key ) )
244
268
{
@@ -293,21 +317,8 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp
293
317
}
294
318
}
295
319
296
- // now add to the list
297
- switch ( key )
298
- {
299
- case "severity" :
300
- severityList . AddRange ( values ) ;
301
- break ;
302
- case "includerules" :
303
- includeRuleList . AddRange ( values ) ;
304
- break ;
305
- case "excluderules" :
306
- excludeRuleList . AddRange ( values ) ;
307
- break ;
308
- default :
309
- break ;
310
- }
320
+ TryAddingProfileItem ( key , values , severityList , includeRuleList , excludeRuleList ) ;
321
+
311
322
}
312
323
313
324
return hasError ;
@@ -426,23 +437,12 @@ private bool ParseProfileString(string profile, PathIntrinsics path, IOutputWrit
426
437
427
438
string key = ( kvp . Item1 as StringConstantExpressionAst ) . Value . ToLower ( ) ;
428
439
429
- switch ( key )
440
+ if ( ! TryAddingProfileItem ( key , rhsList , severityList , includeRuleList , excludeRuleList ) )
430
441
{
431
- case "severity" :
432
- severityList . AddRange ( rhsList ) ;
433
- break ;
434
- case "includerules" :
435
- includeRuleList . AddRange ( rhsList ) ;
436
- break ;
437
- case "excluderules" :
438
- excludeRuleList . AddRange ( rhsList ) ;
439
- break ;
440
- default :
441
- writer . WriteError ( new ErrorRecord (
442
+ writer . WriteError ( new ErrorRecord (
442
443
new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongKey , key , kvp . Item1 . Extent . StartLineNumber , kvp . Item1 . Extent . StartColumnNumber , profile ) ) ,
443
444
Strings . WrongConfigurationKey , ErrorCategory . InvalidData , profile ) ) ;
444
- hasError = true ;
445
- break ;
445
+ hasError = true ;
446
446
}
447
447
}
448
448
}
0 commit comments