@@ -360,38 +360,56 @@ private string GetModuleKeysForIncludeFilters(IEnumerable<string> filters, char
360360 {
361361 string [ ] validFilters = GetValidFilters ( filters ) ;
362362
363- return ! validFilters . Any ( ) ? moduleKeys : GetModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
363+ return ! validFilters . Any ( ) ? moduleKeys : GetIncludeModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
364364 }
365365
366366 private string GetModuleKeysForExcludeFilters ( IEnumerable < string > filters , char escapeSymbol , string moduleKeys )
367367 {
368368 string [ ] validFilters = GetValidFilters ( filters ) ;
369369
370- return ! validFilters . Any ( ) ? string . Empty : GetModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
370+ return ! validFilters . Any ( ) ? string . Empty : GetExcludeModuleKeysForValidFilters ( escapeSymbol , moduleKeys , validFilters ) ;
371371 }
372372
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 )
374382 {
375- string pattern = CreateRegexPattern ( validFilters , escapeSymbol ) ;
383+ string pattern = CreateRegexExcludePattern ( validFilters , escapeSymbol ) ;
376384 IEnumerable < Match > matches = Regex . Matches ( moduleKeys , pattern , RegexOptions . IgnoreCase ) . Cast < Match > ( ) ;
377385
378386 return string . Join (
379387 Environment . NewLine ,
380388 matches . Where ( x => x . Success ) . Select ( x => x . Groups [ 0 ] . Value ) ) ;
381389 }
382390
383- private string [ ] GetValidFilters ( IEnumerable < string > filters )
391+ private static string GetIncludeModuleKeysForValidFilters ( char escapeSymbol , string moduleKeys , string [ ] validFilters )
384392 {
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 ) ) ;
389399 }
390400
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 )
392409 {
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 } ") ;
395413 return string . Join ( "|" , regexPatterns ) ;
396414 }
397415
0 commit comments