From 24a2bb6d49021953bdfb1cfb3a52c3f4f87bae6e Mon Sep 17 00:00:00 2001 From: IvenBach Date: Mon, 20 Nov 2017 18:40:38 -0800 Subject: [PATCH] Revert overeager pattern matching --- .../DeclarationTypeToStringConverter.cs | 8 ++-- RetailCoder.VBE/UI/Controls/MenuItemGroup.cs | 42 +++++++++---------- .../InspectionImageSourceConverter.cs | 3 +- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/RetailCoder.VBE/UI/Controls/DeclarationTypeToStringConverter.cs b/RetailCoder.VBE/UI/Controls/DeclarationTypeToStringConverter.cs index 79f3007da2..1cde046240 100644 --- a/RetailCoder.VBE/UI/Controls/DeclarationTypeToStringConverter.cs +++ b/RetailCoder.VBE/UI/Controls/DeclarationTypeToStringConverter.cs @@ -9,13 +9,13 @@ public class DeclarationTypeToStringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (!(value is DeclarationType type)) + if (value is DeclarationType type) { - return null; + var text = RubberduckUI.ResourceManager.GetString("DeclarationType_" + type, CultureInfo.CurrentUICulture) ?? string.Empty; + return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text); } - var text = RubberduckUI.ResourceManager.GetString("DeclarationType_" + type, CultureInfo.CurrentUICulture) ?? string.Empty; - return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text); + return null; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/RetailCoder.VBE/UI/Controls/MenuItemGroup.cs b/RetailCoder.VBE/UI/Controls/MenuItemGroup.cs index 5fcbed7555..06a35c570d 100644 --- a/RetailCoder.VBE/UI/Controls/MenuItemGroup.cs +++ b/RetailCoder.VBE/UI/Controls/MenuItemGroup.cs @@ -31,33 +31,31 @@ private static void OnGroupNameChanged(DependencyObject d, DependencyPropertyCha { //Add an entry to the group name collection - if (!(d is MenuItem menuItem)) + if (d is MenuItem menuItem) { - return; - } - - var newGroupName = e.NewValue.ToString(); - var oldGroupName = e.OldValue.ToString(); - if (string.IsNullOrEmpty(newGroupName)) - { - //Removing the toggle button from grouping - RemoveCheckboxFromGrouping(menuItem); - } - else - { - //Switching to a new group - if (newGroupName == oldGroupName) + var newGroupName = e.NewValue.ToString(); + var oldGroupName = e.OldValue.ToString(); + if (string.IsNullOrEmpty(newGroupName)) { - return; + //Removing the toggle button from grouping + RemoveCheckboxFromGrouping(menuItem); } - - if (!string.IsNullOrEmpty(oldGroupName)) + else { - //Remove the old group mapping - RemoveCheckboxFromGrouping(menuItem); + //Switching to a new group + if (newGroupName == oldGroupName) + { + return; + } + + if (!string.IsNullOrEmpty(oldGroupName)) + { + //Remove the old group mapping + RemoveCheckboxFromGrouping(menuItem); + } + ElementToGroupNames.Add(menuItem, e.NewValue.ToString()); + menuItem.Checked += MenuItemChecked; } - ElementToGroupNames.Add(menuItem, e.NewValue.ToString()); - menuItem.Checked += MenuItemChecked; } } diff --git a/RetailCoder.VBE/UI/Inspections/InspectionImageSourceConverter.cs b/RetailCoder.VBE/UI/Inspections/InspectionImageSourceConverter.cs index 8e9e50aa84..7d8a66264c 100644 --- a/RetailCoder.VBE/UI/Inspections/InspectionImageSourceConverter.cs +++ b/RetailCoder.VBE/UI/Inspections/InspectionImageSourceConverter.cs @@ -9,7 +9,8 @@ public class InspectionImageSourceConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (!(value is IInspection inspection)) + var inspection = value as IInspection; + if (inspection == null ) { return null; }