From a29eaa2618bbfc8c294954e2ef4f0b68c2b4259b Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 11 May 2019 12:25:38 -0500 Subject: [PATCH] EnumCaseStringConverter - cleanup code style/syntax --- .../EnumConverters/EnumCaseStringConverter.cs | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/client/spark/view/Converters/EnumConverters/EnumCaseStringConverter.cs b/src/client/spark/view/Converters/EnumConverters/EnumCaseStringConverter.cs index b267e2d86..696313310 100644 --- a/src/client/spark/view/Converters/EnumConverters/EnumCaseStringConverter.cs +++ b/src/client/spark/view/Converters/EnumConverters/EnumCaseStringConverter.cs @@ -1,28 +1,15 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Data; -namespace mbts.ui.converters -{ - public class EnumCaseStringConverter : IValueConverter where T : struct - { +namespace mbts.ui.converters { + class EnumCaseStringConverter : IValueConverter where T : struct { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { - T t = default(T); - if (value is T) - t = (T)value; - string raw_str = t.ToString(); - return raw_str.Substring(0, 1) + new String(raw_str.Skip(1).Select(Char.ToLower).ToLArray()); + string raw_str = (value is T t ? t : default).ToString(); + return raw_str.Substring(0, 1) + new string(raw_str.Skip(1).Select(char.ToLower).ToArray()); } - public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { - T t = default(T); - string str = value as string; - if (str != null) - Enum.TryParse(str, true, out t); - return t; - } + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) => + value is string str && Enum.TryParse(str, true, out T result) ? result : default; } -} +} \ No newline at end of file