diff options
author | Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com> | 2021-12-04 12:38:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-04 12:38:09 +0100 |
commit | 2a9dd654bc0197dd864df61b5b37e302022c2871 (patch) | |
tree | ce700ebd9d9b0b5eff5d4202ead4dae9e50bad18 /modules/mono/mono_gd/gd_mono_class.cpp | |
parent | d394cbce994d41155f6a33b795c8f6c7af640c56 (diff) | |
parent | d28be4d5808947606b8189ae1b2900b8fd2925cf (diff) | |
download | redot-engine-2a9dd654bc0197dd864df61b5b37e302022c2871.tar.gz |
Merge pull request #55563 from raulsntos/csharp-delegates-for-generic-class
Fix C# `get_all_delegates` method for generic classes
Diffstat (limited to 'modules/mono/mono_gd/gd_mono_class.cpp')
-rw-r--r-- | modules/mono/mono_gd/gd_mono_class.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp index 4f4480fa49..520568071e 100644 --- a/modules/mono/mono_gd/gd_mono_class.cpp +++ b/modules/mono/mono_gd/gd_mono_class.cpp @@ -464,9 +464,18 @@ const Vector<GDMonoClass *> &GDMonoClass::get_all_delegates() { return delegates_list; } + // If the class is generic we must use the generic type definition. + MonoClass *klass = mono_class; + if (mono_type_get_type(get_mono_type()) == MONO_TYPE_GENERICINST) { + MonoReflectionType *reftype = mono_type_get_object(mono_domain_get(), get_mono_type()); + GDMonoUtils::Marshal::get_generic_type_definition(reftype, &reftype); + MonoType *type = mono_reflection_type_get_type(reftype); + klass = mono_class_from_mono_type(type); + } + void *iter = nullptr; MonoClass *raw_class = nullptr; - while ((raw_class = mono_class_get_nested_types(mono_class, &iter)) != nullptr) { + while ((raw_class = mono_class_get_nested_types(klass, &iter)) != nullptr) { if (mono_class_is_delegate(raw_class)) { StringName name = String::utf8(mono_class_get_name(raw_class)); |