From 388222c5c726edfe7c370c17ece28323670f0ed6 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 7 Jul 2023 20:35:14 +0100 Subject: [PATCH] Remove Exts.WithDefault --- OpenRA.Game/Exts.cs | 6 ------ OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 1bb45d548b8b..3186fbbfff5e 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -32,12 +32,6 @@ public static string FormatCurrent(this string format, params object[] args) return string.Format(CultureInfo.CurrentCulture, format, args); } - public static T WithDefault(T def, Func f) - { - try { return f(); } - catch { return def; } - } - public static Lazy Lazy(Func p) { return new Lazy(p); } public static IEnumerable GetNamespaces(this Assembly a) diff --git a/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs index 2a360212b76f..cbc32386fcd0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs @@ -46,7 +46,8 @@ public DirectConnectLogic(Widget widget, Action onExit, Action openLobby, Connec joinButton.OnClick = () => { - var port = Exts.WithDefault(1234, () => int.Parse(portField.Text, NumberFormatInfo.CurrentInfo)); + if (!int.TryParse(portField.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out var port)) + port = 1234; Game.Settings.Player.LastServer = $"{ipField.Text}:{port}"; Game.Settings.Save();