diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs index 63af6ee6e8d8..0f0381752b94 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs @@ -12,7 +12,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Aabb : IEquatable + public struct Aabb : IEquatable, IFormattable { private Vector3 _position; private Vector3 _size; @@ -733,18 +733,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this AABB. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this AABB. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { - return $"{_position.ToString(format)}, {_size.ToString(format)}"; + string separator = formatProvider.GetListSeparator(); + return $"{_position.ToString(format, formatProvider)}{separator} {_size.ToString(format, formatProvider)}"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index 589d6596f0b8..2187b976a86a 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -1,7 +1,7 @@ using System; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; -using System.ComponentModel; #nullable enable @@ -23,7 +23,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Basis : IEquatable + public struct Basis : IEquatable, IFormattable { // NOTE: x, y and z are public-only. Use Column0, Column1 and Column2 internally. @@ -1134,18 +1134,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this basis. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this basis. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { - return $"[X: {X.ToString(format)}, Y: {Y.ToString(format)}, Z: {Z.ToString(format)}]"; + string separator = formatProvider.GetListSeparator(); + return $"[X: {X.ToString(format, formatProvider)}{separator} Y: {Y.ToString(format, formatProvider)}{separator} Z: {Z.ToString(format, formatProvider)}]"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index a1f1ade9b86a..854afa8f56f7 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Globalization; using System.Runtime.InteropServices; using Godot.NativeInterop; @@ -20,7 +19,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Color : IEquatable + public struct Color : IEquatable, IFormattable { /// /// The color's red component, typically on the range of 0 to 1. @@ -1329,20 +1328,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this color. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this color. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#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 + string separator = formatProvider.GetListSeparator(); + return $"({R.ToString(format, formatProvider)}{separator} {G.ToString(format, formatProvider)}{separator} {B.ToString(format, formatProvider)}{separator} {A.ToString(format, formatProvider)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs index c5998eca5c08..e303b1b57547 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs @@ -13,7 +13,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Plane : IEquatable + public struct Plane : IEquatable, IFormattable { private Vector3 _normal; private real_t _d; @@ -424,20 +424,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this plane. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this plane. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"{_normal.ToString(format)}, {_d.ToString(format)}"; -#pragma warning restore CA1305 + string separator = formatProvider.GetListSeparator(); + return $"{_normal.ToString(format, formatProvider)}{separator} {_d.ToString(format, formatProvider)}"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs index c0889fb0e866..8baeafe6b2cf 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs @@ -16,7 +16,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Projection : IEquatable + public struct Projection : IEquatable, IFormattable { /// /// Enumerated index values for the planes. @@ -1012,23 +1012,25 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this projection. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this projection. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#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 + string separator = formatProvider.GetListSeparator(); + return $"{X.X.ToString(format, formatProvider)}{separator} {X.Y.ToString(format, formatProvider)}{separator} {X.Z.ToString(format, formatProvider)}{separator} {X.W.ToString(format, formatProvider)}\n" + + $"{Y.X.ToString(format, formatProvider)}{separator} {Y.Y.ToString(format, formatProvider)}{separator} {Y.Z.ToString(format, formatProvider)}{separator} {Y.W.ToString(format, formatProvider)}\n" + + $"{Z.X.ToString(format, formatProvider)}{separator} {Z.Y.ToString(format, formatProvider)}{separator} {Z.Z.ToString(format, formatProvider)}{separator} {Z.W.ToString(format, formatProvider)}\n" + + $"{W.X.ToString(format, formatProvider)}{separator} {W.Y.ToString(format, formatProvider)}{separator} {W.Z.ToString(format, formatProvider)}{separator} {W.W.ToString(format, formatProvider)}\n"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index 6a8cb1ba042a..60a7bd31ba1d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -21,7 +21,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Quaternion : IEquatable + public struct Quaternion : IEquatable, IFormattable { /// /// X component of the quaternion (imaginary i axis part). @@ -811,20 +811,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this quaternion. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this quaternion. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#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 + string separator = formatProvider.GetListSeparator(); + return $"({X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}{separator} {Z.ToString(format, formatProvider)}{separator} {W.ToString(format, formatProvider)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs index cf4ac45a9f6a..c6423b25d986 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs @@ -12,7 +12,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Rect2 : IEquatable + public struct Rect2 : IEquatable, IFormattable { private Vector2 _position; private Vector2 _size; @@ -469,18 +469,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this rect. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this rect. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { - return $"{_position.ToString(format)}, {_size.ToString(format)}"; + string separator = formatProvider.GetListSeparator(); + return $"{_position.ToString(format, formatProvider)}{separator} {_size.ToString(format, formatProvider)}"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs index 58560df0c518..9624248964d2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs @@ -12,7 +12,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Rect2I : IEquatable + public struct Rect2I : IEquatable, IFormattable { private Vector2I _position; private Vector2I _size; @@ -429,18 +429,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this rect. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this rect. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { - return $"{_position.ToString(format)}, {_size.ToString(format)}"; + string separator = formatProvider.GetListSeparator(); + return $"{_position.ToString(format, formatProvider)}{separator} {_size.ToString(format, formatProvider)}"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index 9cd5498fa814..02f14356aec6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -1877,5 +1877,31 @@ public static string XMLEscape(this string instance) { return SecurityElement.FromString(instance)?.Text; } + + /// + /// Returns the list separator of this as a string. + /// + /// The format provider to pull from. + /// The list separator of this IFormatProvider, or the current culture's if + /// is or cannot be converted. + public static string GetListSeparator(this IFormatProvider? provider) + { + if (provider is CultureInfo cultureInfo) + { + return cultureInfo.TextInfo.ListSeparator; + } + + if (provider is NumberFormatInfo numberFormatInfo) + { + if (numberFormatInfo == NumberFormatInfo.InvariantInfo) + { + return CultureInfo.InvariantCulture.TextInfo.ListSeparator; + } + // TODO: Figure out if there's a way of backtracing CultureInfo from NumberFormatInfo + return CultureInfo.CurrentCulture.TextInfo.ListSeparator; + } + + return CultureInfo.CurrentCulture.TextInfo.ListSeparator; + } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index 3443277feed9..4253d3c779c2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -17,7 +17,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Transform2D : IEquatable + public struct Transform2D : IEquatable, IFormattable { /// /// The basis matrix's X vector (column 0). Equivalent to array index [0]. @@ -650,18 +650,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this transform. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this transform. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { - return $"[X: {X.ToString(format)}, Y: {Y.ToString(format)}, O: {Origin.ToString(format)}]"; + string separator = formatProvider.GetListSeparator(); + return $"[X: {X.ToString(format, formatProvider)}{separator} Y: {Y.ToString(format, formatProvider)}{separator} O: {Origin.ToString(format, formatProvider)}]"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index f80c0bd8dd99..a04d6dd70db3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -1,7 +1,7 @@ using System; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; -using System.ComponentModel; #nullable enable @@ -18,7 +18,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Transform3D : IEquatable + public struct Transform3D : IEquatable, IFormattable { /// /// The of this transform. Contains the X, Y, and Z basis @@ -674,18 +674,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this transform. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this transform. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { - return $"[X: {Basis.X.ToString(format)}, Y: {Basis.Y.ToString(format)}, Z: {Basis.Z.ToString(format)}, O: {Origin.ToString(format)}]"; + string separator = formatProvider.GetListSeparator(); + return $"[X: {Basis.X.ToString(format, formatProvider)}{separator} Y: {Basis.Y.ToString(format, formatProvider)}{separator} Z: {Basis.Z.ToString(format, formatProvider)}{separator} O: {Origin.ToString(format, formatProvider)}]"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 8f1bc109c042..5f34c5663084 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -11,7 +11,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Vector2 : IEquatable + public struct Vector2 : IEquatable, IFormattable { /// /// Enumerated index values for the axes. @@ -1016,20 +1016,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this vector. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this vector. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)})"; -#pragma warning restore CA1305 + string separator = formatProvider.GetListSeparator(); + return $"({X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs index 1a386d9da1fd..d97d79ba2520 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs @@ -11,7 +11,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Vector2I : IEquatable + public struct Vector2I : IEquatable, IFormattable { /// /// Enumerated index values for the axes. @@ -589,20 +589,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this vector. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this vector. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)})"; -#pragma warning restore CA1305 + string separator = formatProvider.GetListSeparator(); + return $"({X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index 74c1616e3daf..27017923bd13 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -11,7 +11,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Vector3 : IEquatable + public struct Vector3 : IEquatable, IFormattable { /// /// Enumerated index values for the axes. @@ -1118,20 +1118,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this vector. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this vector. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})"; -#pragma warning restore CA1305 + string separator = formatProvider.GetListSeparator(); + return $"({X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}{separator} {Z.ToString(format, formatProvider)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs index d0ad1922f611..c068f2e0ec82 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs @@ -11,7 +11,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Vector3I : IEquatable + public struct Vector3I : IEquatable, IFormattable { /// /// Enumerated index values for the axes. @@ -644,20 +644,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this vector. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this vector. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})"; -#pragma warning restore CA1305 + string separator = formatProvider.GetListSeparator(); + return $"({X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}{separator} {Z.ToString(format, formatProvider)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs index 115e65bbdb04..3ea3800793e7 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs @@ -11,7 +11,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Vector4 : IEquatable + public struct Vector4 : IEquatable, IFormattable { /// /// Enumerated index values for the axes. @@ -894,20 +894,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this vector. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this vector. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#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 + string separator = formatProvider.GetListSeparator(); + return $"({X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}{separator} {Z.ToString(format, formatProvider)}{separator} {W.ToString(format, formatProvider)})"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs index 527c8e5022cc..05f7f3add445 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs @@ -11,7 +11,7 @@ namespace Godot /// [Serializable] [StructLayout(LayoutKind.Sequential)] - public struct Vector4I : IEquatable + public struct Vector4I : IEquatable, IFormattable { /// /// Enumerated index values for the axes. @@ -665,20 +665,22 @@ public override readonly int GetHashCode() /// 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, null); /// /// Converts this to a string with the given . /// /// A string representation of this vector. - public readonly string ToString(string? format) + public readonly string ToString(string? format) => ToString(format, null); + + /// + /// Converts this to a string with the given and . + /// + /// A string representation of this vector. + public readonly string ToString(string? format, IFormatProvider? formatProvider) { -#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 + string separator = formatProvider.GetListSeparator(); + return $"({X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}{separator} {Z.ToString(format, formatProvider)}{separator} {W.ToString(format, formatProvider)})"; } } }