Fix nullability mismatch in WPF converters

This commit is contained in:
Tyrrrz 2024-01-15 23:58:56 +02:00
parent 057beaacd6
commit 4e69ff317b
6 changed files with 43 additions and 21 deletions

View file

@ -10,7 +10,12 @@ public class ChannelToGroupKeyConverter : IValueConverter
{ {
public static ChannelToGroupKeyConverter Instance { get; } = new(); public static ChannelToGroupKeyConverter 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 value switch
{ {
Channel { IsThread: true, Parent: not null } channel Channel { IsThread: true, Parent: not null } channel
@ -22,9 +27,9 @@ public class ChannelToGroupKeyConverter : IValueConverter
}; };
public object ConvertBack( public object ConvertBack(
object value, object? value,
Type targetType, Type targetType,
object parameter, object? parameter,
CultureInfo culture CultureInfo culture
) => throw new NotSupportedException(); ) => throw new NotSupportedException();
} }

View file

@ -9,15 +9,20 @@ public class DateTimeOffsetToDateTimeConverter : IValueConverter
{ {
public static DateTimeOffsetToDateTimeConverter Instance { get; } = new(); public static DateTimeOffsetToDateTimeConverter 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 DateTimeOffset dateTimeOffsetValue value is DateTimeOffset dateTimeOffsetValue
? dateTimeOffsetValue.DateTime ? dateTimeOffsetValue.DateTime
: default(DateTime?); : default(DateTime?);
public object? ConvertBack( public object? ConvertBack(
object value, object? value,
Type targetType, Type targetType,
object parameter, object? parameter,
CultureInfo culture CultureInfo culture
) => ) =>
value is DateTime dateTimeValue value is DateTime dateTimeValue

View file

@ -10,13 +10,17 @@ public class ExportFormatToStringConverter : IValueConverter
{ {
public static ExportFormatToStringConverter Instance { get; } = new(); public static ExportFormatToStringConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) => public object? Convert(
value is ExportFormat exportFormatValue ? exportFormatValue.GetDisplayName() : default; object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is ExportFormat exportFormatValue ? exportFormatValue.GetDisplayName() : default;
public object ConvertBack( public object ConvertBack(
object value, object? value,
Type targetType, Type targetType,
object parameter, object? parameter,
CultureInfo culture CultureInfo culture
) => throw new NotSupportedException(); ) => throw new NotSupportedException();
} }

View file

@ -9,13 +9,13 @@ public class InverseBoolConverter : IValueConverter
{ {
public static InverseBoolConverter Instance { get; } = new(); 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; value is false;
public object ConvertBack( public object ConvertBack(
object value, object? value,
Type targetType, Type targetType,
object parameter, object? parameter,
CultureInfo culture CultureInfo culture
) => value is false; ) => value is false;
} }

View file

@ -10,13 +10,17 @@ public class SnowflakeToDateTimeOffsetConverter : IValueConverter
{ {
public static SnowflakeToDateTimeOffsetConverter Instance { get; } = new(); public static SnowflakeToDateTimeOffsetConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) => public object? Convert(
value is Snowflake snowflake ? snowflake.ToDate() : null; object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is Snowflake snowflake ? snowflake.ToDate() : null;
public object ConvertBack( public object ConvertBack(
object value, object? value,
Type targetType, Type targetType,
object parameter, object? parameter,
CultureInfo culture CultureInfo culture
) => throw new NotSupportedException(); ) => throw new NotSupportedException();
} }

View file

@ -9,13 +9,17 @@ public class TimeSpanToDateTimeConverter : IValueConverter
{ {
public static TimeSpanToDateTimeConverter Instance { get; } = new(); public static TimeSpanToDateTimeConverter Instance { get; } = new();
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) => public object? Convert(
value is TimeSpan timeSpanValue ? DateTime.Today.Add(timeSpanValue) : default(DateTime?); object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is TimeSpan timeSpanValue ? DateTime.Today.Add(timeSpanValue) : default(DateTime?);
public object? ConvertBack( public object? ConvertBack(
object value, object? value,
Type targetType, Type targetType,
object parameter, object? parameter,
CultureInfo culture CultureInfo culture
) => value is DateTime dateTimeValue ? dateTimeValue.TimeOfDay : default(TimeSpan?); ) => value is DateTime dateTimeValue ? dateTimeValue.TimeOfDay : default(TimeSpan?);
} }