From 772064b5ece8c7cbf3e4f3e48c6705c3cb5d547f Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Wed, 4 Sep 2024 07:09:32 -1000 Subject: [PATCH] Fix generator bug with non-public nested types (#374) --- src/NodeApi.Generator/ModuleGenerator.cs | 3 ++- test/TestCases/napi-dotnet/ComplexTypes.cs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NodeApi.Generator/ModuleGenerator.cs b/src/NodeApi.Generator/ModuleGenerator.cs index feb254b2..1aeb96fb 100644 --- a/src/NodeApi.Generator/ModuleGenerator.cs +++ b/src/NodeApi.Generator/ModuleGenerator.cs @@ -475,7 +475,8 @@ private void ExportType( $"{nameof(JSPropertyAttributes)}.{nameof(JSPropertyAttributes.Enumerable)}"; // Declare nested types first, so they can be exported as static properties of this type. - foreach (INamedTypeSymbol nestedType in type.GetTypeMembers()) + foreach (INamedTypeSymbol nestedType in type.GetTypeMembers() + .Where((t) => t.DeclaredAccessibility == Accessibility.Public)) { ExportType(ref s, nestedType, GetExportName(nestedType)); } diff --git a/test/TestCases/napi-dotnet/ComplexTypes.cs b/test/TestCases/napi-dotnet/ComplexTypes.cs index 525e8a0b..324eaa14 100644 --- a/test/TestCases/napi-dotnet/ComplexTypes.cs +++ b/test/TestCases/napi-dotnet/ComplexTypes.cs @@ -199,6 +199,11 @@ public NestedClass(string value) public string Value { get; set; } } + + // Non-public nested types should not be exported. + internal class PrivateNestedClass + { + } } [JSExport]