2020-04-07 10:19:14 -07:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
2020-04-02 06:08:56 -07:00
|
|
|
|
using System.Text.Json;
|
2020-04-16 11:45:27 -07:00
|
|
|
|
using System.Text.Json.Serialization;
|
2020-04-02 06:08:56 -07:00
|
|
|
|
|
2020-10-22 09:45:48 -07:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
2020-04-02 06:08:56 -07:00
|
|
|
|
{
|
2024-04-02 01:09:47 +02:00
|
|
|
|
public record BoolProperty : ICmdLineRepresentable
|
2020-04-02 06:08:56 -07:00
|
|
|
|
{
|
2020-04-16 11:45:27 -07:00
|
|
|
|
public BoolProperty()
|
|
|
|
|
|
{
|
2020-08-19 15:59:10 -07:00
|
|
|
|
Value = false;
|
2020-04-16 11:45:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-26 17:34:03 -07:00
|
|
|
|
public BoolProperty(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
Value = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("value")]
|
|
|
|
|
|
public bool Value { get; set; }
|
2020-04-02 06:08:56 -07:00
|
|
|
|
|
2024-04-02 01:09:47 +02:00
|
|
|
|
public static bool TryParseFromCmd(string cmd, out object result)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (!bool.TryParse(cmd, out bool value))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = new BoolProperty { Value = value };
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-02 06:08:56 -07:00
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
2025-12-02 16:31:02 +08:00
|
|
|
|
return JsonSerializer.Serialize(this, SettingsSerializationContext.Default.BoolProperty);
|
2020-04-02 06:08:56 -07:00
|
|
|
|
}
|
2024-04-02 01:09:47 +02:00
|
|
|
|
|
|
|
|
|
|
public bool TryToCmdRepresentable(out string result)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = Value.ToString();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2020-04-02 06:08:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|