mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-22 23:58:47 +00:00
Specify CultureInfo when converting types
This commit is contained in:
parent
3abd7b1379
commit
656a0b287d
@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Cysharp.Text;
|
using Cysharp.Text;
|
||||||
@ -288,7 +289,7 @@ public sealed class VirtualParadiseParticleEmitterObject : VirtualParadiseObject
|
|||||||
}
|
}
|
||||||
else if (property.PropertyType != typeof(string))
|
else if (property.PropertyType != typeof(string))
|
||||||
{
|
{
|
||||||
value = Convert.ChangeType(value, property.PropertyType);
|
value = Convert.ChangeType(value, property.PropertyType, CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
property.SetValue(this, value);
|
property.SetValue(this, value);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Numerics;
|
using System.Globalization;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Cysharp.Text;
|
using Cysharp.Text;
|
||||||
using VpSharp.Extensions;
|
using VpSharp.Extensions;
|
||||||
@ -81,8 +82,8 @@ public sealed class VirtualParadisePathObject : VirtualParadiseObject
|
|||||||
int spaceIndex = chars[index..].IndexOf(' ');
|
int spaceIndex = chars[index..].IndexOf(' ');
|
||||||
int newLineIndex = chars[index..].IndexOf('\n');
|
int newLineIndex = chars[index..].IndexOf('\n');
|
||||||
|
|
||||||
int pathType = int.Parse(chars[index..(index + spaceIndex)]);
|
int pathType = int.Parse(chars[index..(index + spaceIndex)], provider: CultureInfo.InvariantCulture);
|
||||||
int closed = int.Parse(chars[(index + spaceIndex + 1)..(index + newLineIndex)]);
|
int closed = int.Parse(chars[(index + spaceIndex + 1)..(index + newLineIndex)], provider: CultureInfo.InvariantCulture);
|
||||||
index += newLineIndex;
|
index += newLineIndex;
|
||||||
|
|
||||||
// points from here onwards
|
// points from here onwards
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.Globalization;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Cysharp.Text;
|
using Cysharp.Text;
|
||||||
@ -10,21 +11,21 @@ internal static class SpanExtensions
|
|||||||
{
|
{
|
||||||
Span<char> chars = stackalloc char[value.Length];
|
Span<char> chars = stackalloc char[value.Length];
|
||||||
Encoding.UTF8.GetChars(value, chars);
|
Encoding.UTF8.GetChars(value, chars);
|
||||||
return double.Parse(chars.Trim());
|
return double.Parse(chars.Trim(), provider: CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ToInt32(this ReadOnlySpan<byte> value)
|
public static int ToInt32(this ReadOnlySpan<byte> value)
|
||||||
{
|
{
|
||||||
Span<char> chars = stackalloc char[value.Length];
|
Span<char> chars = stackalloc char[value.Length];
|
||||||
Encoding.UTF8.GetChars(value, chars);
|
Encoding.UTF8.GetChars(value, chars);
|
||||||
return int.Parse(chars.Trim());
|
return int.Parse(chars.Trim(), provider: CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float ToSingle(this ReadOnlySpan<byte> value)
|
public static float ToSingle(this ReadOnlySpan<byte> value)
|
||||||
{
|
{
|
||||||
Span<char> chars = stackalloc char[value.Length];
|
Span<char> chars = stackalloc char[value.Length];
|
||||||
Encoding.UTF8.GetChars(value, chars);
|
Encoding.UTF8.GetChars(value, chars);
|
||||||
return float.Parse(chars.Trim());
|
return float.Parse(chars.Trim(), provider: CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2 ToVector2(this ReadOnlySpan<byte> value)
|
public static Vector2 ToVector2(this ReadOnlySpan<byte> value)
|
||||||
|
@ -13,13 +13,13 @@ internal sealed class HexToColorConverter : ValueConverter<Color>
|
|||||||
Span<char> buffer = stackalloc char[2];
|
Span<char> buffer = stackalloc char[2];
|
||||||
|
|
||||||
reader.Read(buffer);
|
reader.Read(buffer);
|
||||||
int r = int.Parse(buffer, NumberStyles.HexNumber);
|
int r = int.Parse(buffer, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
reader.Read(buffer);
|
reader.Read(buffer);
|
||||||
int g = int.Parse(buffer, NumberStyles.HexNumber);
|
int g = int.Parse(buffer, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
reader.Read(buffer);
|
reader.Read(buffer);
|
||||||
int b = int.Parse(buffer, NumberStyles.HexNumber);
|
int b = int.Parse(buffer, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
result = Color.FromArgb(r, g, b);
|
result = Color.FromArgb(r, g, b);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace VpSharp.Internal.ValueConverters;
|
namespace VpSharp.Internal.ValueConverters;
|
||||||
|
|
||||||
#pragma warning disable CA1812
|
#pragma warning disable CA1812
|
||||||
@ -8,13 +10,13 @@ internal sealed class IntToEnumConverter<T> : ValueConverter<T>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Deserialize(TextReader reader, out T result)
|
public override void Deserialize(TextReader reader, out T result)
|
||||||
{
|
{
|
||||||
int value = int.Parse(reader.ReadToEnd());
|
int value = int.Parse(reader.ReadToEnd(), provider: CultureInfo.InvariantCulture);
|
||||||
result = (T)Convert.ChangeType(value, typeof(T));
|
result = (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Serialize(TextWriter writer, T value)
|
public override void Serialize(TextWriter writer, T value)
|
||||||
{
|
{
|
||||||
writer.Write(Convert.ToInt32(value));
|
writer.Write(Convert.ToInt32(value, CultureInfo.InvariantCulture));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ internal static class WorldSettingsConverter
|
|||||||
}
|
}
|
||||||
else if (propertyType.IsEnum && int.TryParse(value, out int result))
|
else if (propertyType.IsEnum && int.TryParse(value, out int result))
|
||||||
{
|
{
|
||||||
propertyValue = Convert.ChangeType(result, propertyType);
|
propertyValue = Convert.ChangeType(result, propertyType, CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user