From 2118bd59171fcc0523c6ca4a8f1551ed8abb18fd Mon Sep 17 00:00:00 2001 From: "Marcelo C." Date: Tue, 4 Mar 2025 09:23:53 -0300 Subject: [PATCH] Adding ParseIntOption --- Duplicati/Library/Utility/Utility.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Duplicati/Library/Utility/Utility.cs b/Duplicati/Library/Utility/Utility.cs index 038d3adad..5843328db 100644 --- a/Duplicati/Library/Utility/Utility.cs +++ b/Duplicati/Library/Utility/Utility.cs @@ -774,6 +774,18 @@ namespace Duplicati.Library.Utility return (T)(object)flags; } + + /// + /// Parses an option with int value, returning the default value if the option is not found or cannot be parsed + /// + /// The set of options to look for the setting in + /// The value to look for in the settings + /// default value + /// + public static int ParseIntOption(IReadOnlyDictionary options, string value, int @default) + { + return options.TryGetValue(value, out var opt) && int.TryParse(opt ?? string.Empty, out var result) ? result : @default; + } /// /// Converts a sequence of bytes to a hex string