efl-mono: Make override of methods only for methods that are defined by the user

Summary:
Instead of overriding every method and making the callback to C, we
just override the methods that are found by reflection on the type.

Reviewers: bu5hm4n, vitor.sousa, segfaultxavi, woohyun, Jaehyun_Cho, YOhoho, lauromoura

Reviewed By: lauromoura

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8579
This commit is contained in:
Felipe Magno de Almeida 2019-04-09 11:16:17 -03:00
parent b1f0031b55
commit df3b28b0ab
3 changed files with 29 additions and 2 deletions

View File

@ -44,7 +44,10 @@ struct function_registration_generator
return false;
if(!as_generator
(scope_tab << scope_tab << "descs.Add(new Efl_Op_Description() {"
(scope_tab << scope_tab
<< "if (methods.FirstOrDefault(m => m.Name == \"" << string << "\") != null)\n"
<< scope_tab << scope_tab << scope_tab
<< "descs.Add(new Efl_Op_Description() {"
#ifdef _WIN32
<< "api_func = Marshal.StringToHGlobalAnsi(\"" << string << "\")"
#else
@ -52,7 +55,7 @@ struct function_registration_generator
#endif
<< ", func = Marshal.GetFunctionPointerForDelegate(" << string << "_static_delegate)});\n"
)
.generate(sink, std::make_tuple(f.c_name, f.c_name), context))
.generate(sink, std::make_tuple(name_helpers::managed_method_name(f), f.c_name, f.c_name), context))
return false;
return true;
}

View File

@ -369,6 +369,7 @@ struct klass
<< scope_tab << "public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)\n"
<< scope_tab << "{\n"
<< scope_tab << scope_tab << "var descs = new System.Collections.Generic.List<Efl_Op_Description>();\n"
<< scope_tab << scope_tab << "var methods = Efl.Eo.Globals.GetUserMethods(type);\n"
)
.generate(sink, attributes::unused, inative_cxt))
return false;

View File

@ -302,6 +302,29 @@ public class Globals
return null;
}
public static System.Collections.Generic.List<System.Reflection.MethodInfo>
GetUserMethods(System.Type type)
{
var r = new System.Collections.Generic.List<System.Reflection.MethodInfo>();
r.AddRange(type.GetMethods());
var base_type = type.BaseType;
for (;base_type != null; base_type = base_type.BaseType)
{
var attrs = System.Attribute.GetCustomAttributes(type);
foreach (var attr in attrs)
{
if (attr is Efl.Eo.NativeClass)
{
return r;
}
}
r.AddRange(base_type.GetMethods());
}
return r;
}
public static byte class_initializer_call(IntPtr klass, System.Type type)
{
Eina.Log.Debug($"called with 0x{klass.ToInt64():x} {type}");