summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-27 13:53:11 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-27 13:53:11 +0200
commit543fa16b4ce821a0118da3ef0904a105aaa046e9 (patch)
treead25bcdfee152e36803555033370accbd0793a84 /modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
parent506d6e427a4eecfc1e5e5ee1180019a876119701 (diff)
parentda37998dc84dcf05c91fdfe7481445c0cb10af2e (diff)
downloadredot-engine-543fa16b4ce821a0118da3ef0904a105aaa046e9.tar.gz
Merge pull request #68233 from raulsntos/dotnet/raise-events
C#: Generate strongly-typed method to raise signal events and fix event accessibility
Diffstat (limited to 'modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
index 957d5789df..62fa7b0a36 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
@@ -155,6 +155,32 @@ namespace Godot.SourceGenerators
};
}
+ public static string GetAccessibilityKeyword(this INamedTypeSymbol namedTypeSymbol)
+ {
+ if (namedTypeSymbol.DeclaredAccessibility == Accessibility.NotApplicable)
+ {
+ // Accessibility not specified. Get the default accessibility.
+ return namedTypeSymbol.ContainingSymbol switch
+ {
+ null or INamespaceSymbol => "internal",
+ ITypeSymbol { TypeKind: TypeKind.Class or TypeKind.Struct } => "private",
+ ITypeSymbol { TypeKind: TypeKind.Interface } => "public",
+ _ => "",
+ };
+ }
+
+ return namedTypeSymbol.DeclaredAccessibility switch
+ {
+ Accessibility.Private => "private",
+ Accessibility.Protected => "protected",
+ Accessibility.Internal => "internal",
+ Accessibility.ProtectedAndInternal => "private",
+ Accessibility.ProtectedOrInternal => "private",
+ Accessibility.Public => "public",
+ _ => "",
+ };
+ }
+
public static string NameWithTypeParameters(this INamedTypeSymbol symbol)
{
return symbol.IsGenericType ?