Multi-Platform Package Manager for Stable Diffusion
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
using System;
|
|
|
|
using System.Globalization;
|
|
|
|
using Avalonia.Data.Converters;
|
|
|
|
|
|
|
|
namespace StabilityMatrix.Avalonia.Converters;
|
|
|
|
|
|
|
|
public class LaunchOptionConverter : IValueConverter
|
|
|
|
{
|
|
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
{
|
|
|
|
if (targetType == typeof(string))
|
|
|
|
{
|
|
|
|
return value?.ToString() ?? "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetType == typeof(bool?))
|
|
|
|
{
|
|
|
|
return bool.TryParse(value?.ToString(), out var boolValue) && boolValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetType == typeof(double?))
|
|
|
|
{
|
|
|
|
if (value == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return double.TryParse(value.ToString(), out var doubleValue) ? doubleValue : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetType == typeof(int?))
|
|
|
|
{
|
|
|
|
if (value == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return int.TryParse(value.ToString(), out var intValue) ? intValue : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ArgumentException("Unsupported type");
|
|
|
|
}
|
|
|
|
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|