From 04ee9628ebf1354ef4ba320bd2c91eb1f6b0e022 Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Mon, 22 Aug 2022 15:46:54 -0700 Subject: [PATCH] add access specifier to method class --- .../PInvokeGenerator.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 28b9dbdf..d2fae91d 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -1555,7 +1555,8 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) } sw.Write(indentationString); - sw.Write("public "); + sw.Write(GetMethodClassAccessSpecifier(outputBuilder.Name).AsString()); + sw.Write(' '); if (outputBuilder.IsTestOutput || !isTopLevelStruct) { @@ -1865,6 +1866,23 @@ private AccessSpecifier GetAccessSpecifier(NamedDecl namedDecl, bool matchStar) return accessSpecifier; } + private AccessSpecifier GetMethodClassAccessSpecifier(string name) + { + var accessMap = _config.WithAccessSpecifiers; + + if (accessMap.TryGetValue(name, out var accessSpecifier)) + { + return accessSpecifier; + } + + if (accessMap.TryGetValue("*", out accessSpecifier)) + { + return accessSpecifier; + } + + return AccessSpecifier.None; + } + private static string GetAnonymousName(Cursor cursor, string kind) { cursor.Location.GetFileLocation(out var file, out var line, out var column, out _);