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.
35 lines
992 B
35 lines
992 B
1 year ago
|
using System;
|
||
|
using System.Globalization;
|
||
|
using Avalonia.Data.Converters;
|
||
|
|
||
|
namespace StabilityMatrix.Avalonia.Converters;
|
||
|
|
||
|
public class LaunchOptionIntDoubleConverter : IValueConverter
|
||
|
{
|
||
|
// Convert from int to double
|
||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
{
|
||
|
if (targetType == typeof(double?))
|
||
|
{
|
||
|
if (value == null)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
return System.Convert.ToDouble(value);
|
||
|
}
|
||
|
|
||
|
throw new ArgumentException($"Unsupported type {targetType}");
|
||
|
}
|
||
|
|
||
|
// Convert from double to object int (floor)
|
||
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
{
|
||
|
if (targetType == typeof(int?) || targetType == typeof(object))
|
||
|
{
|
||
|
return System.Convert.ToInt32(value);
|
||
|
}
|
||
|
|
||
|
throw new ArgumentException($"Unsupported type {targetType}");
|
||
|
}
|
||
|
}
|