@@ -360,38 +360,56 @@ private string GetModuleKeysForIncludeFilters(IEnumerable<string> filters, char
360
360
{
361
361
string [ ] validFilters = GetValidFilters ( filters ) ;
362
362
363
- return ! validFilters . Any ( ) ? moduleKeys : GetModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
363
+ return ! validFilters . Any ( ) ? moduleKeys : GetIncludeModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
364
364
}
365
365
366
366
private string GetModuleKeysForExcludeFilters ( IEnumerable < string > filters , char escapeSymbol , string moduleKeys )
367
367
{
368
368
string [ ] validFilters = GetValidFilters ( filters ) ;
369
369
370
- return ! validFilters . Any ( ) ? string . Empty : GetModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
370
+ return ! validFilters . Any ( ) ? string . Empty : GetExcludeModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
371
371
}
372
372
373
- private static string GetModuleKeysForValidFilters ( char escapeSymbol , string moduleKeys , string [ ] validFilters )
373
+ private string [ ] GetValidFilters ( IEnumerable < string > filters )
374
+ {
375
+ return ( filters ?? Array . Empty < string > ( ) )
376
+ . Where ( IsValidFilterExpression )
377
+ . Where ( x => x . EndsWith ( "*" ) )
378
+ . ToArray ( ) ;
379
+ }
380
+
381
+ private static string GetExcludeModuleKeysForValidFilters ( char escapeSymbol , string moduleKeys , string [ ] validFilters )
374
382
{
375
- string pattern = CreateRegexPattern ( validFilters , escapeSymbol ) ;
383
+ string pattern = CreateRegexExcludePattern ( validFilters , escapeSymbol ) ;
376
384
IEnumerable < Match > matches = Regex . Matches ( moduleKeys , pattern , RegexOptions . IgnoreCase ) . Cast < Match > ( ) ;
377
385
378
386
return string . Join (
379
387
Environment . NewLine ,
380
388
matches . Where ( x => x . Success ) . Select ( x => x . Groups [ 0 ] . Value ) ) ;
381
389
}
382
390
383
- private string [ ] GetValidFilters ( IEnumerable < string > filters )
391
+ private static string GetIncludeModuleKeysForValidFilters ( char escapeSymbol , string moduleKeys , string [ ] validFilters )
384
392
{
385
- return ( filters ?? Array . Empty < string > ( ) )
386
- . Where ( IsValidFilterExpression )
387
- . Where ( x => x . EndsWith ( "*" ) )
388
- . ToArray ( ) ;
393
+ string pattern = CreateRegexIncludePattern ( validFilters , escapeSymbol ) ;
394
+ IEnumerable < Match > matches = Regex . Matches ( moduleKeys , pattern , RegexOptions . IgnoreCase ) . Cast < Match > ( ) ;
395
+
396
+ return string . Join (
397
+ Environment . NewLine ,
398
+ matches . Where ( x => x . Success ) . Select ( x => x . Groups [ 0 ] . Value ) ) ;
389
399
}
390
400
391
- private static string CreateRegexPattern ( IEnumerable < string > filters , char escapeSymbol )
401
+ private static string CreateRegexExcludePattern ( IEnumerable < string > filters , char escapeSymbol )
402
+ //only look for module filters here, types will be filtered out when instrumenting
403
+ => CreateRegexPattern ( filters , escapeSymbol , filter => filter . Substring ( filter . IndexOf ( ']' ) + 1 ) == "*" ) ;
404
+
405
+ private static string CreateRegexIncludePattern ( IEnumerable < string > filters , char escapeSymbol ) =>
406
+ CreateRegexPattern ( filters , escapeSymbol ) ;
407
+
408
+ private static string CreateRegexPattern ( IEnumerable < string > filters , char escapeSymbol , Func < string , bool > filterPredicate = null )
392
409
{
393
- IEnumerable < string > regexPatterns = filters . Select ( x =>
394
- $ "{ escapeSymbol } { WildcardToRegex ( x . Substring ( 1 , x . IndexOf ( ']' ) - 1 ) ) . Trim ( '^' , '$' ) } { escapeSymbol } ") ;
410
+ IEnumerable < string > filteredFilters = filterPredicate != null ? filters . Where ( filterPredicate ) : filters ;
411
+ IEnumerable < string > regexPatterns = filteredFilters . Select ( x =>
412
+ $ "{ escapeSymbol } { WildcardToRegex ( x . Substring ( 1 , x . IndexOf ( ']' ) - 1 ) ) . Trim ( '^' , '$' ) } { escapeSymbol } ") ;
395
413
return string . Join ( "|" , regexPatterns ) ;
396
414
}
397
415
0 commit comments