steam-deck-tools/SteamController/ProfilesSettings/Helpers/ProfilesStringConverter.cs
2023-05-21 18:03:00 +02:00

36 lines
1.1 KiB
C#

using System.ComponentModel;
using System.Globalization;
namespace SteamController.ProfilesSettings.Helpers
{
internal class ProfileStringConverter : TypeConverter
{
public static List<Profiles.Profile> Profiles = new List<Profiles.Profile>();
private volatile StandardValuesCollection? collection;
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
{
return collection ??= new StandardValuesCollection(Profiles.
Where((profile) => profile.Visible).
Select((profile) => profile.Name).
ToArray());
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
{
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
{
return true;
}
public override bool IsValid(ITypeDescriptorContext? context, object? value)
{
return Profiles.Find((profile) => profile.Name == value?.ToString()) is not null;
}
}
}