mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-10 02:35:42 +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.Text;
|
||||
using Cysharp.Text;
|
||||
@ -288,7 +289,7 @@ public sealed class VirtualParadiseParticleEmitterObject : VirtualParadiseObject
|
||||
}
|
||||
else if (property.PropertyType != typeof(string))
|
||||
{
|
||||
value = Convert.ChangeType(value, property.PropertyType);
|
||||
value = Convert.ChangeType(value, property.PropertyType, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
property.SetValue(this, value);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Numerics;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using Cysharp.Text;
|
||||
using VpSharp.Extensions;
|
||||
@ -81,8 +82,8 @@ public sealed class VirtualParadisePathObject : VirtualParadiseObject
|
||||
int spaceIndex = chars[index..].IndexOf(' ');
|
||||
int newLineIndex = chars[index..].IndexOf('\n');
|
||||
|
||||
int pathType = int.Parse(chars[index..(index + spaceIndex)]);
|
||||
int closed = int.Parse(chars[(index + spaceIndex + 1)..(index + newLineIndex)]);
|
||||
int pathType = int.Parse(chars[index..(index + spaceIndex)], provider: CultureInfo.InvariantCulture);
|
||||
int closed = int.Parse(chars[(index + spaceIndex + 1)..(index + newLineIndex)], provider: CultureInfo.InvariantCulture);
|
||||
index += newLineIndex;
|
||||
|
||||
// points from here onwards
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using Cysharp.Text;
|
||||
@ -10,21 +11,21 @@ internal static class SpanExtensions
|
||||
{
|
||||
Span<char> chars = stackalloc char[value.Length];
|
||||
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)
|
||||
{
|
||||
Span<char> chars = stackalloc char[value.Length];
|
||||
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)
|
||||
{
|
||||
Span<char> chars = stackalloc char[value.Length];
|
||||
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)
|
||||
|
@ -13,13 +13,13 @@ internal sealed class HexToColorConverter : ValueConverter<Color>
|
||||
Span<char> buffer = stackalloc char[2];
|
||||
|
||||
reader.Read(buffer);
|
||||
int r = int.Parse(buffer, NumberStyles.HexNumber);
|
||||
int r = int.Parse(buffer, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||
|
||||
reader.Read(buffer);
|
||||
int g = int.Parse(buffer, NumberStyles.HexNumber);
|
||||
int g = int.Parse(buffer, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace VpSharp.Internal.ValueConverters;
|
||||
|
||||
#pragma warning disable CA1812
|
||||
@ -8,13 +10,13 @@ internal sealed class IntToEnumConverter<T> : ValueConverter<T>
|
||||
/// <inheritdoc />
|
||||
public override void Deserialize(TextReader reader, out T result)
|
||||
{
|
||||
int value = int.Parse(reader.ReadToEnd());
|
||||
result = (T)Convert.ChangeType(value, typeof(T));
|
||||
int value = int.Parse(reader.ReadToEnd(), provider: CultureInfo.InvariantCulture);
|
||||
result = (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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))
|
||||
{
|
||||
propertyValue = Convert.ChangeType(result, propertyType);
|
||||
propertyValue = Convert.ChangeType(result, propertyType, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user