@@ -377,6 +377,11 @@ public SourceText GenerateTypeDefinitions(bool? autoCamelCase = null)
377377
378378 private bool IsTypeExported ( Type type )
379379 {
380+ if ( IsExcludedNamespace ( type . Namespace ) )
381+ {
382+ return false ;
383+ }
384+
380385 // Types not in the current assembly are not exported from this TS module.
381386 // (But support mscorlib and System.Runtime forwarding to System.Private.CoreLib.)
382387 if ( type . Assembly != _assembly &&
@@ -626,7 +631,8 @@ private void GenerateClassDefinition(ref SourceBuilder s, Type type)
626631 foreach ( PropertyInfo property in type . GetProperties (
627632 BindingFlags . Public | BindingFlags . Static ) )
628633 {
629- if ( ! IsExcludedMember ( property ) )
634+ // Indexed properties are not implemented.
635+ if ( ! IsExcludedMember ( property ) && property . GetIndexParameters ( ) . Length == 0 )
630636 {
631637 if ( isFirstMember ) isFirstMember = false ; else s ++ ;
632638 ExportTypeMember ( ref s , property ) ;
@@ -665,7 +671,11 @@ private void GenerateClassDefinition(ref SourceBuilder s, Type type)
665671 string prefix = ( implements . Length == 0 ? $ " { implementsKind } " : "," ) +
666672 ( interfaceTypes . Length > 1 ? "\n \t " : " " ) ;
667673
668- if ( isStreamSubclass &&
674+ if ( ! interfaceType . IsPublic || IsExcludedNamespace ( interfaceType . Namespace ) )
675+ {
676+ continue ;
677+ }
678+ else if ( isStreamSubclass &&
669679 ( interfaceType . Name == nameof ( IDisposable ) ||
670680 interfaceType . Name == nameof ( IAsyncDisposable ) ) )
671681 {
@@ -725,7 +735,8 @@ private void GenerateClassDefinition(ref SourceBuilder s, Type type)
725735 ( isStaticClass ? BindingFlags . DeclaredOnly : default ) |
726736 ( type . IsInterface || isGenericTypeDefinition ? default : BindingFlags . Static ) ) )
727737 {
728- if ( ! IsExcludedMember ( property ) )
738+ // Indexed properties are not implemented.
739+ if ( ! IsExcludedMember ( property ) && property . GetIndexParameters ( ) . Length == 0 )
729740 {
730741 if ( isFirstMember ) isFirstMember = false ; else s ++ ;
731742 ExportTypeMember ( ref s , property ) ;
@@ -763,7 +774,9 @@ private static bool HasExplicitInterfaceImplementations(Type type, Type interfac
763774 type . GetInterfaces ( ) . Any ( ( i ) => i . Name == typeof ( IComparable < > ) . Name ) ) ||
764775 ( interfaceType . Name == "ISpanFormattable" &&
765776 ( type . Name == "INumberBase`1" ||
766- type . GetInterfaces ( ) . Any ( ( i ) => i . Name == "INumberBase`1" ) ) ) )
777+ type . GetInterfaces ( ) . Any ( ( i ) => i . Name == "INumberBase`1" ) ) ) ||
778+ ( interfaceType . Name == "ICollection" &&
779+ type . Name == "IProducerConsumerCollection`1" ) )
767780 {
768781 // TS interfaces cannot extend multiple interfaces that have non-identical methods
769782 // with the same name. This is most commonly an issue with IComparable and
@@ -773,10 +786,10 @@ private static bool HasExplicitInterfaceImplementations(Type type, Type interfac
773786
774787 return false ;
775788 }
776- else if ( type . Name == "TypeDelegator" && interfaceType . Name == "IReflectableType" )
789+ else if ( interfaceType . Name == "IReflectableType" )
777790 {
778- // Special case: TypeDelegator has an explicit implementation of this interface,
779- // but it isn 't detected by reflection due to the runtime type delegation.
791+ // Special case: Reflectable types have explicit implementations of this interface,
792+ // but they aren 't detected by reflection due to the runtime type delegation.
780793 return true ;
781794 }
782795
@@ -823,6 +836,11 @@ private static bool HasExplicitInterfaceImplementations(Type type, Type interfac
823836 }
824837 }
825838
839+ if ( type . BaseType != null && type . BaseType != typeof ( object ) )
840+ {
841+ return HasExplicitInterfaceImplementations ( type . BaseType ! , interfaceType ) ;
842+ }
843+
826844 return false ;
827845 }
828846
@@ -968,6 +986,21 @@ private void EndNamespace(ref SourceBuilder s, Type type)
968986 }
969987 }
970988
989+ private static bool IsExcludedNamespace ( string ? ns )
990+ {
991+ // These namespaces contain APIs that are problematic for TS generation.
992+ // (Mostly old .NET Framework APIs.)
993+ return ns switch
994+ {
995+ "System.Runtime.InteropServices" or
996+ "System.Runtime.Remoting.Messaging" or
997+ "System.Runtime.Serialization" or
998+ "System.Security.AccessControl" or
999+ "System.Security.Policy" => true ,
1000+ _ => false ,
1001+ } ;
1002+ }
1003+
9711004 private static bool IsExcludedMember ( PropertyInfo property )
9721005 {
9731006 if ( property . PropertyType . IsPointer )
0 commit comments