From 5c206c38f969bb6c1438c7ea673ccc66ed402611 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Thu, 29 Jul 2021 13:51:54 +0200 Subject: [PATCH] Simplify C# print methods - Extracts the parameters logic to a single method - Simplify the handling of null parameters (cherry picked from commit ad460cde7988e42acd4ec8d7c35d9c50f7c063a7) --- .../glue/GodotSharp/GodotSharp/Core/GD.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs index cc68abf1a18..87ff3416f72 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs @@ -46,6 +46,16 @@ namespace Godot return ret; } + private static object[] GetPrintParams(object[] parameters) + { + if (parameters == null) + { + return new[] { "null" }; + } + + return Array.ConvertAll(parameters, x => x?.ToString() ?? "null"); + } + public static int Hash(object var) { return godot_icall_GD_hash(var); @@ -83,7 +93,7 @@ namespace Godot public static void Print(params object[] what) { - godot_icall_GD_print(Array.ConvertAll(what ?? new object[] { "null" }, x => x != null ? x.ToString() : "null")); + godot_icall_GD_print(GetPrintParams(what)); } public static void PrintStack() @@ -93,22 +103,22 @@ namespace Godot public static void PrintErr(params object[] what) { - godot_icall_GD_printerr(Array.ConvertAll(what ?? new object[] { "null" }, x => x != null ? x.ToString() : "null")); + godot_icall_GD_printerr(GetPrintParams(what)); } public static void PrintRaw(params object[] what) { - godot_icall_GD_printraw(Array.ConvertAll(what ?? new object[] { "null" }, x => x != null ? x.ToString() : "null")); + godot_icall_GD_printraw(GetPrintParams(what)); } public static void PrintS(params object[] what) { - godot_icall_GD_prints(Array.ConvertAll(what ?? new object[] { "null" }, x => x != null ? x.ToString() : "null")); + godot_icall_GD_prints(GetPrintParams(what)); } public static void PrintT(params object[] what) { - godot_icall_GD_printt(Array.ConvertAll(what ?? new object[] { "null" }, x => x != null ? x.ToString() : "null")); + godot_icall_GD_printt(GetPrintParams(what)); } public static float Randf()