diff --git a/src/NodeApi.Generator/TypeDefinitionsGenerator.cs b/src/NodeApi.Generator/TypeDefinitionsGenerator.cs index f64fa8d3..90aec5fb 100644 --- a/src/NodeApi.Generator/TypeDefinitionsGenerator.cs +++ b/src/NodeApi.Generator/TypeDefinitionsGenerator.cs @@ -320,7 +320,11 @@ public SourceText GenerateTypeDefinitions(bool? autoCamelCase = null) private bool IsTypeExported(Type type) { - if (type.Assembly != _assembly) + // Types not in the current assembly are not exported from this TS module. + // (But support mscorlib and System.Runtime forwarding to System.Private.CoreLib.) + if (type.Assembly != _assembly && + !(type.Assembly.GetName().Name == "System.Private.CoreLib" && + (_assembly.GetName().Name == "mscorlib" || _assembly.GetName().Name == "System.Runtime"))) { return false; } @@ -689,7 +693,8 @@ private static bool HasExplicitInterfaceImplementations(Type type, Type interfac if ((interfaceType.Name == nameof(IComparable) && type.IsInterface && type.GetInterfaces().Any((i) => i.Name == typeof(IComparable<>).Name)) || (interfaceType.Name == "ISpanFormattable" && type.IsInterface && - type.GetInterfaces().Any((i) => i.Name == "INumberBase`1"))) + (type.Name == "INumberBase`1" || + type.GetInterfaces().Any((i) => i.Name == "INumberBase`1")))) { // TS interfaces cannot extend multiple interfaces that have non-identical methods // with the same name. This is most commonly an issue with IComparable and @@ -891,11 +896,13 @@ private static bool IsExcludedMethod(MethodInfo method) { // Exclude "special" methods like property get/set and event add/remove. // Exclude old style Begin/End async methods, as they always have Task-based alternatives. + // Exclude instance methods declared by System.Object like ToString() and Equals(). return method.IsSpecialName || (method.Name.StartsWith("Begin") && method.ReturnType.FullName == typeof(IAsyncResult).FullName) || (method.Name.StartsWith("End") && method.GetParameters().Length == 1 && - method.GetParameters()[0].ParameterType.FullName == typeof(IAsyncResult).FullName); + method.GetParameters()[0].ParameterType.FullName == typeof(IAsyncResult).FullName) || + (!method.IsStatic && method.DeclaringType!.FullName == "System.Object"); } private void GenerateEnumDefinition(ref SourceBuilder s, Type type)