Fix #5054: parse string to number with invariant culture.

This commit is contained in:
Ben
2025-02-10 16:23:41 +08:00
parent 189f8f1d27
commit 1aabb93f77
37 changed files with 109 additions and 76 deletions

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Oqtane.Shared
{
public sealed class SharedConverter
{
public static int ParseInteger(string value)
{
return ParseInteger(value, CultureInfo.InvariantCulture, 0);
}
public static int ParseInteger(string value, CultureInfo cultureInfo)
{
return ParseInteger(value, cultureInfo, 0);
}
public static int ParseInteger(string value, CultureInfo cultureInfo, int defaultValue)
{
if (int.TryParse(value, cultureInfo, out int result))
{
return result;
}
return 0;
}
}
}