diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index a95f8489..9fffa6d3 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -1300,6 +1300,11 @@ private void VisitRecordDecl(RecordDecl recordDecl) { _topLevelClassUsings[name] = withUsings; } + + if (desc.IsUnsafe) + { + _isTopLevelClassUnsafe[name] = true; + } } if (hasVtbl) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 759b0a40..c9498b41 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -4991,7 +4991,9 @@ void CreateTestOutputBuilder(string name) { _testOutputBuilder = _outputBuilderFactory.CreateTests(name); - if (!_topLevelClassNames.Contains(name)) + var isTopLevelStruct = _config.WithTypes.TryGetValue(name, out var withType) && (withType == "struct"); + + if (!_topLevelClassNames.Contains(name) || isTopLevelStruct) { _testOutputBuilder.AddUsingDirective("System.Runtime.InteropServices"); }