Re-implement changes in the previous commit

This commit is contained in:
Tyrrrz
2023-03-23 13:23:32 +02:00
parent 20e782e6ed
commit 2e1636e6c9
2 changed files with 30 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
using System;
using System.Globalization;
using CliFx.Extensibility;
namespace DiscordChatExporter.Cli.Commands.Converters;
internal class TruthyBooleanBindingConverter : BindingConverter<bool>
{
public override bool Convert(string? rawValue)
{
// Null is still considered true, to match the base behavior
if (rawValue is null)
return true;
if (string.IsNullOrWhiteSpace(rawValue))
return false;
if (bool.TryParse(rawValue, out var boolValue))
return boolValue;
if (int.TryParse(rawValue, CultureInfo.InvariantCulture, out var intValue) && intValue == 0)
return false;
return true;
}
}