From 7a4548bf8255135456267f85e1a6223a7e2e9cda Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Tue, 12 Jul 2016 16:31:46 +0200 Subject: [PATCH] Fix some R# nags. --- Gu.Wpf.NumericInput.UITests/Helpers/Info.cs | 1 + Gu.Wpf.NumericInput.sln.DotSettings | 1 + .../Boxes/BaseBoxes/BaseBox.cs | 2 +- .../{IIncrementBox.cs => ISpinnerBox.cs} | 4 ++- .../Boxes/BaseBoxes/NumericBox{T}.cs | 2 +- Gu.Wpf.NumericInput/Boxes/NumericBox.Keys.cs | 1 + .../ErrorContentToStringConverter.cs | 34 +++++++++++++++++++ .../Gu.Wpf.NumericInput.csproj | 7 ++-- .../WeakRoutedEventManager.generated.cs | 1 - .../Internals/WeakRoutedEventManager.tt | 9 +++-- .../Spinners/SpinnerDecorator.cs | 8 ++--- Gu.Wpf.NumericInput/Themes/Validation.xaml | 4 +-- .../Validation/ValidationRules/CanParse.cs | 2 ++ .../IsGreaterThanOrEqualToMinRule.cs | 2 ++ .../IsLessThanOrEqualToMaxRule.cs | 2 ++ .../ValidationRules/RegexValidationRule.cs | 2 ++ 16 files changed, 65 insertions(+), 17 deletions(-) rename Gu.Wpf.NumericInput/Boxes/BaseBoxes/{IIncrementBox.cs => ISpinnerBox.cs} (70%) create mode 100644 Gu.Wpf.NumericInput/Converters/ErrorContentToStringConverter.cs diff --git a/Gu.Wpf.NumericInput.UITests/Helpers/Info.cs b/Gu.Wpf.NumericInput.UITests/Helpers/Info.cs index 2183d48a..df4efe5b 100644 --- a/Gu.Wpf.NumericInput.UITests/Helpers/Info.cs +++ b/Gu.Wpf.NumericInput.UITests/Helpers/Info.cs @@ -19,6 +19,7 @@ public static ProcessStartInfo ProcessStartInfo var workingDirectory = System.IO.Path.GetDirectoryName(fileName); var processStartInfo = new ProcessStartInfo { + // ReSharper disable once AssignNullToNotNullAttribute WorkingDirectory = workingDirectory, FileName = fileName, //UseShellExecute = false, diff --git a/Gu.Wpf.NumericInput.sln.DotSettings b/Gu.Wpf.NumericInput.sln.DotSettings index 40fc2240..8d440823 100644 --- a/Gu.Wpf.NumericInput.sln.DotSettings +++ b/Gu.Wpf.NumericInput.sln.DotSettings @@ -7,6 +7,7 @@ True True <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> diff --git a/Gu.Wpf.NumericInput/Boxes/BaseBoxes/BaseBox.cs b/Gu.Wpf.NumericInput/Boxes/BaseBoxes/BaseBox.cs index b87a788a..8b2530a0 100644 --- a/Gu.Wpf.NumericInput/Boxes/BaseBoxes/BaseBox.cs +++ b/Gu.Wpf.NumericInput/Boxes/BaseBoxes/BaseBox.cs @@ -11,7 +11,7 @@ /// public abstract partial class BaseBox : TextBox { - private static readonly RoutedEventHandler LoadedHandler = new RoutedEventHandler(OnLoaded); + private static readonly RoutedEventHandler LoadedHandler = OnLoaded; // this is only used to create the binding expression needed for Validator private static readonly Binding ValidationBinding = new Binding { Mode = BindingMode.OneTime, Source = string.Empty, NotifyOnValidationError = true }; diff --git a/Gu.Wpf.NumericInput/Boxes/BaseBoxes/IIncrementBox.cs b/Gu.Wpf.NumericInput/Boxes/BaseBoxes/ISpinnerBox.cs similarity index 70% rename from Gu.Wpf.NumericInput/Boxes/BaseBoxes/IIncrementBox.cs rename to Gu.Wpf.NumericInput/Boxes/BaseBoxes/ISpinnerBox.cs index 04ad5328..9a7fe604 100644 --- a/Gu.Wpf.NumericInput/Boxes/BaseBoxes/IIncrementBox.cs +++ b/Gu.Wpf.NumericInput/Boxes/BaseBoxes/ISpinnerBox.cs @@ -2,10 +2,12 @@ { using System.Windows.Input; - public interface IIncrementBox + public interface ISpinnerBox { ICommand IncreaseCommand { get; } ICommand DecreaseCommand { get; } + + bool AllowSpinners { get; } } } \ No newline at end of file diff --git a/Gu.Wpf.NumericInput/Boxes/BaseBoxes/NumericBox{T}.cs b/Gu.Wpf.NumericInput/Boxes/BaseBoxes/NumericBox{T}.cs index 0ccb3c79..9338a322 100644 --- a/Gu.Wpf.NumericInput/Boxes/BaseBoxes/NumericBox{T}.cs +++ b/Gu.Wpf.NumericInput/Boxes/BaseBoxes/NumericBox{T}.cs @@ -10,7 +10,7 @@ /// Baseclass with common functionality for numeric textboxes. /// The type of the numeric value. - public abstract partial class NumericBox : BaseBox, IIncrementBox + public abstract partial class NumericBox : BaseBox, ISpinnerBox where T : struct, IComparable, IFormattable, IConvertible, IEquatable { /// Initializes a new instance of the class. diff --git a/Gu.Wpf.NumericInput/Boxes/NumericBox.Keys.cs b/Gu.Wpf.NumericInput/Boxes/NumericBox.Keys.cs index 50d85086..49b945e9 100644 --- a/Gu.Wpf.NumericInput/Boxes/NumericBox.Keys.cs +++ b/Gu.Wpf.NumericInput/Boxes/NumericBox.Keys.cs @@ -28,6 +28,7 @@ public static partial class NumericBox private static ComponentResourceKey CreateKey([CallerMemberName] string caller = null) { + // ReSharper disable once AssignNullToNotNullAttribute return new ComponentResourceKey(typeof(NumericBox), caller); } } diff --git a/Gu.Wpf.NumericInput/Converters/ErrorContentToStringConverter.cs b/Gu.Wpf.NumericInput/Converters/ErrorContentToStringConverter.cs new file mode 100644 index 00000000..86d8b956 --- /dev/null +++ b/Gu.Wpf.NumericInput/Converters/ErrorContentToStringConverter.cs @@ -0,0 +1,34 @@ +namespace Gu.Wpf.NumericInput +{ + using System; + using System.Globalization; + using System.Windows.Controls; + using System.Windows.Data; + + public class ErrorContentToStringConverter : IValueConverter + { + public static readonly ErrorContentToStringConverter Default = new ErrorContentToStringConverter(); + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var error = value as ValidationError; + if (error != null) + { + var result = error.ErrorContent as ValidationResult; + if (result != null) + { + return result.ErrorContent?.ToString(); + } + + return error.ErrorContent?.ToString(); + } + + return value?.ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException($"{this.GetType().Name} does not support twoway bindings."); + } + } +} diff --git a/Gu.Wpf.NumericInput/Gu.Wpf.NumericInput.csproj b/Gu.Wpf.NumericInput/Gu.Wpf.NumericInput.csproj index 456de170..3f65cc52 100644 --- a/Gu.Wpf.NumericInput/Gu.Wpf.NumericInput.csproj +++ b/Gu.Wpf.NumericInput/Gu.Wpf.NumericInput.csproj @@ -56,12 +56,13 @@ - + + @@ -181,6 +182,8 @@ - + + Designer + \ No newline at end of file diff --git a/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.generated.cs b/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.generated.cs index 9cf64b06..4fff7ed1 100644 --- a/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.generated.cs +++ b/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.generated.cs @@ -4,7 +4,6 @@ namespace Gu.Wpf.NumericInput using System; using System.Windows; using System.Windows.Controls; - using System.Windows.Input; internal static class WeakRoutedEventManager { diff --git a/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.tt b/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.tt index 9a906a30..2931aefa 100644 --- a/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.tt +++ b/Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.tt @@ -13,7 +13,6 @@ namespace Gu.Wpf.NumericInput using System; using System.Windows; using System.Windows.Controls; - using System.Windows.Input; <# var events = new[] { @@ -178,6 +177,10 @@ namespace Gu.Wpf.NumericInput public class Data { + + public readonly Type OwnerType; + public readonly RoutedEvent Event; + public Data(RoutedEvent @event) : this(@event.OwnerType, @event) { @@ -188,9 +191,5 @@ namespace Gu.Wpf.NumericInput this.OwnerType = ownerType; this.Event = @event; } - - public Type OwnerType { get; private set; } - - public RoutedEvent Event { get; private set; } } #> \ No newline at end of file diff --git a/Gu.Wpf.NumericInput/Spinners/SpinnerDecorator.cs b/Gu.Wpf.NumericInput/Spinners/SpinnerDecorator.cs index a09a8d10..6ca64259 100644 --- a/Gu.Wpf.NumericInput/Spinners/SpinnerDecorator.cs +++ b/Gu.Wpf.NumericInput/Spinners/SpinnerDecorator.cs @@ -22,9 +22,9 @@ public class SpinnerDecorator : Control public static readonly DependencyProperty ChildProperty = DependencyProperty.Register( "Child", - typeof(IIncrementBox), + typeof(ISpinnerBox), typeof(SpinnerDecorator), - new PropertyMetadata(default(IIncrementBox), OnChildChanged)); + new PropertyMetadata(default(ISpinnerBox), OnChildChanged)); static SpinnerDecorator() { @@ -34,9 +34,9 @@ static SpinnerDecorator() /// /// Gets or sets the single child of a /// - public IIncrementBox Child + public ISpinnerBox Child { - get { return (IIncrementBox)this.GetValue(ChildProperty); } + get { return (ISpinnerBox)this.GetValue(ChildProperty); } set { this.SetValue(ChildProperty, value); } } diff --git a/Gu.Wpf.NumericInput/Themes/Validation.xaml b/Gu.Wpf.NumericInput/Themes/Validation.xaml index d138f949..b9e8af82 100644 --- a/Gu.Wpf.NumericInput/Themes/Validation.xaml +++ b/Gu.Wpf.NumericInput/Themes/Validation.xaml @@ -58,7 +58,7 @@ + Text="{Binding ., Converter={x:Static local:ErrorContentToStringConverter.Default}}"/> @@ -99,7 +99,7 @@ VerticalAlignment="Top" Padding="0" Style="{StaticResource ValidationTextStyle}" - Text="{Binding ErrorContent.ErrorContent}" /> + Text="{Binding ., Converter={x:Static local:ErrorContentToStringConverter.Default}}" /> diff --git a/Gu.Wpf.NumericInput/Validation/ValidationRules/CanParse.cs b/Gu.Wpf.NumericInput/Validation/ValidationRules/CanParse.cs index 20edfe5f..0bd6fe03 100644 --- a/Gu.Wpf.NumericInput/Validation/ValidationRules/CanParse.cs +++ b/Gu.Wpf.NumericInput/Validation/ValidationRules/CanParse.cs @@ -16,6 +16,7 @@ private CanParse(bool validatesOnTargetUpdated) { } + /// public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner) { var box = (NumericBox)((BindingExpression)owner).Target; @@ -43,6 +44,7 @@ public override ValidationResult Validate(object value, CultureInfo cultureInfo, return CanParseValidationResult.CreateErrorResult(text, box); } + /// This should never be called. public override ValidationResult Validate(object value, CultureInfo cultureInfo) { throw new InvalidOperationException("Should not get here"); diff --git a/Gu.Wpf.NumericInput/Validation/ValidationRules/IsGreaterThanOrEqualToMinRule.cs b/Gu.Wpf.NumericInput/Validation/ValidationRules/IsGreaterThanOrEqualToMinRule.cs index 6139283e..ba38a73b 100644 --- a/Gu.Wpf.NumericInput/Validation/ValidationRules/IsGreaterThanOrEqualToMinRule.cs +++ b/Gu.Wpf.NumericInput/Validation/ValidationRules/IsGreaterThanOrEqualToMinRule.cs @@ -16,6 +16,7 @@ private IsGreaterThanOrEqualToMinRule(bool validatesOnTargetUpdated) { } + /// public override ValidationResult Validate(object o, CultureInfo cultureInfo, BindingExpressionBase owner) { var box = (NumericBox)((BindingExpression)owner).Target; @@ -39,6 +40,7 @@ public override ValidationResult Validate(object o, CultureInfo cultureInfo, Bin return ValidationResult.ValidResult; } + /// This should never be called. public override ValidationResult Validate(object o, CultureInfo cultureInfo) { throw new InvalidOperationException("Should not get here"); diff --git a/Gu.Wpf.NumericInput/Validation/ValidationRules/IsLessThanOrEqualToMaxRule.cs b/Gu.Wpf.NumericInput/Validation/ValidationRules/IsLessThanOrEqualToMaxRule.cs index 501d31a9..1a2b0634 100644 --- a/Gu.Wpf.NumericInput/Validation/ValidationRules/IsLessThanOrEqualToMaxRule.cs +++ b/Gu.Wpf.NumericInput/Validation/ValidationRules/IsLessThanOrEqualToMaxRule.cs @@ -16,6 +16,7 @@ private IsLessThanOrEqualToMaxRule(bool validatesOnTargetUpdated) { } + /// public override ValidationResult Validate(object o, CultureInfo cultureInfo, BindingExpressionBase owner) { var box = (NumericBox)((BindingExpression)owner).Target; @@ -39,6 +40,7 @@ public override ValidationResult Validate(object o, CultureInfo cultureInfo, Bin return ValidationResult.ValidResult; } + /// This should never be called. public override ValidationResult Validate(object o, CultureInfo cultureInfo) { throw new InvalidOperationException("Should not get here"); diff --git a/Gu.Wpf.NumericInput/Validation/ValidationRules/RegexValidationRule.cs b/Gu.Wpf.NumericInput/Validation/ValidationRules/RegexValidationRule.cs index bad3ee9d..d14ee813 100644 --- a/Gu.Wpf.NumericInput/Validation/ValidationRules/RegexValidationRule.cs +++ b/Gu.Wpf.NumericInput/Validation/ValidationRules/RegexValidationRule.cs @@ -16,6 +16,7 @@ private RegexValidationRule(bool validatesOnTargetUpdated) { } + /// public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner) { var box = (BaseBox)((BindingExpression)owner).Target; @@ -51,6 +52,7 @@ public override ValidationResult Validate(object value, CultureInfo cultureInfo, } } + /// This should never be called. public override ValidationResult Validate(object value, CultureInfo cultureInfo) { throw new InvalidOperationException("Should not get here");