Multiprocotol Terminalprogram (BAT)
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.
MultiTerm/MultiTerm.Wpf/ValueConverters/IntToStringConverter.cs

30 lines
909 B

using System;
using System.Globalization;
using System.Windows.Data;
namespace MultiTerm.Wpf.ValueConverters;
public class IntToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// guard type
if(value is not int integerVal) { throw new ArgumentException("Can only convert from integer value"); }
return integerVal.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// guard type
if (value is not string stringVal) { throw new ArgumentException("Can only convert from string value"); }
// try parsing to int
int parsedVal;
if(int.TryParse(stringVal, out parsedVal) == false)
{
// error
parsedVal = -1;
}
return parsedVal;
}
}