From 23f76a1c80d166a6d675345bdf93e4e835be971a Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 6 Mar 2019 12:47:50 -0600 Subject: [PATCH] remove some redundant\unused code --- .../Orders/OrderTypeVMs/OrderTypeVMFactory.cs | 4 ++-- .../EnumConverters/EnumHasFlagConverter.cs | 18 +----------------- src/client/spark/view/Utility/EnumHelper.cs | 13 +++---------- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs b/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs index 4201ef8f4..953a943f2 100644 --- a/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs +++ b/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs @@ -180,8 +180,8 @@ namespace mbts.spark { public ObservableCollection child_algo_selectors => _child_algo_selectors; // editing permissions public AlgoEditingPermissions editing_permissions { get; private set; } - public bool can_edit_values => EnumHelper.includes_flag(editing_permissions, AlgoEditingPermissions.AllowEditValues); - public bool can_edit_structure => EnumHelper.includes_flag(editing_permissions, AlgoEditingPermissions.AllowEditStructure); + public bool can_edit_values => EnumHelper.has_flags(editing_permissions, AlgoEditingPermissions.AllowEditValues); + public bool can_edit_structure => EnumHelper.has_flags(editing_permissions, AlgoEditingPermissions.AllowEditStructure); public bool can_save_values => _can_save_values.Value; public bool can_save_structure => _can_save_structure.Value; // misc diff --git a/src/client/spark/view/Converters/EnumConverters/EnumHasFlagConverter.cs b/src/client/spark/view/Converters/EnumConverters/EnumHasFlagConverter.cs index 4f54bd32f..e547fad19 100644 --- a/src/client/spark/view/Converters/EnumConverters/EnumHasFlagConverter.cs +++ b/src/client/spark/view/Converters/EnumConverters/EnumHasFlagConverter.cs @@ -3,13 +3,12 @@ using System; using System.Collections; using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Windows.Data; namespace mbts.ui.converters { class EnumFlagsToBooleanConverter : IValueConverter { - //Func _convert_del_backing; Func _convert_del; + public IList Flags { get; } = new List(); public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { @@ -27,19 +26,4 @@ namespace mbts.ui.converters { } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } - - class EnumFlagsToBooleanConverter : IValueConverter where TEnum : struct { - public IList Flags { get; } = new List(); - - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => - Flags.All(f => EnumHelper.has_flags(value, f)); - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); - - static string _convert(object value, string separator) => - _convert(ConvertUtils.try_convert(value), separator); - - static bool _convert(int enum_int, IList flags) => - flags.All(f => (enum_int & f) == f); - } } \ No newline at end of file diff --git a/src/client/spark/view/Utility/EnumHelper.cs b/src/client/spark/view/Utility/EnumHelper.cs index 5147aaa7d..71af68b02 100644 --- a/src/client/spark/view/Utility/EnumHelper.cs +++ b/src/client/spark/view/Utility/EnumHelper.cs @@ -51,8 +51,8 @@ namespace mbts.ui.utility { public static Func get_has_flags_delegate(Type enum_type) => EnumDescriptorStore.descriptor(enum_type).has_flags; - public static bool has_flags(object value, object flags) where T : struct => - EnumDescriptorStore.descriptor.has_flags(value, flags); + public static bool has_flags(TEnum value, TEnum flags) => + EnumDescriptorStore.descriptor.has_flags(value, flags); public static string get_display_name(object enum_obj, TextCapitalizationFormat capitalization_format = TextCapitalizationFormat.Default) { string str = enum_obj.ToString(); @@ -71,13 +71,6 @@ namespace mbts.ui.utility { return mi.Length > 0 ? mi[0].GetCustomAttribute() : null; } - public static bool includes_flag(TEnum flags, TEnum value) { - if (!typeof(TEnum).IsEnum) throw new InvalidOperationException("Type is not an Enum."); - long lflags = Convert.ToInt64(flags); - long lvalue = Convert.ToInt64(value); - return (lflags & lvalue) == lvalue; - } - // though it isn't hard to write "flags & TEnum.Foo != 0," split_flags offers a less error-prone alternative in terms of typeos. // (less likely that code calling this method will have a typeo, than code checking flags in the traditional manner described above) public static IEnumerable split_flags(TEnum flags) where TEnum : struct { @@ -243,4 +236,4 @@ namespace mbts.ui.utility { } public new T result => (T)(object)base.result; } -} +} \ No newline at end of file