Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access specifier to method class #378

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 _);
Expand Down