Skip to content

Commit

Permalink
Fix nullability annotations in WPF converters
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Jan 15, 2024
1 parent fe02ebe commit 9f15a7a
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 38 deletions.
6 changes: 3 additions & 3 deletions LightBulb/Converters/CycleStateToPackIconKindConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CycleStateToPackIconKindConverter : IValueConverter
{
public static CycleStateToPackIconKindConverter Instance { get; } = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value switch
{
CycleState.Disabled => PackIconKind.Cancel,
Expand All @@ -23,9 +23,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
};

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => throw new NotSupportedException();
}
12 changes: 8 additions & 4 deletions LightBulb/Converters/DoubleToStringConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public class DoubleToStringConverter : IValueConverter
{
public static DoubleToStringConverter Instance { get; } = new();

public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is double doubleValue ? doubleValue.ToString(culture) : default;
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is double doubleValue ? doubleValue.ToString(culture) : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) =>
value is string stringValue
Expand Down
6 changes: 3 additions & 3 deletions LightBulb/Converters/FractionToDegreesConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class FractionToDegreesConverter : IValueConverter
{
public static FractionToDegreesConverter Instance { get; } = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is double doubleValue ? doubleValue * 360.0 : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => value is double doubleValue ? doubleValue / 360.0 : default;
}
12 changes: 8 additions & 4 deletions LightBulb/Converters/FractionToPercentageStringConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public class FractionToPercentageStringConverter : IValueConverter
{
public static FractionToPercentageStringConverter Instance { get; } = new();

public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is double doubleValue ? doubleValue.ToString("P0", culture) : default;
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is double doubleValue ? doubleValue.ToString("P0", culture) : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) =>
value is string stringValue
Expand Down
6 changes: 3 additions & 3 deletions LightBulb/Converters/InverseBoolConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class InverseBoolConverter : IValueConverter
{
public static InverseBoolConverter Instance { get; } = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is false;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => value is false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SettingsTabViewModelToPackIconKindConverter : IValueConverter
{
public static SettingsTabViewModelToPackIconKindConverter Instance { get; } = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value switch
{
GeneralSettingsTabViewModel => PackIconKind.Settings,
Expand All @@ -23,9 +23,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
};

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => throw new NotSupportedException();
}
6 changes: 3 additions & 3 deletions LightBulb/Converters/TimeOnlyToDegreesConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class TimeOnlyToDegreesConverter : IValueConverter
{
public static TimeOnlyToDegreesConverter Instance { get; } = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is TimeOnly timeOfDayValue ? timeOfDayValue.ToTimeSpan().TotalDays * 360.0 : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) =>
value is double doubleValue
Expand Down
6 changes: 3 additions & 3 deletions LightBulb/Converters/TimeOnlyToHoursConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class TimeOnlyToHoursConverter : IValueConverter
{
public static TimeOnlyToHoursConverter Instance { get; } = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is TimeOnly timeOfDayValue ? timeOfDayValue.ToTimeSpan().TotalHours : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) =>
value is double doubleValue
Expand Down
14 changes: 9 additions & 5 deletions LightBulb/Converters/TimeOnlyToStringConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public class TimeOnlyToStringConverter : IValueConverter
{
public static TimeOnlyToStringConverter Instance { get; } = new();

public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is TimeOnly timeOfDay ? timeOfDay.ToString(null, culture) : default;
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is TimeOnly timeOfDay ? timeOfDay.ToString(null, culture) : default;

public object? ConvertBack(
object value,
public object ConvertBack(
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) =>
value is string stringValue
Expand Down
12 changes: 8 additions & 4 deletions LightBulb/Converters/TimeSpanToDurationStringConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public class TimeSpanToDurationStringConverter : IValueConverter
{
public static TimeSpanToDurationStringConverter Instance { get; } = new();

public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is TimeSpan timeSpanValue ? timeSpanValue.ToString(@"hh\:mm\:ss", culture) : default;
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is TimeSpan timeSpanValue ? timeSpanValue.ToString(@"hh\:mm\:ss", culture) : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) =>
value is string stringValue && TimeSpan.TryParse(stringValue, culture, out var result)
Expand Down
6 changes: 3 additions & 3 deletions LightBulb/Converters/TimeSpanToHoursConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class TimeSpanToHoursConverter : IValueConverter
{
public static TimeSpanToHoursConverter Instance { get; } = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is TimeSpan timeSpanValue ? timeSpanValue.TotalHours : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => value is double doubleValue ? TimeSpan.FromHours(doubleValue) : default;
}

0 comments on commit 9f15a7a

Please sign in to comment.