11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics ;
34using System . IO ;
45using System . Linq ;
56using System . Reflection ;
@@ -111,23 +112,23 @@ public static bool IsValidFilterExpression(string filter)
111112 return true ;
112113 }
113114
114- public static bool IsModuleExcluded ( string module , string [ ] filters )
115+ public static bool IsModuleExcluded ( string module , string [ ] excludeFilters )
115116 {
116- if ( filters == null )
117+ if ( excludeFilters == null || excludeFilters . Length == 0 )
117118 return false ;
118119
119120 module = Path . GetFileNameWithoutExtension ( module ) ;
120121 if ( module == null )
121122 return false ;
122123
123- foreach ( var filter in filters )
124+ foreach ( var filter in excludeFilters )
124125 {
125- string modulePattern = filter . Substring ( 1 , filter . IndexOf ( ']' ) - 1 ) ;
126126 string typePattern = filter . Substring ( filter . IndexOf ( ']' ) + 1 ) ;
127127
128128 if ( typePattern != "*" )
129129 continue ;
130130
131+ string modulePattern = filter . Substring ( 1 , filter . IndexOf ( ']' ) - 1 ) ;
131132 modulePattern = WildcardToRegex ( modulePattern ) ;
132133
133134 var regex = new Regex ( modulePattern ) ;
@@ -139,30 +140,57 @@ public static bool IsModuleExcluded(string module, string[] filters)
139140 return false ;
140141 }
141142
142- public static bool IsTypeExcluded ( string module , string type , string [ ] filters )
143+ public static bool IsModuleIncluded ( string module , string [ ] includeFilters )
143144 {
144- if ( filters == null )
145- return false ;
145+ if ( includeFilters == null || includeFilters . Length == 0 )
146+ return true ;
146147
147148 module = Path . GetFileNameWithoutExtension ( module ) ;
148149 if ( module == null )
149150 return false ;
150151
151- foreach ( var filter in filters )
152+ foreach ( var filter in includeFilters )
152153 {
153- string typePattern = filter . Substring ( filter . IndexOf ( ']' ) + 1 ) ;
154154 string modulePattern = filter . Substring ( 1 , filter . IndexOf ( ']' ) - 1 ) ;
155155
156- typePattern = WildcardToRegex ( typePattern ) ;
156+ if ( modulePattern == "*" )
157+ return true ;
158+
157159 modulePattern = WildcardToRegex ( modulePattern ) ;
158160
159- if ( new Regex ( typePattern ) . IsMatch ( type ) && new Regex ( modulePattern ) . IsMatch ( module ) )
161+ var regex = new Regex ( modulePattern ) ;
162+
163+ if ( regex . IsMatch ( module ) )
160164 return true ;
161165 }
162166
163167 return false ;
164168 }
165169
170+ public static bool IsTypeExcluded ( string module , string type , string [ ] excludeFilters )
171+ {
172+ if ( excludeFilters == null || excludeFilters . Length == 0 )
173+ return false ;
174+
175+ module = Path . GetFileNameWithoutExtension ( module ) ;
176+ if ( module == null )
177+ return false ;
178+
179+ return IsTypeFilterMatch ( module , type , excludeFilters ) ;
180+ }
181+
182+ public static bool IsTypeIncluded ( string module , string type , string [ ] includeFilters )
183+ {
184+ if ( includeFilters == null || includeFilters . Length == 0 )
185+ return true ;
186+
187+ module = Path . GetFileNameWithoutExtension ( module ) ;
188+ if ( module == null )
189+ return true ;
190+
191+ return IsTypeFilterMatch ( module , type , includeFilters ) ;
192+ }
193+
166194 public static bool IsLocalMethod ( string method )
167195 => new Regex ( WildcardToRegex ( "<*>*__*|*" ) ) . IsMatch ( method ) ;
168196
@@ -206,6 +234,26 @@ public static string[] GetExcludedFiles(string[] excludes)
206234 return files . Distinct ( ) . ToArray ( ) ;
207235 }
208236
237+ private static bool IsTypeFilterMatch ( string module , string type , string [ ] filters )
238+ {
239+ Debug . Assert ( module != null ) ;
240+ Debug . Assert ( filters != null ) ;
241+
242+ foreach ( var filter in filters )
243+ {
244+ string typePattern = filter . Substring ( filter . IndexOf ( ']' ) + 1 ) ;
245+ string modulePattern = filter . Substring ( 1 , filter . IndexOf ( ']' ) - 1 ) ;
246+
247+ typePattern = WildcardToRegex ( typePattern ) ;
248+ modulePattern = WildcardToRegex ( modulePattern ) ;
249+
250+ if ( new Regex ( typePattern ) . IsMatch ( type ) && new Regex ( modulePattern ) . IsMatch ( module ) )
251+ return true ;
252+ }
253+
254+ return false ;
255+ }
256+
209257 private static string GetBackupPath ( string module , string identifier )
210258 {
211259 return Path . Combine (
0 commit comments