From 6f2553b1711097e65624b0029ef6cef822a855b0 Mon Sep 17 00:00:00 2001 From: Yanjiang Qian Date: Wed, 2 Jul 2025 20:10:51 +0800 Subject: [PATCH] Fix namespace for Unsafe not import issue --- .../ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs | 1 + .../CSharpLatestUnix/StructDeclarationTest.cs | 1 + .../CSharpLatestWindows/StructDeclarationTest.cs | 1 + .../CSharpPreviewUnix/StructDeclarationTest.cs | 1 + .../CSharpPreviewWindows/StructDeclarationTest.cs | 1 + 5 files changed, 5 insertions(+) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 5a21f8d5..1a874965 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -3121,6 +3121,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co if (arraySize == 1) { + code.AddUsingDirective("System.Runtime.CompilerServices"); code.Write("Unsafe.Add(ref e0, index)"); } else diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs index caccbc5e..cc69a079 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs index 5ce7bebe..af091c6d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs index 854c5546..2c3cf62b 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs index 5bf9a1e2..ecd7a0ef 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs @@ -21,6 +21,7 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test