From 700d87b3709c5eeb6fa7a238b24ae93e6fad4d68 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Wed, 22 Jan 2020 11:33:41 +0900 Subject: [PATCH] Revert "efl_mono: remove class ExtensionTag" Extension Methods' classes have methods with same names and parameters. e.g. Text(this Efl.Ui.ItemFactory fac) Although the where clause contains different classes, they cannot be identified as different methods by C# compiler. e.g. Text(this Efl.Ui.ItemFactory fac) where T : Efl.Ui.Button e.g. Text(this Efl.Ui.ItemFactory fac) where T : Efl.Ui.Check As a result, to avoid ambiguous methods, ExtensionTag should be used as a second parameter of each method. e.g. Text(this Efl.Ui.ItemFactory fac, ExtensionTagmagic = null) where T : Efl.Ui.Button e.g. Text(this Efl.Ui.ItemFactory fac, ExtensionTagmagic = null) where T : Efl.Ui.Check This reverts commit 76631f502a8234c04ed8124bfdebe62ed5bdf954. --- .../eolian_mono/eolian/mono/function_definition.hh | 10 ++++++---- src/bin/eolian_mono/eolian/mono/part_definition.hh | 5 +++-- src/bindings/mono/efl_mono/Bind.cs | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh index fcc8a88f15..3c30cdd3fe 100644 --- a/src/bin/eolian_mono/eolian/mono/function_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh @@ -284,8 +284,9 @@ struct property_extension_method_definition_generator if (property.setter.is_engaged()) { attributes::type_def prop_type = property.setter->parameters[0].type; - if (!as_generator(scope_tab(2) << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "(this Efl.Ui.ItemFactory fac) where T : " - << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n" + if (!as_generator(scope_tab(2) << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "(this Efl.Ui.ItemFactory fac, Efl.Csharp.ExtensionTag<" + << name_helpers::klass_full_concrete_or_interface_name(cls) + << ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n" << scope_tab(2) << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(\"" << property.name << "\", fac);\n" << scope_tab(2) << "}\n\n" ).generate(sink, std::make_tuple(prop_type, prop_type), context)) @@ -300,8 +301,9 @@ struct property_extension_method_definition_generator if (property.setter.is_engaged()) { attributes::type_def prop_type = property.setter->parameters[0].type; - if (!as_generator(scope_tab(2) << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "(this Efl.BindablePart part) where T : " - << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n" + if (!as_generator(scope_tab(2) << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "(this Efl.BindablePart part, Efl.Csharp.ExtensionTag<" + << name_helpers::klass_full_concrete_or_interface_name(cls) + << ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n" << scope_tab(2) << scope_tab << "Contract.Requires(part != null, nameof(part));\n" << scope_tab(2) << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(part.PartName, \"" << property.name << "\", part.Binder);\n" << scope_tab(2) << "}\n\n" diff --git a/src/bin/eolian_mono/eolian/mono/part_definition.hh b/src/bin/eolian_mono/eolian/mono/part_definition.hh index d87b0b56ac..4facf27209 100644 --- a/src/bin/eolian_mono/eolian/mono/part_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/part_definition.hh @@ -70,8 +70,9 @@ struct part_extension_method_definition_generator bindableClass = "Efl.BindableFactoryPart"; if (!as_generator( - scope_tab(2) << "public static " << bindableClass << "<" << part_klass_name << "> " << name_helpers::managed_part_name(part) << "(this Efl.Ui.ItemFactory fac) where T : " - << name_helpers::klass_full_concrete_or_interface_name(cls) << "\n" + scope_tab(2) << "public static " << bindableClass << "<" << part_klass_name << "> " << name_helpers::managed_part_name(part) << "(this Efl.Ui.ItemFactory fac, Efl.Csharp.ExtensionTag<" + << name_helpers::klass_full_concrete_or_interface_name(cls) + << ", T> x=null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << "\n" << scope_tab(2) << "{\n" << scope_tab(2) << scope_tab << "return new " << bindableClass << "<" << part_klass_name << ">(\"" << part.name << "\", fac);\n" << scope_tab(2) << "}\n\n" diff --git a/src/bindings/mono/efl_mono/Bind.cs b/src/bindings/mono/efl_mono/Bind.cs index 302f1dadd2..2a4fcbded5 100644 --- a/src/bindings/mono/efl_mono/Bind.cs +++ b/src/bindings/mono/efl_mono/Bind.cs @@ -148,6 +148,20 @@ public class BindableFactoryPart } } +namespace Csharp +{ + +/// Helper class to differentiate between factory extension methods. +/// +/// For internal use only. +[EditorBrowsable(EditorBrowsableState.Never)] +public class ExtensionTag + where TInherited : TBase +{ +} + +} + } #endif