Skip to content

Commit 5f4fd2c

Browse files
committed
Fix code style issues
F to M Converters
1 parent ab65856 commit 5f4fd2c

File tree

8 files changed

+33
-42
lines changed

8 files changed

+33
-42
lines changed

src/MaterialDesignThemes.Wpf/Converters/GridLinesVisibilityBorderToThicknessConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ internal class GridLinesVisibilityBorderToThicknessConverter : IValueConverter
99

1010
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1111
{
12-
if (!(value is DataGridGridLinesVisibility visibility))
12+
if (value is not DataGridGridLinesVisibility visibility)
1313
return Binding.DoNothing;
1414

15-
var thickness = parameter as double? ?? GridLinesThickness;
15+
double thickness = parameter as double? ?? GridLinesThickness;
1616

1717
return visibility switch
1818
{

src/MaterialDesignThemes.Wpf/Converters/HorizontalThicknessConverter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1515
}
1616

1717
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18-
{
19-
throw new NotImplementedException();
20-
}
18+
=> throw new NotImplementedException();
2119
}

src/MaterialDesignThemes.Wpf/Converters/HsbLinearGradientConverter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1515
}
1616

1717
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18-
{
19-
throw new NotImplementedException();
20-
}
18+
=> throw new NotImplementedException();
2119
}

src/MaterialDesignThemes.Wpf/Converters/HsbToColorConverter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,5 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
2929
}
3030

3131
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
32-
{
33-
throw new NotImplementedException();
34-
}
32+
=> throw new NotImplementedException();
3533
}

src/MaterialDesignThemes.Wpf/Converters/IsDarkConverter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,5 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
2020
}
2121

2222
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
23-
{
24-
throw new NotImplementedException();
25-
}
23+
=> throw new NotImplementedException();
2624
}

src/MaterialDesignThemes.Wpf/Converters/MathConverter.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@ public sealed class MathConverter : IValueConverter
1414
{
1515
double value1 = System.Convert.ToDouble(value, CultureInfo.InvariantCulture);
1616
double value2 = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);
17-
switch (Operation)
17+
return Operation switch
1818
{
19-
case MathOperation.Add:
20-
return value1 + value2 + Offset;
21-
case MathOperation.Divide:
22-
return value1 / value2 + Offset;
23-
case MathOperation.Multiply:
24-
return value1 * value2 + Offset;
25-
case MathOperation.Subtract:
26-
return value1 - value2 + Offset;
27-
case MathOperation.Pow:
28-
return Math.Pow(value1, value2) + Offset;
29-
default:
30-
return Binding.DoNothing;
31-
}
19+
MathOperation.Add => value1 + value2 + Offset,
20+
MathOperation.Divide => value1 / value2 + Offset,
21+
MathOperation.Multiply => value1 * value2 + Offset,
22+
MathOperation.Subtract => value1 - value2 + Offset,
23+
MathOperation.Pow => Math.Pow(value1, value2) + Offset,
24+
_ => Binding.DoNothing,
25+
};
3226
}
3327
catch (FormatException)
3428
{

src/MaterialDesignThemes.Wpf/Converters/MathMultipleConverter.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@ public sealed class MathMultipleConverter : IMultiValueConverter
1414
if (!double.TryParse(value[0]!.ToString(), out double value1) || !double.TryParse(value[1]!.ToString(), out double value2))
1515
return 0;
1616

17-
switch (Operation)
17+
return Operation switch
1818
{
19-
default:
20-
// (case MathOperation.Add:)
21-
return value1 + value2;
22-
case MathOperation.Divide:
23-
return value1 / value2;
24-
case MathOperation.Multiply:
25-
return value1 * value2;
26-
case MathOperation.Subtract:
27-
return value1 - value2;
28-
case MathOperation.Pow:
29-
return Math.Pow(value1, value2);
30-
}
31-
19+
MathOperation.Add => value1 + value2,
20+
MathOperation.Divide => value1 / value2,
21+
MathOperation.Multiply => value1 * value2,
22+
MathOperation.Subtract => value1 - value2,
23+
MathOperation.Pow => Math.Pow(value1, value2),
24+
_ => Binding.DoNothing
25+
};
3226
}
3327

3428
public object?[]? ConvertBack(object? value, Type[]? targetTypes, object? parameter, CultureInfo? culture)

tests/MaterialDesignThemes.Wpf.Tests/Converters/MathConverterTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Globalization;
2+
using System.Windows.Data;
23
using MaterialDesignThemes.Wpf.Converters;
34

45
namespace MaterialDesignThemes.Wpf.Tests.Converters;
@@ -16,4 +17,14 @@ public void EnumValues_AreAllHandled(MathOperation operation)
1617

1718
Assert.True(converter.Convert(1.0, null, 1.0, CultureInfo.CurrentUICulture) is double);
1819
}
20+
21+
[Fact]
22+
public void NoneDoubleArguments_ShouldReturnDoNothing()
23+
{
24+
MathConverter converter = new();
25+
object? actual1 = converter.Convert("", null, 1.0, CultureInfo.CurrentUICulture);
26+
Assert.Equal(Binding.DoNothing, actual1);
27+
object? actual2 = converter.Convert(1.0, null, "", CultureInfo.CurrentUICulture);
28+
Assert.Equal(Binding.DoNothing, actual2);
29+
}
1930
}

0 commit comments

Comments
 (0)