Skip to content

Commit

Permalink
Fix some R# nags.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Jul 12, 2016
1 parent 4d4ce95 commit 7a4548b
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 17 deletions.
1 change: 1 addition & 0 deletions Gu.Wpf.NumericInput.UITests/Helpers/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Gu.Wpf.NumericInput.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/QualifiedUsingAtNestedScope/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FCONSTANT/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FVARIABLE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FCONSTRUCTOR/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
Expand Down
2 changes: 1 addition & 1 deletion Gu.Wpf.NumericInput/Boxes/BaseBoxes/BaseBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// </summary>
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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
{
using System.Windows.Input;

public interface IIncrementBox
public interface ISpinnerBox
{
ICommand IncreaseCommand { get; }

ICommand DecreaseCommand { get; }

bool AllowSpinners { get; }
}
}
2 changes: 1 addition & 1 deletion Gu.Wpf.NumericInput/Boxes/BaseBoxes/NumericBox{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/// <summary>Baseclass with common functionality for numeric textboxes.</summary>
/// <typeparam name="T">The type of the numeric value.</typeparam>
public abstract partial class NumericBox<T> : BaseBox, IIncrementBox
public abstract partial class NumericBox<T> : BaseBox, ISpinnerBox
where T : struct, IComparable<T>, IFormattable, IConvertible, IEquatable<T>
{
/// <summary>Initializes a new instance of the <see cref="NumericBox{T}"/> class.</summary>
Expand Down
1 change: 1 addition & 0 deletions Gu.Wpf.NumericInput/Boxes/NumericBox.Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
34 changes: 34 additions & 0 deletions Gu.Wpf.NumericInput/Converters/ErrorContentToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -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.");
}
}
}
7 changes: 5 additions & 2 deletions Gu.Wpf.NumericInput/Gu.Wpf.NumericInput.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@
<Compile Include="Boxes\BaseBoxes\BaseBox.Events.cs" />
<Compile Include="Boxes\BaseBoxes\DecimalDigitsBox{T}.cs" />
<Compile Include="Boxes\BaseBoxes\FormattedView.cs" />
<Compile Include="Boxes\BaseBoxes\IIncrementBox.cs" />
<Compile Include="Boxes\BaseBoxes\ISpinnerBox.cs" />
<Compile Include="Boxes\BaseBoxes\NumericBox{T}.DependencyProperties.cs" />
<Compile Include="Boxes\BaseBoxes\NumericBox{T}.Events.cs" />
<Compile Include="Boxes\BaseBoxes\Status.cs" />
<Compile Include="Boxes\TextSource.cs" />
<Compile Include="Boxes\ValidationTrigger.cs" />
<Compile Include="Converters\ErrorContentToStringConverter.cs" />
<Compile Include="Converters\FormattedTextBlockMarginConverter.cs" />
<Compile Include="Internals\BindingHelper.cs" />
<Compile Include="Internals\BooleanBoxes.cs" />
Expand Down Expand Up @@ -181,6 +182,8 @@
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.sv.resx" />
<EmbeddedResource Include="Properties\Resources.de.resx" />
<EmbeddedResource Include="Properties\Resources.nl.resx" />
<EmbeddedResource Include="Properties\Resources.nl.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
9 changes: 4 additions & 5 deletions Gu.Wpf.NumericInput/Internals/WeakRoutedEventManager.tt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Gu.Wpf.NumericInput
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
<#
var events = new[]
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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; }
}
#>
8 changes: 4 additions & 4 deletions Gu.Wpf.NumericInput/Spinners/SpinnerDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -34,9 +34,9 @@ static SpinnerDecorator()
/// <summary>
/// Gets or sets the single child of a <see cref="SpinnerDecorator" />
/// </summary>
public IIncrementBox Child
public ISpinnerBox Child
{
get { return (IIncrementBox)this.GetValue(ChildProperty); }
get { return (ISpinnerBox)this.GetValue(ChildProperty); }
set { this.SetValue(ChildProperty, value); }
}

Expand Down
4 changes: 2 additions & 2 deletions Gu.Wpf.NumericInput/Themes/Validation.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ValidationError}">
<TextBlock Style="{StaticResource ValidationTextStyle}"
Text="{Binding ErrorContent.ErrorContent}" />
Text="{Binding ., Converter={x:Static local:ErrorContentToStringConverter.Default}}"/>
<!-- yes it is supposed to be ErrorContent.ErrorContent -->
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down Expand Up @@ -99,7 +99,7 @@
VerticalAlignment="Top"
Padding="0"
Style="{StaticResource ValidationTextStyle}"
Text="{Binding ErrorContent.ErrorContent}" />
Text="{Binding ., Converter={x:Static local:ErrorContentToStringConverter.Default}}" />
<!-- yes it is supposed to be ErrorContent.ErrorContent -->
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
2 changes: 2 additions & 0 deletions Gu.Wpf.NumericInput/Validation/ValidationRules/CanParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private CanParse(bool validatesOnTargetUpdated)
{
}

/// <inheritdoc/>
public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
{
var box = (NumericBox<T>)((BindingExpression)owner).Target;
Expand Down Expand Up @@ -43,6 +44,7 @@ public override ValidationResult Validate(object value, CultureInfo cultureInfo,
return CanParseValidationResult.CreateErrorResult(text, box);
}

/// <summary> This should never be called.</summary>
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
throw new InvalidOperationException("Should not get here");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private IsGreaterThanOrEqualToMinRule(bool validatesOnTargetUpdated)
{
}

/// <inheritdoc/>
public override ValidationResult Validate(object o, CultureInfo cultureInfo, BindingExpressionBase owner)
{
var box = (NumericBox<T>)((BindingExpression)owner).Target;
Expand All @@ -39,6 +40,7 @@ public override ValidationResult Validate(object o, CultureInfo cultureInfo, Bin
return ValidationResult.ValidResult;
}

/// <summary> This should never be called.</summary>
public override ValidationResult Validate(object o, CultureInfo cultureInfo)
{
throw new InvalidOperationException("Should not get here");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private IsLessThanOrEqualToMaxRule(bool validatesOnTargetUpdated)
{
}

/// <inheritdoc/>
public override ValidationResult Validate(object o, CultureInfo cultureInfo, BindingExpressionBase owner)
{
var box = (NumericBox<T>)((BindingExpression)owner).Target;
Expand All @@ -39,6 +40,7 @@ public override ValidationResult Validate(object o, CultureInfo cultureInfo, Bin
return ValidationResult.ValidResult;
}

/// <summary> This should never be called.</summary>
public override ValidationResult Validate(object o, CultureInfo cultureInfo)
{
throw new InvalidOperationException("Should not get here");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private RegexValidationRule(bool validatesOnTargetUpdated)
{
}

/// <inheritdoc/>
public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
{
var box = (BaseBox)((BindingExpression)owner).Target;
Expand Down Expand Up @@ -51,6 +52,7 @@ public override ValidationResult Validate(object value, CultureInfo cultureInfo,
}
}

/// <summary> This should never be called.</summary>
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
throw new InvalidOperationException("Should not get here");
Expand Down

0 comments on commit 7a4548b

Please sign in to comment.