Skip to content

Commit 958dde5

Browse files
authored
Fix code style issues (#3637)
* B Converters * C Converters * D & E Converters
1 parent 3ac685e commit 958dde5

11 files changed

+38
-71
lines changed

src/MaterialDesignThemes.Wpf/Converters/BooleanConverter.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33

44
namespace MaterialDesignThemes.Wpf.Converters;
55

6-
public class BooleanConverter<T> : IValueConverter
6+
public class BooleanConverter<T>(T trueValue, T falseValue) : IValueConverter
77
{
8-
public BooleanConverter(T trueValue, T falseValue)
9-
{
10-
TrueValue = trueValue;
11-
FalseValue = falseValue;
12-
}
13-
14-
public T TrueValue { get; set; }
15-
public T FalseValue { get; set; }
8+
public T TrueValue { get; set; } = trueValue;
9+
public T FalseValue { get; set; } = falseValue;
1610

1711
public virtual object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1812
=> value is bool boolValue && boolValue ? TrueValue : FalseValue;

src/MaterialDesignThemes.Wpf/Converters/BorderClipConverter.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public object Convert(object?[]? values, Type targetType, object? parameter, Cul
3636
}
3737

3838
public object?[]? ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture)
39-
{
40-
throw new NotImplementedException();
41-
}
39+
=> throw new NotImplementedException();
4240

4341
// https://wpfspark.wordpress.com/2011/06/08/clipborder-a-wpf-border-that-clips/
4442
private static Geometry GetRoundRectangle(Rect baseRect, Thickness borderThickness, CornerRadius cornerRadius)
@@ -65,25 +63,25 @@ private static Geometry GetRoundRectangle(Rect baseRect, Thickness borderThickne
6563
}
6664

6765
// Taking the border thickness into account
68-
var leftHalf = borderThickness.Left * 0.5;
66+
double leftHalf = borderThickness.Left * 0.5;
6967
if (leftHalf < double.Epsilon)
7068
{
7169
leftHalf = 0.0;
7270
}
7371

74-
var topHalf = borderThickness.Top * 0.5;
72+
double topHalf = borderThickness.Top * 0.5;
7573
if (topHalf < double.Epsilon)
7674
{
7775
topHalf = 0.0;
7876
}
7977

80-
var rightHalf = borderThickness.Right * 0.5;
78+
double rightHalf = borderThickness.Right * 0.5;
8179
if (rightHalf < double.Epsilon)
8280
{
8381
rightHalf = 0.0;
8482
}
8583

86-
var bottomHalf = borderThickness.Bottom * 0.5;
84+
double bottomHalf = borderThickness.Bottom * 0.5;
8785
if (bottomHalf < double.Epsilon)
8886
{
8987
bottomHalf = 0.0;
@@ -121,7 +119,7 @@ private static Geometry GetRoundRectangle(Rect baseRect, Thickness borderThickne
121119
// Adjust the width of the TopLeft and TopRight rectangles so that they are proportional to the width of the baseRect
122120
if (topLeftRect.Right > topRightRect.Left)
123121
{
124-
var newWidth = (topLeftRect.Width / (topLeftRect.Width + topRightRect.Width)) * baseRect.Width;
122+
double newWidth = (topLeftRect.Width / (topLeftRect.Width + topRightRect.Width)) * baseRect.Width;
125123
topLeftRect = new Rect(topLeftRect.Location.X, topLeftRect.Location.Y, newWidth, topLeftRect.Height);
126124
topRightRect = new Rect(
127125
baseRect.Left + newWidth,
@@ -133,7 +131,7 @@ private static Geometry GetRoundRectangle(Rect baseRect, Thickness borderThickne
133131
// Adjust the height of the TopRight and BottomRight rectangles so that they are proportional to the height of the baseRect
134132
if (topRightRect.Bottom > bottomRightRect.Top)
135133
{
136-
var newHeight = (topRightRect.Height / (topRightRect.Height + bottomRightRect.Height)) * baseRect.Height;
134+
double newHeight = (topRightRect.Height / (topRightRect.Height + bottomRightRect.Height)) * baseRect.Height;
137135
topRightRect = new Rect(topRightRect.Location.X, topRightRect.Location.Y, topRightRect.Width, newHeight);
138136
bottomRightRect = new Rect(
139137
bottomRightRect.Location.X,
@@ -145,7 +143,7 @@ private static Geometry GetRoundRectangle(Rect baseRect, Thickness borderThickne
145143
// Adjust the width of the BottomLeft and BottomRight rectangles so that they are proportional to the width of the baseRect
146144
if (bottomRightRect.Left < bottomLeftRect.Right)
147145
{
148-
var newWidth = (bottomLeftRect.Width / (bottomLeftRect.Width + bottomRightRect.Width)) * baseRect.Width;
146+
double newWidth = (bottomLeftRect.Width / (bottomLeftRect.Width + bottomRightRect.Width)) * baseRect.Width;
149147
bottomLeftRect = new Rect(bottomLeftRect.Location.X, bottomLeftRect.Location.Y, newWidth, bottomLeftRect.Height);
150148
bottomRightRect = new Rect(
151149
baseRect.Left + newWidth,
@@ -157,7 +155,7 @@ private static Geometry GetRoundRectangle(Rect baseRect, Thickness borderThickne
157155
// Adjust the height of the TopLeft and BottomLeft rectangles so that they are proportional to the height of the baseRect
158156
if (bottomLeftRect.Top < topLeftRect.Bottom)
159157
{
160-
var newHeight = (topLeftRect.Height / (topLeftRect.Height + bottomLeftRect.Height)) * baseRect.Height;
158+
double newHeight = (topLeftRect.Height / (topLeftRect.Height + bottomLeftRect.Height)) * baseRect.Height;
161159
topLeftRect = new Rect(topLeftRect.Location.X, topLeftRect.Location.Y, topLeftRect.Width, newHeight);
162160
bottomLeftRect = new Rect(
163161
bottomLeftRect.Location.X,
@@ -166,7 +164,7 @@ private static Geometry GetRoundRectangle(Rect baseRect, Thickness borderThickne
166164
Math.Max(0.0, baseRect.Height - newHeight));
167165
}
168166

169-
var roundedRectGeometry = new StreamGeometry();
167+
StreamGeometry roundedRectGeometry = new();
170168

171169
using (var context = roundedRectGeometry.Open())
172170
{

src/MaterialDesignThemes.Wpf/Converters/BrushOpacityConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class BrushOpacityConverter : IValueConverter
1010
{
1111
if (value is SolidColorBrush brush)
1212
{
13-
var opacity = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);
13+
double opacity = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);
1414
SolidColorBrush rv = new(brush.Color)
1515
{
1616
Opacity = opacity

src/MaterialDesignThemes.Wpf/Converters/BrushToRadialGradientBrushConverter.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public class BrushToRadialGradientBrushConverter : IValueConverter
88
{
99
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1010
{
11-
var solidColorBrush = value as SolidColorBrush;
12-
if (solidColorBrush == null) return Binding.DoNothing;
11+
if (value is not SolidColorBrush solidColorBrush) return Binding.DoNothing;
1312

1413
return new RadialGradientBrush(solidColorBrush.Color, Colors.Transparent)
1514
{
@@ -22,7 +21,5 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
2221
}
2322

2423
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
25-
{
26-
return Binding.DoNothing;
27-
}
24+
=> Binding.DoNothing;
2825
}

src/MaterialDesignThemes.Wpf/Converters/CalendarDateCoalesceConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class CalendarDateCoalesceConverter : IMultiValueConverter
1515
{
1616
public object? Convert(object?[]? values, Type targetType, object? parameter, CultureInfo culture)
1717
{
18-
if (values?.Length != 2) throw new ArgumentException("Must specify two values", "values");
19-
if (values[0] is not DateTime) throw new ArgumentException($"First value should be a {nameof(DateTime)}", "values");
20-
if (values[1] is not null && values[1] is not DateTime) throw new ArgumentException($"Second value should be null or a {nameof(DateTime)}", "values");
18+
if (values?.Length != 2) throw new ArgumentException("Must specify two values", nameof(values));
19+
if (values[0] is not DateTime) throw new ArgumentException($"First value should be a {nameof(DateTime)}", nameof(values));
20+
if (values[1] is not null && values[1] is not DateTime) throw new ArgumentException($"Second value should be null or a {nameof(DateTime)}", nameof(values));
2121

2222
var selectedDate = (DateTime?)values[1];
2323

src/MaterialDesignThemes.Wpf/Converters/CalendarYearMonthConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public sealed class CalendarYearMonthConverter : IMultiValueConverter
88
public object? Convert(object?[]? values, Type targetType, object? parameter, CultureInfo culture)
99
{
1010
long ticks = long.MaxValue;
11-
foreach (var value in values ?? Enumerable.Empty<object?>())
11+
foreach (object? value in values ?? Enumerable.Empty<object?>())
1212
{
1313
if (value is DateTime dt)
1414
ticks = dt.Ticks;

src/MaterialDesignThemes.Wpf/Converters/ClockItemIsCheckedConverter.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,16 @@
33

44
namespace MaterialDesignThemes.Wpf.Converters;
55

6-
internal class ClockItemIsCheckedConverter : IValueConverter
6+
internal class ClockItemIsCheckedConverter(Func<DateTime> currentTimeGetter, ClockDisplayMode displayMode, bool is24Hours) : IValueConverter
77
{
8-
private readonly Func<DateTime> _currentTimeGetter;
9-
private readonly ClockDisplayMode _displayMode;
10-
private readonly bool _is24Hours;
11-
12-
public ClockItemIsCheckedConverter(Func<DateTime> currentTimeGetter, ClockDisplayMode displayMode, bool is24Hours)
13-
{
14-
_currentTimeGetter = currentTimeGetter ?? throw new ArgumentNullException(nameof(currentTimeGetter));
15-
_displayMode = displayMode;
16-
_is24Hours = is24Hours;
17-
}
8+
private readonly Func<DateTime> _currentTimeGetter = currentTimeGetter ?? throw new ArgumentNullException(nameof(currentTimeGetter));
9+
private readonly ClockDisplayMode _displayMode = displayMode;
10+
private readonly bool _is24Hours = is24Hours;
1811

1912
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
2013
{
2114
var dateTime = (DateTime)value;
22-
var i = (int)parameter;
15+
int i = (int)parameter;
2316

2417
int converted;
2518
if (_displayMode == ClockDisplayMode.Hours)

src/MaterialDesignThemes.Wpf/Converters/ClockLineConverter.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1919
}
2020

2121
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
22-
{
23-
return Binding.DoNothing;
24-
}
22+
=> Binding.DoNothing;
2523

2624
public override object ProvideValue(IServiceProvider serviceProvider)
27-
{
28-
return this;
29-
}
25+
=> this;
3026
}

src/MaterialDesignThemes.Wpf/Converters/DrawerOffsetConverter.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,19 @@ public class DrawerOffsetConverter : IValueConverter
77
{
88
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
99
{
10-
var d = value as double? ?? 0;
10+
double d = value as double? ?? 0;
1111
if (double.IsInfinity(d) || double.IsNaN(d)) d = 0;
1212

13-
var dock = (parameter is Dock) ? (Dock)parameter : Dock.Left;
14-
switch (dock)
13+
Dock dock = (parameter is Dock) ? (Dock)parameter : Dock.Left;
14+
return dock switch
1515
{
16-
case Dock.Top:
17-
return new Thickness(0, 0 - d, 0, 0);
18-
case Dock.Bottom:
19-
return new Thickness(0, 0, 0, 0 - d);
20-
case Dock.Right:
21-
return new Thickness(0, 0, 0 - d, 0);
22-
case Dock.Left:
23-
default:
24-
return new Thickness(0 - d, 0, 0, 0);
25-
}
16+
Dock.Top => new Thickness(0, 0 - d, 0, 0),
17+
Dock.Bottom => new Thickness(0, 0, 0, 0 - d),
18+
Dock.Right => new Thickness(0, 0, 0 - d, 0),
19+
_ => (object)new Thickness(0 - d, 0, 0, 0),
20+
};
2621
}
2722

2823
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
29-
{
30-
throw new NotImplementedException();
31-
}
24+
=> throw new NotImplementedException();
3225
}

src/MaterialDesignThemes.Wpf/Converters/EqualityToVisibilityConverter.cs

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

1515
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
16-
{
17-
throw new NotImplementedException();
18-
}
16+
=> throw new NotImplementedException();
1917
}

0 commit comments

Comments
 (0)