From ca4fa4b190e3a067c394e580514e786ebebbae26 Mon Sep 17 00:00:00 2001 From: hanuman Date: Sat, 1 Jan 2022 17:17:40 -0500 Subject: [PATCH] Fix warnings --- Avalonia/Converters.cs | 10 +++++----- Avalonia/Helpers/Mvvm/RelayCommandGeneric.cs | 12 ++---------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Avalonia/Converters.cs b/Avalonia/Converters.cs index 7484cd0..fab8be8 100644 --- a/Avalonia/Converters.cs +++ b/Avalonia/Converters.cs @@ -9,15 +9,15 @@ namespace HanumanInstitute.MediaPlayer.Avalonia; /// public class TimeSpanToDoubleConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { var valueAdd = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture); - return ((TimeSpan)value).TotalSeconds + valueAdd; + return ((TimeSpan?) value)?.TotalSeconds + valueAdd ?? 0.0; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { var valueAdd = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture); - return TimeSpan.FromSeconds((double)value - valueAdd); + return value != null ? TimeSpan.FromSeconds((double)value - valueAdd) : TimeSpan.Zero; } -} \ No newline at end of file +} diff --git a/Avalonia/Helpers/Mvvm/RelayCommandGeneric.cs b/Avalonia/Helpers/Mvvm/RelayCommandGeneric.cs index 395b3b1..2b235ce 100644 --- a/Avalonia/Helpers/Mvvm/RelayCommandGeneric.cs +++ b/Avalonia/Helpers/Mvvm/RelayCommandGeneric.cs @@ -101,15 +101,7 @@ public RelayCommand(Action execute, Predicate? canExecute) Justification = "This cannot be an event")] public void RaiseCanExecuteChanged() { -#if SILVERLIGHT - var handler = CanExecuteChanged; - if (handler != null) - { - handler(this, EventArgs.Empty); - } -#else - // CommandManager.InvalidateRequerySuggested(); -#endif + CanExecuteChanged?.Invoke(this, EventArgs.Empty); } /// @@ -120,7 +112,7 @@ public void RaiseCanExecuteChanged() /// true if this command can be executed; otherwise, false. public bool CanExecute(object parameter) { - return _canExecute == null ? true : _canExecute((T)parameter); + return _canExecute?.Invoke((T)parameter) ?? true; } ///