Skip to content

Commit

Permalink
Fix CoreLib type references in typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin committed Sep 25, 2023
1 parent ea83f9a commit 6b34d01
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/NodeApi.Generator/TypeDefinitionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6b34d01

Please sign in to comment.