Skip to content

[.NET] Allow forcing the enum suffix to avoid hiding members#120395

Open
raulsntos wants to merge 1 commit into
godotengine:masterfrom
raulsntos:dotnet/force-enum-suffix
Open

[.NET] Allow forcing the enum suffix to avoid hiding members#120395
raulsntos wants to merge 1 commit into
godotengine:masterfrom
raulsntos:dotnet/force-enum-suffix

Conversation

@raulsntos

Copy link
Copy Markdown
Member

What problem(s) does this PR solve?

A property and and enum can often have matching names after they are converted to PascalCase to follow C# naming conventions. When the property and the enum are declared in the same class this is not a problem because the bindings generator detects this and adds an Enum suffix to the enum type.

But when the property is declared in a derived class, it hides the enum type instead, which is now a CI error unless we explicitly suppress it, which we don't want to do often. This allows specifying which enums should always add the Enum suffix in the generated C# bindings, which solves these 2 issues:

  • Can be used to prevent hiding members, resolving the CI error.
  • Can also be used to avoid breaking compatibility later if a new member is added that matches the name of the enum, which seems to be the case in Add Trail3D class #117107.

Additional information

This can be used by #117107 to fix the current CI errors with a change like this:

diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 56c586752f3..3890c228cd6 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -153,7 +153,11 @@ const Vector<String> prop_allowed_inherited_member_hiding = {
 // This avoids hiding the enum when the property is declared in a derived class,
 // and the need for the 'new' keyword. It can also be used to avoid breaking compat
 // later if a new member is added with the same name as the enum.
-const Vector<String> enums_with_forced_suffix = {};
+const Vector<String> enums_with_forced_suffix = {
+	"Line3D.MaterialMode",
+	"Line3D.MeshAlignment",
+	"Line3D.TilingMode",
+};
 
 void BindingsGenerator::TypeInterface::postsetup_enum_type(BindingsGenerator::TypeInterface &r_enum_itype) {
 	// C interface for enums is the same as that of 'uint32_t'. Remember to apply

Can also be used to avoid breaking compatibility later if a
new member is added that matches the name of the enum.
@raulsntos raulsntos added this to the 4.8 milestone Jun 18, 2026
@raulsntos raulsntos requested review from a team as code owners June 18, 2026 13:43
@paulloz

paulloz commented Jun 18, 2026

Copy link
Copy Markdown
Member

Do we want to use this to limit current usages of new (e.g. all the occurrences of TextDirection)?

@raulsntos

Copy link
Copy Markdown
Member Author

Changing TextDirection now would break compatibility. I think it would be a good idea to add the suffix for all new enums, but we'd need a way to know which version introduced the enum to avoid breaking compatibility for all existing enums, and that's not available in ClassDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants