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.
|
|
|
|
|
|
|
2023-05-15 23:32:26 +01:00
|
|
|
|
using System;
|
2024-04-02 01:09:47 +02:00
|
|
|
|
using System.Globalization;
|
2020-04-07 10:19:14 -07:00
|
|
|
|
using System.Text.Json;
|
2020-04-16 11:45:27 -07:00
|
|
|
|
using System.Text.Json.Serialization;
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
2020-10-22 09:45:48 -07:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
2020-04-07 10:19:14 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Represents the configuration property of the settings that store Integer type.
|
2024-04-02 01:09:47 +02:00
|
|
|
|
public record IntProperty : ICmdLineRepresentable
|
2020-04-07 10:19:14 -07:00
|
|
|
|
{
|
2020-04-16 11:45:27 -07:00
|
|
|
|
public IntProperty()
|
|
|
|
|
|
{
|
2020-08-19 15:59:10 -07:00
|
|
|
|
Value = 0;
|
2020-04-16 11:45:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-26 17:34:03 -07:00
|
|
|
|
public IntProperty(int value)
|
|
|
|
|
|
{
|
|
|
|
|
|
Value = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-07 10:19:14 -07:00
|
|
|
|
// Gets or sets the integer value of the settings configuration.
|
2020-04-16 11:45:27 -07:00
|
|
|
|
[JsonPropertyName("value")]
|
|
|
|
|
|
public int Value { get; set; }
|
2020-04-07 10:19:14 -07:00
|
|
|
|
|
2024-04-02 01:09:47 +02:00
|
|
|
|
public static bool TryParseFromCmd(string cmd, out object result)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (!int.TryParse(cmd, out var value))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = new IntProperty { Value = value };
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-07 10:19:14 -07:00
|
|
|
|
// Returns a JSON version of the class settings configuration class.
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
2025-12-02 16:31:02 +08:00
|
|
|
|
return JsonSerializer.Serialize(this, SettingsSerializationContext.Default.IntProperty);
|
2020-04-07 10:19:14 -07:00
|
|
|
|
}
|
2023-05-15 23:32:26 +01:00
|
|
|
|
|
|
|
|
|
|
public static implicit operator IntProperty(int v)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static implicit operator IntProperty(uint v)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2024-04-02 01:09:47 +02:00
|
|
|
|
|
|
|
|
|
|
public bool TryToCmdRepresentable(out string result)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = Value.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2020-04-07 10:19:14 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|