diff --git a/BrightSharp/BrightSharp.csproj b/BrightSharp/BrightSharp.csproj index 6eb908c..fbc7bb7 100644 --- a/BrightSharp/BrightSharp.csproj +++ b/BrightSharp/BrightSharp.csproj @@ -34,6 +34,42 @@ 4 false + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + @@ -60,6 +96,7 @@ + diff --git a/BrightSharp/Converters/IntToValueConverter.cs b/BrightSharp/Converters/IntToValueConverter.cs new file mode 100644 index 0000000..514a350 --- /dev/null +++ b/BrightSharp/Converters/IntToValueConverter.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections; +using System.Globalization; +using System.Windows.Data; + +namespace BrightSharp.Converters +{ + public class IntToValueConverter : IValueConverter + { + public ulong? TrueValueInt { get; set; } = null; + public ulong? FalseValueInt { get; set; } = 0; + + + public object TrueValue { get; set; } = true; + public object FalseValue { get; set; } = false; + + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + { + value = false; + } + if (value is string valueStr) + { + value = valueStr.Length > 0; + } + if (value is bool valueBool) + { + value = valueBool ? 1 : 0; + } + if (value is ICollection valueCol) + { + value = valueCol.Count; + } + if (value is Enum en) + { + value = System.Convert.ToInt32(en); + } + if (ulong.TryParse(value.ToString(), out ulong valueLong)) + { + // Exact match for false + if (FalseValueInt.HasValue && FalseValueInt == valueLong) return FalseValue; + // Exact match for true + if (TrueValueInt.HasValue && TrueValueInt == valueLong) return TrueValue; + // Any value for false + if (!FalseValueInt.HasValue) return FalseValue; + // Any value for true + if (!TrueValueInt.HasValue) return TrueValue; + } + return TrueValue; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + // Convert with potential lose exact value match + return Equals(value, TrueValue) ? TrueValueInt : FalseValueInt; + } + } +} diff --git a/BrightSharp/Themes/Style.DevLab.xaml b/BrightSharp/Themes/Style.DevLab.xaml index 4b18e87..429b83c 100644 --- a/BrightSharp/Themes/Style.DevLab.xaml +++ b/BrightSharp/Themes/Style.DevLab.xaml @@ -17,7 +17,7 @@ Red - +