/ src / settings-ui / Settings.UI.Library / BoolProperty.cs
BoolProperty.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System.Text.Json;
 6  using System.Text.Json.Serialization;
 7  
 8  namespace Microsoft.PowerToys.Settings.UI.Library
 9  {
10      public record BoolProperty : ICmdLineRepresentable
11      {
12          public BoolProperty()
13          {
14              Value = false;
15          }
16  
17          public BoolProperty(bool value)
18          {
19              Value = value;
20          }
21  
22          [JsonPropertyName("value")]
23          public bool Value { get; set; }
24  
25          public static bool TryParseFromCmd(string cmd, out object result)
26          {
27              result = null;
28  
29              if (!bool.TryParse(cmd, out bool value))
30              {
31                  return false;
32              }
33  
34              result = new BoolProperty { Value = value };
35              return true;
36          }
37  
38          public override string ToString()
39          {
40              return JsonSerializer.Serialize(this, SettingsSerializationContext.Default.BoolProperty);
41          }
42  
43          public bool TryToCmdRepresentable(out string result)
44          {
45              result = Value.ToString();
46              return true;
47          }
48      }
49  }