C#: make C# static methods accessible.

This commit is contained in:
Zae 2023-09-20 22:49:33 +08:00
parent 5f1e56ff26
commit 67e1373e5a
7 changed files with 104 additions and 4 deletions

View file

@ -125,7 +125,7 @@ namespace Godot.SourceGenerators
var members = symbol.GetMembers();
var methodSymbols = members
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Method && !s.IsImplicitlyDeclared)
.Where(s => s.Kind == SymbolKind.Method && !s.IsImplicitlyDeclared)
.Cast<IMethodSymbol>()
.Where(m => m.MethodKind == MethodKind.Ordinary);
@ -221,6 +221,29 @@ namespace Godot.SourceGenerators
source.Append(" }\n");
}
// Generate InvokeGodotClassStaticMethod
var godotClassStaticMethods = godotClassMethods.Where(m => m.Method.IsStatic).ToArray();
if (godotClassStaticMethods.Length > 0)
{
source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(" internal new static bool InvokeGodotClassStaticMethod(in godot_string_name method, ");
source.Append("NativeVariantPtrArgs args, out godot_variant ret)\n {\n");
foreach (var method in godotClassStaticMethods)
{
GenerateMethodInvoker(method, source);
}
source.Append(" ret = default;\n");
source.Append(" return false;\n");
source.Append(" }\n");
source.Append("#pragma warning restore CS0109\n");
}
// Generate HasGodotClassMethod
if (distinctMethodNames.Length > 0)
@ -356,7 +379,14 @@ namespace Godot.SourceGenerators
arguments = null;
}
return new MethodInfo(method.Method.Name, returnVal, MethodFlags.Default, arguments,
MethodFlags flags = MethodFlags.Default;
if (method.Method.IsStatic)
{
flags |= MethodFlags.Static;
}
return new MethodInfo(method.Method.Name, returnVal, flags, arguments,
defaultArguments: null);
}