Skip to content

Commit

Permalink
fix: Use InvariantCulture for int.TryParse calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jan 5, 2024
1 parent 4ab293f commit e13d08d
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ int GetResourcesVersion()
{
if (versionMember.Value?.ToString()?.TrimStart("Version") is { } versionString)
{
if (int.TryParse(versionString, out var explicitVersion))
if (int.TryParse(versionString, CultureInfo.InvariantCulture, out var explicitVersion))
{
if (explicitVersion < 1 || explicitVersion > XamlConstants.MaxFluentResourcesVersion)
{
Expand Down
3 changes: 2 additions & 1 deletion src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -110,7 +111,7 @@ private void ProcessContentItems(ITaskItem[] assets, Func<ResourceCandidate, str
{
var resourceCandidate = ResourceCandidate.Parse(fullPath, relativePath);

if (!UseHighDPIResources && int.TryParse(resourceCandidate.GetQualifierValue("scale"), out var scale) && scale > HighDPIThresholdScale)
if (!UseHighDPIResources && int.TryParse(resourceCandidate.GetQualifierValue("scale"), CultureInfo.InvariantCulture, out var scale) && scale > HighDPIThresholdScale)
{
Log.LogMessage($"Skipping '{asset.ItemSpec}' of scale {scale} because {nameof(UseHighDPIResources)} is false.");
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.RemoteControl.VS/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private int GetDotnetMajorVersion()

if (result.output.Contains("."))
{
if (int.TryParse(result.output.Substring(0, result.output.IndexOf('.')), out int majorVersion))
if (int.TryParse(result.output.Substring(0, result.output.IndexOf('.')), CultureInfo.InvariantCulture, out int majorVersion))
{
return majorVersion;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UI/Controls/BindableImageView.Android.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Android.Animation;
Expand Down Expand Up @@ -245,7 +246,7 @@ private void OnUriSourceChanged()
{
int resourceId;

if (int.TryParse(UriSource.Replace("res:///", ""), out resourceId))
if (int.TryParse(UriSource.Replace("res:///", ""), CultureInfo.InvariantCulture, out resourceId))
{
SetImageResource(resourceId);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,19 +1069,19 @@ private void OnHexTextChanging(TextBox sender, TextBoxTextChangingEventArgs args
private Rgb GetRgbColorFromTextBoxes()
{
// Uno Doc: There is no drop-in C# equivalent for the C++ '_wtoi' function; therefore, this code is re-written.
_ = int.TryParse(m_redTextBox?.Text, out int redValue);
_ = int.TryParse(m_greenTextBox?.Text, out int greenValue);
_ = int.TryParse(m_blueTextBox?.Text, out int blueValue);
_ = int.TryParse(m_redTextBox?.Text, CultureInfo.InvariantCulture, out int redValue);
_ = int.TryParse(m_greenTextBox?.Text, CultureInfo.InvariantCulture, out int greenValue);
_ = int.TryParse(m_blueTextBox?.Text, CultureInfo.InvariantCulture, out int blueValue);

return new Rgb(redValue / 255.0, greenValue / 255.0, blueValue / 255.0);
}

private Hsv GetHsvColorFromTextBoxes()
{
// Uno Doc: There is no drop-in C# equivalent for the C++ '_wtoi' function; therefore, this code is re-written.
_ = int.TryParse(m_hueTextBox?.Text, out int hueValue);
_ = int.TryParse(m_saturationTextBox?.Text, out int saturationValue);
_ = int.TryParse(m_valueTextBox?.Text, out int valueValue);
_ = int.TryParse(m_hueTextBox?.Text, CultureInfo.InvariantCulture, out int hueValue);
_ = int.TryParse(m_saturationTextBox?.Text, CultureInfo.InvariantCulture, out int saturationValue);
_ = int.TryParse(m_valueTextBox?.Text, CultureInfo.InvariantCulture, out int valueValue);

return new Hsv(hueValue, saturationValue / 100.0, valueValue / 100.0);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UI/UI/Xaml/UIElement.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -637,7 +638,7 @@ private static KeyRoutedEventArgs PayloadToKeyArgs(object src, string payload)

private static RoutedEventArgs PayloadToFocusArgs(object src, string payload)
{
if (int.TryParse(payload, out int xamlHandle))
if (int.TryParse(payload, CultureInfo.InvariantCulture, out int xamlHandle))
{
if (GetElementFromHandle(xamlHandle) is UIElement element)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable

using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Android.App;
Expand Down Expand Up @@ -302,7 +303,7 @@ private static void ReadAddresses(Contact contact, string lookupKey, ContentReso

private static ContactPhoneKind TypeToContactPhoneKind(string? type)
{
if (int.TryParse(type, out var typeInt))
if (int.TryParse(type, CultureInfo.InvariantCulture, out var typeInt))
{
if (Enum.IsDefined(typeof(PhoneDataKind), typeInt))
{
Expand Down Expand Up @@ -330,7 +331,7 @@ private static ContactPhoneKind TypeToContactPhoneKind(string? type)

private static ContactEmailKind TypeToContactEmailKind(string? type)
{
if (int.TryParse(type, out var typeInt))
if (int.TryParse(type, CultureInfo.InvariantCulture, out var typeInt))
{
if (Enum.IsDefined(typeof(EmailDataKind), typeInt))
{
Expand All @@ -349,7 +350,7 @@ private static ContactEmailKind TypeToContactEmailKind(string? type)

private static ContactAddressKind TypeToContactAddressKind(string? type)
{
if (int.TryParse(type, out var typeInt))
if (int.TryParse(type, CultureInfo.InvariantCulture, out var typeInt))
{
if (Enum.IsDefined(typeof(AddressDataKind), typeInt))
{
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UWP/Helpers/AndroidResourceNameEncoder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable

using System;
using System.Globalization;
using System.Linq;

namespace Uno
Expand Down Expand Up @@ -33,7 +34,7 @@ public static string Encode(string key)
key = new string(charArray);

//Checks if the keys are starting by a number because they are invalid in C#
if (key.Length > 0 && int.TryParse(key.Substring(0, 1), out _))
if (key.Length > 0 && int.TryParse(key.Substring(0, 1), CultureInfo.InvariantCulture, out _))
{
key = $"{NumberPrefix}{key}";
}
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UWP/Storage/Pickers/FileOpenPicker.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -141,7 +142,7 @@ private async Task<FilePickerSelectedFilesArray> UploadPickerPickFilesAsync(bool

var fileCountString = await NativeMethods.UploadPickFilesAsync(multiple, targetFolder.FullName, BuildAcceptString());

if (int.TryParse(fileCountString, out var fileCount))
if (int.TryParse(fileCountString, CultureInfo.InvariantCulture, out var fileCount))
{
var files = targetFolder
.GetFiles()
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/System/Profile/AnalyticsVersionInfo.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ partial void Initialize()
{
DeviceFamily = $"{OsName}.{AnalyticsInfo.DeviceForm}";
var versionString = Build.VERSION.Release;
if (int.TryParse(versionString, out var intVersion))
if (int.TryParse(versionString, CultureInfo.InvariantCulture, out var intVersion))
{
versionString = $"{intVersion}.0.0.0";
}
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UWP/UI/Notifications/BadgeUpdater.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable

using System.Globalization;
using UIKit;
using Windows.Data.Xml.Dom;

Expand All @@ -9,7 +10,7 @@ public partial class BadgeUpdater
{
partial void SetBadge(string? value)
{
if (value != null && int.TryParse(value, out var badgeNumber))
if (value != null && int.TryParse(value, CultureInfo.InvariantCulture, out var badgeNumber))
{
UIApplication.SharedApplication.ApplicationIconBadgeNumber = badgeNumber;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UWP/UI/Notifications/BadgeUpdater.skia.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable

using System.Globalization;
using Uno.Foundation.Extensibility;
using Uno.UI.Notifications;

Expand All @@ -16,7 +17,7 @@ partial void InitPlatform()

partial void SetBadge(string? value)
{
if (int.TryParse(value, out var numericValue))
if (int.TryParse(value, CultureInfo.InvariantCulture, out var numericValue))
{
_badgeUpdaterExtension?.SetBadge(numericValue);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UWP/UI/Notifications/BadgeUpdater.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable

using System.Globalization;
using Uno.Foundation;

using NativeMethods = __Windows.UI.Notifications.BadgeUpdater.NativeMethods;
Expand All @@ -10,7 +11,7 @@ public partial class BadgeUpdater
{
partial void SetBadge(string? value)
{
if (int.TryParse(value, out var number))
if (int.TryParse(value, CultureInfo.InvariantCulture, out var number))
{
NativeMethods.SetNumber(number);
}
Expand Down

0 comments on commit e13d08d

Please sign in to comment.