From 88f5f815e66a002ae336db29f8a51b957439bbef Mon Sep 17 00:00:00 2001 From: Matt Diener Date: Fri, 30 Jun 2023 10:46:42 -0400 Subject: [PATCH] C# Fix deserialization of delegates that are 0-parameter overloads Co-authored-by: Raul Santos (cherry picked from commit 783facf60b3e20671499ab307a00321f36cf65d9) --- .../GodotSharp/Core/DelegateUtils.cs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs index 5d03379430e..6c2fb7374c2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs @@ -500,24 +500,17 @@ namespace Godot Type? returnType = hasReturn ? DeserializeType(reader) : typeof(void); int parametersCount = reader.ReadInt32(); + var parameterTypes = parametersCount == 0 ? Type.EmptyTypes : new Type[parametersCount]; - if (parametersCount > 0) + for (int i = 0; i < parametersCount; i++) { - var parameterTypes = new Type[parametersCount]; - - for (int i = 0; i < parametersCount; i++) - { - Type? parameterType = DeserializeType(reader); - if (parameterType == null) - return false; - parameterTypes[i] = parameterType; - } - - methodInfo = declaringType.GetMethod(methodName, (BindingFlags)flags, null, parameterTypes, null); - return methodInfo != null && methodInfo.ReturnType == returnType; + Type? parameterType = DeserializeType(reader); + if (parameterType == null) + return false; + parameterTypes[i] = parameterType; } - methodInfo = declaringType.GetMethod(methodName, (BindingFlags)flags); + methodInfo = declaringType.GetMethod(methodName, (BindingFlags)flags, null, parameterTypes, null); return methodInfo != null && methodInfo.ReturnType == returnType; }