From 300aa202c81c9c8986f4828999e1ece46b62733f Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Fri, 15 Mar 2024 19:43:00 -0500 Subject: [PATCH] C#: Implement `InvariantCulture` on Variant strings --- .../mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs | 5 +---- .../glue/GodotSharp/GodotSharp/Core/Basis.cs | 5 +---- .../glue/GodotSharp/GodotSharp/Core/Color.cs | 9 ++------- .../glue/GodotSharp/GodotSharp/Core/Plane.cs | 10 +++------- .../GodotSharp/GodotSharp/Core/Projection.cs | 16 ++++++---------- .../GodotSharp/GodotSharp/Core/Quaternion.cs | 10 +++------- .../glue/GodotSharp/GodotSharp/Core/Rect2.cs | 5 +---- .../glue/GodotSharp/GodotSharp/Core/Rect2I.cs | 5 +---- .../mono/glue/GodotSharp/GodotSharp/Core/Rid.cs | 5 ++--- .../GodotSharp/GodotSharp/Core/Transform2D.cs | 5 +---- .../GodotSharp/GodotSharp/Core/Transform3D.cs | 5 +---- .../glue/GodotSharp/GodotSharp/Core/Vector2.cs | 10 +++------- .../glue/GodotSharp/GodotSharp/Core/Vector2I.cs | 10 +++------- .../glue/GodotSharp/GodotSharp/Core/Vector3.cs | 10 +++------- .../glue/GodotSharp/GodotSharp/Core/Vector3I.cs | 10 +++------- .../glue/GodotSharp/GodotSharp/Core/Vector4.cs | 10 +++------- .../glue/GodotSharp/GodotSharp/Core/Vector4I.cs | 10 +++------- 17 files changed, 40 insertions(+), 100 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs index 63af6ee6e8d..feaa1d07dad 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs @@ -733,10 +733,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this AABB. - public override readonly string ToString() - { - return $"{_position}, {_size}"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index 589d6596f0b..8d24582ba15 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -1134,10 +1134,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this basis. - public override readonly string ToString() - { - return $"[X: {X}, Y: {Y}, Z: {Z}]"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index a1f1ade9b86..d3b9f2d2aed 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -1329,10 +1329,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this color. - public override readonly string ToString() - { - return $"({R}, {G}, {B}, {A})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -1340,9 +1337,7 @@ namespace Godot /// A string representation of this color. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({R.ToString(format)}, {G.ToString(format)}, {B.ToString(format)}, {A.ToString(format)})"; -#pragma warning restore CA1305 + return $"({R.ToString(format, CultureInfo.InvariantCulture)}, {G.ToString(format, CultureInfo.InvariantCulture)}, {B.ToString(format, CultureInfo.InvariantCulture)}, {A.ToString(format, CultureInfo.InvariantCulture)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs index c5998eca5c0..1f50a38e78d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -424,10 +425,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this plane. - public override readonly string ToString() - { - return $"{_normal}, {_d}"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -435,9 +433,7 @@ namespace Godot /// A string representation of this plane. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"{_normal.ToString(format)}, {_d.ToString(format)}"; -#pragma warning restore CA1305 + return $"{_normal.ToString(format)}, {_d.ToString(format, CultureInfo.InvariantCulture)}"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs index c0889fb0e86..fed0eb5e784 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -1012,10 +1013,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this projection. - public override readonly string ToString() - { - return $"{X.X}, {X.Y}, {X.Z}, {X.W}\n{Y.X}, {Y.Y}, {Y.Z}, {Y.W}\n{Z.X}, {Z.Y}, {Z.Z}, {Z.W}\n{W.X}, {W.Y}, {W.Z}, {W.W}\n"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -1023,12 +1021,10 @@ namespace Godot /// A string representation of this projection. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"{X.X.ToString(format)}, {X.Y.ToString(format)}, {X.Z.ToString(format)}, {X.W.ToString(format)}\n" + - $"{Y.X.ToString(format)}, {Y.Y.ToString(format)}, {Y.Z.ToString(format)}, {Y.W.ToString(format)}\n" + - $"{Z.X.ToString(format)}, {Z.Y.ToString(format)}, {Z.Z.ToString(format)}, {Z.W.ToString(format)}\n" + - $"{W.X.ToString(format)}, {W.Y.ToString(format)}, {W.Z.ToString(format)}, {W.W.ToString(format)}\n"; -#pragma warning restore CA1305 + return $"{X.X.ToString(format, CultureInfo.InvariantCulture)}, {X.Y.ToString(format, CultureInfo.InvariantCulture)}, {X.Z.ToString(format, CultureInfo.InvariantCulture)}, {X.W.ToString(format, CultureInfo.InvariantCulture)}\n" + + $"{Y.X.ToString(format, CultureInfo.InvariantCulture)}, {Y.Y.ToString(format, CultureInfo.InvariantCulture)}, {Y.Z.ToString(format, CultureInfo.InvariantCulture)}, {Y.W.ToString(format, CultureInfo.InvariantCulture)}\n" + + $"{Z.X.ToString(format, CultureInfo.InvariantCulture)}, {Z.Y.ToString(format, CultureInfo.InvariantCulture)}, {Z.Z.ToString(format, CultureInfo.InvariantCulture)}, {Z.W.ToString(format, CultureInfo.InvariantCulture)}\n" + + $"{W.X.ToString(format, CultureInfo.InvariantCulture)}, {W.Y.ToString(format, CultureInfo.InvariantCulture)}, {W.Z.ToString(format, CultureInfo.InvariantCulture)}, {W.W.ToString(format, CultureInfo.InvariantCulture)}\n"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index 6a8cb1ba042..09511ebdcae 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -811,10 +812,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this quaternion. - public override readonly string ToString() - { - return $"({X}, {Y}, {Z}, {W})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -822,9 +820,7 @@ namespace Godot /// A string representation of this quaternion. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})"; -#pragma warning restore CA1305 + return $"({X.ToString(format, CultureInfo.InvariantCulture)}, {Y.ToString(format, CultureInfo.InvariantCulture)}, {Z.ToString(format, CultureInfo.InvariantCulture)}, {W.ToString(format, CultureInfo.InvariantCulture)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs index cf4ac45a9f6..9d9065911ee 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs @@ -469,10 +469,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this rect. - public override readonly string ToString() - { - return $"{_position}, {_size}"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs index 58560df0c51..65704b3da7b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs @@ -429,10 +429,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this rect. - public override readonly string ToString() - { - return $"{_position}, {_size}"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs index fccae94eac5..4f0015c7aea 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs @@ -1,8 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; +using System.Globalization; using System.Runtime.InteropServices; -using Godot.NativeInterop; #nullable enable @@ -102,6 +101,6 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this Rid. - public override string ToString() => $"RID({Id})"; + public override readonly string ToString() => $"RID({Id.ToString(null, CultureInfo.InvariantCulture)})"; } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index 3443277feed..a5fa89d3bfd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -650,10 +650,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this transform. - public override readonly string ToString() - { - return $"[X: {X}, Y: {Y}, O: {Origin}]"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index f80c0bd8dd9..0f534d477f2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -674,10 +674,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this transform. - public override readonly string ToString() - { - return $"[X: {Basis.X}, Y: {Basis.Y}, Z: {Basis.Z}, O: {Origin}]"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 8f1bc109c04..856fd54352f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -1016,10 +1017,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this vector. - public override readonly string ToString() - { - return $"({X}, {Y})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -1027,9 +1025,7 @@ namespace Godot /// A string representation of this vector. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)})"; -#pragma warning restore CA1305 + return $"({X.ToString(format, CultureInfo.InvariantCulture)}, {Y.ToString(format, CultureInfo.InvariantCulture)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs index 1a386d9da1f..511cc7971cf 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -589,10 +590,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this vector. - public override readonly string ToString() - { - return $"({X}, {Y})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -600,9 +598,7 @@ namespace Godot /// A string representation of this vector. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)})"; -#pragma warning restore CA1305 + return $"({X.ToString(format, CultureInfo.InvariantCulture)}, {Y.ToString(format, CultureInfo.InvariantCulture)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index 74c1616e3da..6300705107f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -1118,10 +1119,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this vector. - public override readonly string ToString() - { - return $"({X}, {Y}, {Z})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -1129,9 +1127,7 @@ namespace Godot /// A string representation of this vector. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})"; -#pragma warning restore CA1305 + return $"({X.ToString(format, CultureInfo.InvariantCulture)}, {Y.ToString(format, CultureInfo.InvariantCulture)}, {Z.ToString(format, CultureInfo.InvariantCulture)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs index d0ad1922f61..aea46efc5ba 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -644,10 +645,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this vector. - public override readonly string ToString() - { - return $"({X}, {Y}, {Z})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -655,9 +653,7 @@ namespace Godot /// A string representation of this vector. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})"; -#pragma warning restore CA1305 + return $"({X.ToString(format, CultureInfo.InvariantCulture)}, {Y.ToString(format, CultureInfo.InvariantCulture)}, {Z.ToString(format, CultureInfo.InvariantCulture)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs index 115e65bbdb0..7c4832943c0 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -894,10 +895,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this vector. - public override string ToString() - { - return $"({X}, {Y}, {Z}, {W})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -905,9 +903,7 @@ namespace Godot /// A string representation of this vector. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})"; -#pragma warning restore CA1305 + return $"({X.ToString(format, CultureInfo.InvariantCulture)}, {Y.ToString(format, CultureInfo.InvariantCulture)}, {Z.ToString(format, CultureInfo.InvariantCulture)}, {W.ToString(format, CultureInfo.InvariantCulture)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs index 527c8e5022c..27aa86b7e47 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; #nullable enable @@ -665,10 +666,7 @@ namespace Godot /// Converts this to a string. /// /// A string representation of this vector. - public override readonly string ToString() - { - return $"({X}, {Y}, {Z}, {W})"; - } + public override readonly string ToString() => ToString(null); /// /// Converts this to a string with the given . @@ -676,9 +674,7 @@ namespace Godot /// A string representation of this vector. public readonly string ToString(string? format) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})"; -#pragma warning restore CA1305 + return $"({X.ToString(format, CultureInfo.InvariantCulture)}, {Y.ToString(format, CultureInfo.InvariantCulture)}, {Z.ToString(format, CultureInfo.InvariantCulture)}, {W.ToString(format, CultureInfo.InvariantCulture)})"; } } }