Skip to content

Commit

Permalink
Fix nullability mismatch in WPF converters
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Jan 15, 2024
1 parent 057beaa commit 4e69ff3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
11 changes: 8 additions & 3 deletions DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ public class ChannelToGroupKeyConverter : IValueConverter
{
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
{
Channel { IsThread: true, Parent: not null } channel
Expand All @@ -22,9 +27,9 @@ public class ChannelToGroupKeyConverter : IValueConverter
};

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => throw new NotSupportedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ public class DateTimeOffsetToDateTimeConverter : IValueConverter
{
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
? dateTimeOffsetValue.DateTime
: default(DateTime?);

public object? ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) =>
value is DateTime dateTimeValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ public class ExportFormatToStringConverter : IValueConverter
{
public static ExportFormatToStringConverter Instance { get; } = new();

public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is ExportFormat exportFormatValue ? exportFormatValue.GetDisplayName() : default;
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is ExportFormat exportFormatValue ? exportFormatValue.GetDisplayName() : default;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => throw new NotSupportedException();
}
6 changes: 3 additions & 3 deletions DiscordChatExporter.Gui/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 @@ -10,13 +10,17 @@ public class SnowflakeToDateTimeOffsetConverter : IValueConverter
{
public static SnowflakeToDateTimeOffsetConverter Instance { get; } = new();

public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is Snowflake snowflake ? snowflake.ToDate() : null;
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is Snowflake snowflake ? snowflake.ToDate() : null;

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => throw new NotSupportedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public class TimeSpanToDateTimeConverter : IValueConverter
{
public static TimeSpanToDateTimeConverter Instance { get; } = new();

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

public object? ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture
) => value is DateTime dateTimeValue ? dateTimeValue.TimeOfDay : default(TimeSpan?);
}

0 comments on commit 4e69ff3

Please sign in to comment.