Skip to content

Commit

Permalink
Fix Codacy/PR Quality Review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Jun 7, 2019
1 parent b6df429 commit 19c4541
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/MahApps.Metro/Controls/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ public bool InterceptManualEnter
[Category("Behavior")]
public bool ChangeValueOnTextChanged
{
get { return (bool)GetValue(ChangeValueOnTextChangedProperty); }
set { SetValue(ChangeValueOnTextChangedProperty, value); }
get { return (bool)this.GetValue(ChangeValueOnTextChangedProperty); }
set { this.SetValue(ChangeValueOnTextChangedProperty, value); }
}

/// <summary>
Expand Down Expand Up @@ -582,7 +582,7 @@ public override void OnApplyTemplate()

if (this.repeatUp == null || this.repeatDown == null || this.valueTextBox == null)
{
throw new InvalidOperationException(string.Format("You have missed to specify {0}, {1} or {2} in your template", PART_NumericUp, PART_NumericDown, PART_TextBox));
throw new InvalidOperationException($"You have missed to specify {PART_NumericUp}, {PART_NumericDown} or {PART_TextBox} in your template!");
}

this.ToggleReadOnlyMode(this.IsReadOnly | !this.InterceptManualEnter);
Expand Down Expand Up @@ -1059,13 +1059,14 @@ private string FormattedValue(double? newValue, string format, CultureInfo cultu
private ScrollViewer TryFindScrollViewer()
{
this.valueTextBox.ApplyTemplate();
var scrollViewer = this.valueTextBox.Template.FindName(PART_ContentHost, this.valueTextBox) as ScrollViewer;
if (scrollViewer != null)

var scrollViewerFromTemplate = this.valueTextBox.Template.FindName(PART_ContentHost, this.valueTextBox) as ScrollViewer;
if (scrollViewerFromTemplate != null)
{
this.handlesMouseWheelScrolling = new Lazy<PropertyInfo>(() => this.scrollViewer.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance).SingleOrDefault(i => i.Name == "HandlesMouseWheelScrolling"));
}

return scrollViewer;
return scrollViewerFromTemplate;
}

private void ChangeValueWithSpeedUp(bool toPositive)
Expand Down Expand Up @@ -1124,21 +1125,23 @@ private void ChangeValueBy(double difference)

private void SetValueTo(double newValue)
{
var value = newValue;

if (this.SnapToMultipleOfInterval && Math.Abs(this.Interval) > 0)
{
newValue = Math.Round(newValue / this.Interval) * this.Interval;
value = Math.Round(newValue / this.Interval) * this.Interval;
}

if (newValue > this.Maximum)
if (value > this.Maximum)
{
newValue = this.Maximum;
value = this.Maximum;
}
else if (newValue < this.Minimum)
else if (value < this.Minimum)
{
newValue = this.Minimum;
value = this.Minimum;
}

this.SetCurrentValue(ValueProperty, CoerceValue(this, newValue));
this.SetCurrentValue(ValueProperty, CoerceValue(this, value));
}

private void EnableDisableDown()
Expand Down Expand Up @@ -1175,7 +1178,7 @@ private void OnTextBoxLostFocus(object sender, RoutedEventArgs e)

private void ChangeValueFromTextInput(TextBox textBox)
{
if (!this.InterceptManualEnter || textBox is null)
if (textBox is null || !this.InterceptManualEnter)
{
return;
}
Expand Down Expand Up @@ -1285,22 +1288,22 @@ private bool ValidateText(string text, out double convertedValue)
|| this.ParsingNumberStyle.HasFlag(NumberStyles.AllowHexSpecifier)
|| this.ParsingNumberStyle == NumberStyles.HexNumber;

text = this.TryGetNumberFromText(text, isHex);
var number = this.TryGetNumberFromText(text, isHex);

// If we are only accepting numbers then attempt to parse as an integer.
if (isNumeric)
{
return this.ConvertNumber(text, out convertedValue);
return this.ConvertNumber(number, out convertedValue);
}

if (text == this.SpecificCultureInfo.NumberFormat.NumberDecimalSeparator
|| text == this.SpecificCultureInfo.NumberFormat.CurrencyDecimalSeparator
|| text == this.SpecificCultureInfo.NumberFormat.PercentDecimalSeparator)
if (number == this.SpecificCultureInfo.NumberFormat.NumberDecimalSeparator
|| number == this.SpecificCultureInfo.NumberFormat.CurrencyDecimalSeparator
|| number == this.SpecificCultureInfo.NumberFormat.PercentDecimalSeparator)
{
return true;
}

if (!double.TryParse(text, this.ParsingNumberStyle, this.SpecificCultureInfo, out convertedValue))
if (!double.TryParse(number, this.ParsingNumberStyle, this.SpecificCultureInfo, out convertedValue))
{
return false;
}
Expand Down

0 comments on commit 19c4541

Please sign in to comment.