/ src / settings-ui / Settings.UI.Library / StringProperty.cs
StringProperty.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      // Represents the configuration property of the settings that store string type.
11      public record StringProperty : ICmdLineRepresentable
12      {
13          public StringProperty()
14          {
15              Value = string.Empty;
16          }
17  
18          public StringProperty(string value)
19          {
20              Value = value;
21          }
22  
23          // Gets or sets the integer value of the settings configuration.
24          [JsonPropertyName("value")]
25          public string Value { get; set; }
26  
27          // Returns a JSON version of the class settings configuration class.
28          public override string ToString()
29          {
30              return JsonSerializer.Serialize(this, SettingsSerializationContext.Default.StringProperty);
31          }
32  
33          public static StringProperty ToStringProperty(string v)
34          {
35              return new StringProperty(v);
36          }
37  
38          public static bool TryParseFromCmd(string cmd, out object result)
39          {
40              result = new StringProperty(cmd);
41              return true;
42          }
43  
44          public bool TryToCmdRepresentable(out string result)
45          {
46              result = Value;
47              return true;
48          }
49  
50          public static implicit operator StringProperty(string v)
51          {
52              return new StringProperty(v);
53          }
54      }
55  }