Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve C# method listing #52607

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,28 @@ Variant::Type CSharpInstance::get_property_type(const StringName &p_name, bool *
return Variant::NIL;
}

void CSharpInstance::get_method_list(List<MethodInfo> *p_list) const {
if (!script->is_valid() || !script->script_class)
return;

GD_MONO_SCOPE_THREAD_ATTACH;

// TODO: We're filtering out constructors but there may be other methods unsuitable for explicit calls.
GDMonoClass *top = script->script_class;

while (top && top != script->native) {
const Vector<GDMonoMethod *> &methods = top->get_all_methods();
for (int i = 0; i < methods.size(); ++i) {
MethodInfo minfo = methods[i]->get_method_info();
if (minfo.name != CACHED_STRING_NAME(dotctor)) {
p_list->push_back(minfo);
}
}

top = top->get_parent_class();
}
}

bool CSharpInstance::has_method(const StringName &p_method) const {
if (!script.is_valid()) {
return false;
Expand Down Expand Up @@ -3280,10 +3302,19 @@ void CSharpScript::get_script_method_list(List<MethodInfo> *p_list) const {

GD_MONO_SCOPE_THREAD_ATTACH;

// TODO: Filter out things unsuitable for explicit calls, like constructors.
const Vector<GDMonoMethod *> &methods = script_class->get_all_methods();
for (int i = 0; i < methods.size(); ++i) {
p_list->push_back(methods[i]->get_method_info());
// TODO: We're filtering out constructors but there may be other methods unsuitable for explicit calls.
GDMonoClass *top = script_class;

while (top && top != native) {
const Vector<GDMonoMethod *> &methods = top->get_all_methods();
for (int i = 0; i < methods.size(); ++i) {
MethodInfo minfo = methods[i]->get_method_info();
if (minfo.name != CACHED_STRING_NAME(dotctor)) {
p_list->push_back(methods[i]->get_method_info());
}
}

top = top->get_parent_class();
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/mono/csharp_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class CSharpInstance : public ScriptInstance {
void get_property_list(List<PropertyInfo> *p_properties) const override;
Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const override;

/* TODO */ void get_method_list(List<MethodInfo> *p_list) const override {}
void get_method_list(List<MethodInfo> *p_list) const override;
bool has_method(const StringName &p_method) const override;
Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;

Expand Down