@@ -218,7 +218,8 @@ public static void GenerateTypeDefinitions(
218218 IDictionary < ModuleType , string > modulePaths ,
219219 string ? targetFramework = null ,
220220 bool isSystemAssembly = false ,
221- bool suppressWarnings = false )
221+ bool suppressWarnings = false ,
222+ IEnumerable < string > ? excludePatterns = null )
222223 {
223224 if ( string . IsNullOrEmpty ( assemblyPath ) )
224225 {
@@ -282,6 +283,7 @@ public static void GenerateTypeDefinitions(
282283 SuppressWarnings = suppressWarnings ,
283284 ExportAll = assemblyExportAttribute != null &&
284285 GetExportAttributeValue ( assemblyExportAttribute ) ,
286+ ExcludePatterns = excludePatterns ? . ToList ( ) ?? new List < string > ( ) ,
285287 } ;
286288
287289 generator . LoadAssemblyDocs ( ) ;
@@ -380,6 +382,8 @@ public TypeDefinitionsGenerator(
380382
381383 public bool SuppressWarnings { get ; set ; }
382384
385+ public List < string > ExcludePatterns { get ; set ; } = new ( ) ;
386+
383387 public override void ReportDiagnostic ( Diagnostic diagnostic )
384388 {
385389 if ( SuppressWarnings && diagnostic . Severity == DiagnosticSeverity . Warning )
@@ -1260,8 +1264,23 @@ private void EndNamespace(ref SourceBuilder s, Type type)
12601264 }
12611265 }
12621266
1263- private static bool IsExcluded ( MemberInfo member )
1267+ private bool IsExcluded ( MemberInfo member )
12641268 {
1269+ Type type = member as Type ?? member . DeclaringType ! ;
1270+
1271+ // Check user-provided exclude patterns first
1272+ if ( ExcludePatterns . Count > 0 )
1273+ {
1274+ string typeFullName = type . FullName ?? type . Name ;
1275+ foreach ( string pattern in ExcludePatterns )
1276+ {
1277+ if ( IsWildcardMatch ( typeFullName , pattern ) )
1278+ {
1279+ return true ;
1280+ }
1281+ }
1282+ }
1283+
12651284 if ( member is PropertyInfo property )
12661285 {
12671286 return IsExcluded ( property ) ;
@@ -1271,8 +1290,6 @@ private static bool IsExcluded(MemberInfo member)
12711290 return IsExcluded ( method ) ;
12721291 }
12731292
1274- Type type = member as Type ?? member . DeclaringType ! ;
1275-
12761293 if ( type . BaseType != null && IsExcluded ( type . BaseType ) )
12771294 {
12781295 return true ;
@@ -1301,14 +1318,41 @@ private static bool IsExcluded(MemberInfo member)
13011318 } ;
13021319 }
13031320
1304- private static bool IsExcluded ( PropertyInfo property )
1321+ /// <summary>
1322+ /// Checks if a string matches a wildcard pattern. Supports * (any characters) and ? (single character).
1323+ /// </summary>
1324+ private static bool IsWildcardMatch ( string input , string pattern )
13051325 {
1306- if ( property . PropertyType . IsPointer )
1326+ if ( string . IsNullOrEmpty ( pattern ) ) return false ;
1327+ if ( string . IsNullOrEmpty ( input ) ) return false ;
1328+
1329+ // Convert wildcard pattern to regex pattern
1330+ string regexPattern = "^" + Regex . Escape ( pattern )
1331+ . Replace ( @"\*" , ".*" )
1332+ . Replace ( @"\?" , "." ) + "$" ;
1333+
1334+ return Regex . IsMatch ( input , regexPattern , RegexOptions . IgnoreCase ) ;
1335+ }
1336+
1337+ private bool IsExcluded ( PropertyInfo property )
1338+ {
1339+ Type propertyType ;
1340+ try
1341+ {
1342+ propertyType = property . PropertyType ;
1343+ }
1344+ catch ( System . NotSupportedException e )
1345+ {
1346+ Console . WriteLine ( $ "Error: Property { property . DeclaringType ! . FullName } .{ property . Name } could not be analyzed. ({ e . GetType ( ) . Name } )") ;
1347+ throw ;
1348+ }
1349+
1350+ if ( propertyType . IsPointer )
13071351 {
13081352 return true ;
13091353 }
13101354
1311- if ( IsExcluded ( property . PropertyType ) )
1355+ if ( IsExcluded ( propertyType ) )
13121356 {
13131357 return true ;
13141358 }
@@ -1324,11 +1368,22 @@ private bool IsExcluded(MethodBase method)
13241368 return true ;
13251369 }
13261370
1371+ System . Reflection . ParameterInfo [ ] methodParams ;
1372+ try
1373+ {
1374+ methodParams = method . GetParameters ( ) ;
1375+ }
1376+ catch ( System . NotSupportedException e )
1377+ {
1378+ Console . WriteLine ( $ "Error: Method { method . DeclaringType ! . FullName } .{ method . Name } () could not be analyzed. ({ e . GetType ( ) . Name } )") ;
1379+ throw ;
1380+ }
1381+
13271382 // Exclude old style Begin/End async methods, as they always have Task-based alternatives.
13281383 if ( ( method . Name . StartsWith ( "Begin" ) &&
13291384 ( method as MethodInfo ) ? . ReturnType . FullName == typeof ( IAsyncResult ) . FullName ) ||
1330- ( method . Name . StartsWith ( "End" ) && method . GetParameters ( ) . Length == 1 &&
1331- method . GetParameters ( ) [ 0 ] . ParameterType . FullName == typeof ( IAsyncResult ) . FullName ) )
1385+ ( method . Name . StartsWith ( "End" ) && methodParams . Length == 1 &&
1386+ methodParams [ 0 ] . ParameterType . FullName == typeof ( IAsyncResult ) . FullName ) )
13321387 {
13331388 return true ;
13341389 }
0 commit comments