remove some redundant\unused code

This commit is contained in:
John Colvin committed 2019-03-06 12:49:08 -06:00
1 parent cc0f6ea448
commit 23f76a1c80
3 files changed
+6 -29

No files matched your search

@@ -180,8 +180,8 @@ namespace mbts.spark {
public ObservableCollection<IAlgoSelector> 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
@@ -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<object, object, bool> _convert_del_backing;
Func<object, object, bool> _convert_del;
public IList Flags { get; } = new List<object>();
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<TEnum> : IValueConverter where TEnum : struct {
public IList<TEnum> Flags { get; } = new List<TEnum>();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
Flags.All(f => EnumHelper.has_flags<TEnum>(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<TEnum>(value), separator);
static bool _convert(int enum_int, IList<int> flags) =>
flags.All(f => (enum_int & f) == f);
}
}
+3 -10
View File
@@ -51,8 +51,8 @@ namespace mbts.ui.utility {
public static Func<object, object, bool> get_has_flags_delegate(Type enum_type) =>
EnumDescriptorStore.descriptor(enum_type).has_flags;
public static bool has_flags<T>(object value, object flags) where T : struct =>
EnumDescriptorStore<T>.descriptor.has_flags(value, flags);
public static bool has_flags<TEnum>(TEnum value, TEnum flags) =>
EnumDescriptorStore<TEnum>.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<TAttribute>() : null;
}
public static bool includes_flag<TEnum>(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<TEnum> split_flags<TEnum>(TEnum flags) where TEnum : struct {
@@ -243,4 +236,4 @@ namespace mbts.ui.utility {
}
public new T result => (T)(object)base.result;
}
}
}