2020-08-07 11:56:28 -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.
using System.Text.Json.Serialization ;
2024-04-02 01:09:47 +02:00
using System.Text.RegularExpressions ;
2020-08-07 11:56:28 -07:00
2020-10-22 09:45:48 -07:00
namespace Microsoft.PowerToys.Settings.UI.Library
2020-08-07 11:56:28 -07:00
{
2024-04-02 01:09:47 +02:00
public class GenericProperty < T > : ICmdLineRepresentable
2020-08-07 11:56:28 -07:00
{
[JsonPropertyName("value")]
public T Value { get ; set ; }
public GenericProperty ( T value )
{
Value = value ;
}
2022-09-28 18:18:55 +02:00
// Added a parameterless constructor because of an exception during deserialization. More details here: https://learn.microsoft.com/dotnet/standard/serialization/system-text-json-how-to#deserialization-behavior
2020-08-07 11:56:28 -07:00
public GenericProperty ( )
{
}
2024-04-02 01:09:47 +02:00
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "Adding ICmdLineRepresentable support")]
public static bool TryParseFromCmd ( string cmd , out object result )
{
result = null ;
if ( ICmdLineRepresentable . TryParseFromCmdFor ( typeof ( T ) , cmd , out var value ) )
{
result = new GenericProperty < T > { Value = ( T ) value } ;
return true ;
}
return false ;
}
public bool TryToCmdRepresentable ( out string result )
{
result = Value . ToString ( ) ;
return true ;
}
2020-08-07 11:56:28 -07:00
}
}