From fea63939a797822a2603eb55c742a975bbd14a42 Mon Sep 17 00:00:00 2001 From: Glenn <5834289+glennawatson@users.noreply.github.com> Date: Thu, 8 Apr 2021 17:13:44 +1000 Subject: [PATCH] housekeeping: Update version and fix nullability issues (#2738) * housekeeping: Change the non-package repos * housekeeping: Update versions and fix nullability issues --- src/Directory.build.props | 4 ++-- src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj | 2 +- src/ReactiveUI.Drawing/ReactiveUI.Drawing.csproj | 2 +- .../ReactiveUI.Fody.Helpers.csproj | 2 +- src/ReactiveUI.Splat.Tests/ReactiveUI.Splat.Tests.csproj | 8 ++++---- src/ReactiveUI.XamForms.Tests/Mocks/ChildViewModel.cs | 4 +++- src/ReactiveUI.XamForms.Tests/Mocks/MainViewModel.cs | 4 +++- .../Mocks/NavigationViewModel.cs | 8 ++++++++ src/ReactiveUI.XamForms.Tests/RoutedViewHostTest.cs | 6 ++++++ .../ObservableForProperty/ObservableAsPropertyHelper.cs | 6 ++++++ src/ReactiveUI/ReactiveUI.csproj | 2 +- src/ReactiveUI/Suspension/SuspensionHostExtensions.cs | 6 ++++++ 12 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/Directory.build.props b/src/Directory.build.props index 8e2c25d4c6..e3e837db92 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -59,11 +59,11 @@ - + - + diff --git a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj index 301ba913e4..fe14d6b1fa 100644 --- a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj +++ b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/ReactiveUI.Drawing/ReactiveUI.Drawing.csproj b/src/ReactiveUI.Drawing/ReactiveUI.Drawing.csproj index c7462bc1be..d6739fcb48 100644 --- a/src/ReactiveUI.Drawing/ReactiveUI.Drawing.csproj +++ b/src/ReactiveUI.Drawing/ReactiveUI.Drawing.csproj @@ -15,6 +15,6 @@ - + diff --git a/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj b/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj index 5a36879278..4e16b73be0 100644 --- a/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj +++ b/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/ReactiveUI.Splat.Tests/ReactiveUI.Splat.Tests.csproj b/src/ReactiveUI.Splat.Tests/ReactiveUI.Splat.Tests.csproj index 16bf26873d..a8b03d91f0 100644 --- a/src/ReactiveUI.Splat.Tests/ReactiveUI.Splat.Tests.csproj +++ b/src/ReactiveUI.Splat.Tests/ReactiveUI.Splat.Tests.csproj @@ -9,13 +9,13 @@ - - - + + + - \ No newline at end of file + diff --git a/src/ReactiveUI.XamForms.Tests/Mocks/ChildViewModel.cs b/src/ReactiveUI.XamForms.Tests/Mocks/ChildViewModel.cs index 5c7c088c53..a8085d87b7 100644 --- a/src/ReactiveUI.XamForms.Tests/Mocks/ChildViewModel.cs +++ b/src/ReactiveUI.XamForms.Tests/Mocks/ChildViewModel.cs @@ -3,6 +3,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. +using System; + using Splat; namespace ReactiveUI.XamForms.Tests.Mocks @@ -15,7 +17,7 @@ public class ChildViewModel : ReactiveObject, IRoutableViewModel /// /// Initializes a new instance of the class. /// - public ChildViewModel() => HostScreen = Locator.Current.GetService(); + public ChildViewModel() => HostScreen = Locator.Current.GetService() ?? throw new InvalidOperationException("There is no valid screens"); /// /// Initializes a new instance of the class. diff --git a/src/ReactiveUI.XamForms.Tests/Mocks/MainViewModel.cs b/src/ReactiveUI.XamForms.Tests/Mocks/MainViewModel.cs index aebc329acf..4f3a14c607 100644 --- a/src/ReactiveUI.XamForms.Tests/Mocks/MainViewModel.cs +++ b/src/ReactiveUI.XamForms.Tests/Mocks/MainViewModel.cs @@ -3,6 +3,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. +using System; + using Splat; namespace ReactiveUI.XamForms.Tests.Mocks @@ -15,7 +17,7 @@ public class MainViewModel : ReactiveObject, IRoutableViewModel /// /// Initializes a new instance of the class. /// - public MainViewModel() => HostScreen = Locator.Current.GetService(); + public MainViewModel() => HostScreen = Locator.Current.GetService() ?? throw new InvalidOperationException("There is no valid screen"); /// public string? UrlPathSegment => "Main view"; diff --git a/src/ReactiveUI.XamForms.Tests/Mocks/NavigationViewModel.cs b/src/ReactiveUI.XamForms.Tests/Mocks/NavigationViewModel.cs index f47912ac27..e171f9c4b1 100644 --- a/src/ReactiveUI.XamForms.Tests/Mocks/NavigationViewModel.cs +++ b/src/ReactiveUI.XamForms.Tests/Mocks/NavigationViewModel.cs @@ -5,6 +5,8 @@ using System; using System.Reactive; +using System.Reactive.Linq; + using Splat; namespace ReactiveUI.XamForms.Tests.Mocks @@ -25,6 +27,12 @@ public class NavigationViewModel : ReactiveObject, IScreen public IObservable Navigate(string name) { var viewModel = Locator.Current.GetService(name); + + if (viewModel is null) + { + return Observable.Throw(new InvalidOperationException("Could not find the view model with the name.")); + } + return Router.Navigate.Execute(viewModel); } diff --git a/src/ReactiveUI.XamForms.Tests/RoutedViewHostTest.cs b/src/ReactiveUI.XamForms.Tests/RoutedViewHostTest.cs index 3831737697..052ae1463e 100644 --- a/src/ReactiveUI.XamForms.Tests/RoutedViewHostTest.cs +++ b/src/ReactiveUI.XamForms.Tests/RoutedViewHostTest.cs @@ -360,6 +360,12 @@ private RoutedViewHost CreateRoutedViewHost(string? initialViewModel = nameof(Ma if (initialViewModel is not null) { var mainViewModel = Locator.Current.GetService(initialViewModel); + + if (mainViewModel is null) + { + throw new InvalidOperationException("There should be a valid view model."); + } + _navigationViewModel.Router.NavigationStack.Add(mainViewModel); } diff --git a/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs b/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs index 10af416f97..79bd961af4 100644 --- a/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs +++ b/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs @@ -58,7 +58,9 @@ public sealed class ObservableAsPropertyHelper : IHandleObservableErrors, IDi public ObservableAsPropertyHelper( IObservable observable, Action onChanged, +#pragma warning disable CS8601 // Possible null reference assignment. T initialValue = default, +#pragma warning restore CS8601 // Possible null reference assignment. bool deferSubscription = false, IScheduler? scheduler = null) : this(observable, onChanged, null, initialValue, deferSubscription, scheduler) @@ -96,7 +98,9 @@ public ObservableAsPropertyHelper( IObservable observable, Action onChanged, Action? onChanging = null, +#pragma warning disable CS8601 // Possible null reference assignment. T initialValue = default, +#pragma warning restore CS8601 // Possible null reference assignment. bool deferSubscription = false, IScheduler? scheduler = null) : this(observable, onChanged, onChanging, () => initialValue, deferSubscription, scheduler) @@ -235,7 +239,9 @@ public T Value /// normally be a Dispatcher-based scheduler. /// /// A default property helper. +#pragma warning disable CS8601 // Possible null reference assignment. public static ObservableAsPropertyHelper Default(T initialValue = default, IScheduler? scheduler = null) => +#pragma warning restore CS8601 // Possible null reference assignment. new ObservableAsPropertyHelper(Observable.Never, _ => { }, initialValue!, false, scheduler); /// diff --git a/src/ReactiveUI/ReactiveUI.csproj b/src/ReactiveUI/ReactiveUI.csproj index 4e92f90076..a4c8af629a 100644 --- a/src/ReactiveUI/ReactiveUI.csproj +++ b/src/ReactiveUI/ReactiveUI.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/ReactiveUI/Suspension/SuspensionHostExtensions.cs b/src/ReactiveUI/Suspension/SuspensionHostExtensions.cs index df0f3d453f..a79d0476a6 100644 --- a/src/ReactiveUI/Suspension/SuspensionHostExtensions.cs +++ b/src/ReactiveUI/Suspension/SuspensionHostExtensions.cs @@ -67,6 +67,12 @@ public static IDisposable SetupDefaultSuspendResume(this ISuspensionHost item, I var ret = new CompositeDisposable(); driver ??= Locator.Current.GetService(); + if (driver is null) + { + item.Log().Error("Could not find a valid driver and therefore cannot setup Suspend/Resume."); + return Disposable.Empty; + } + ret.Add(item.ShouldInvalidateState .SelectMany(_ => driver.InvalidateState()) .LoggedCatch(item, Observables.Unit, "Tried to invalidate app state")