From 55c0983abdcb09788696ba5940672cce9c9d0d46 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Sat, 11 Nov 2023 21:35:49 +0000 Subject: [PATCH] Update solution to use net 8.0 --- README.md | 2 +- src/Directory.build.props | 8 +- src/Directory.build.targets | 12 +-- .../AppCenterFeatureUsageTrackingSession.cs | 2 +- src/Splat.AppCenter/AppCenterViewTracking.cs | 15 +--- src/Splat.AppCenter/Splat.AppCenter.csproj | 2 +- .../Splat.ApplicationInsights.csproj | 2 +- .../Splat.Autofac.Tests.csproj | 2 +- src/Splat.Autofac/Splat.Autofac.csproj | 2 +- src/Splat.Avalonia.Autofac/AvaloniaMixins.cs | 11 ++- .../Splat.Avalonia.Autofac.csproj | 2 +- src/Splat.Avalonia.DryIoc/AvaloniaMixins.cs | 10 +++ .../Splat.Avalonia.DryIoc.csproj | 2 +- .../AvaloniaMixins.cs | 10 +++ ...soft.Extensions.DependencyInjection.csproj | 4 +- src/Splat.Avalonia.Ninject/AvaloniaMixins.cs | 10 +++ .../Splat.Avalonia.Ninject.csproj | 2 +- .../Mocks/ViewModels/BarViewModel.cs | 2 +- .../Mocks/ViewModels/FooViewModel.cs | 2 +- .../Mocks/ViewModels/MainWindowViewModel.cs | 2 +- .../ViewModels/RoutedViewHostPageViewModel.cs | 2 +- .../Mocks/Views/BarView.axaml.cs | 2 +- .../Mocks/Views/FooView.axaml.cs | 2 +- ...ests.SplatUIProject.DotNet6_0.verified.txt | 1 - src/Splat.Drawing.Tests/BitmapLoaderTests.cs | 14 +--- .../Colors/SplatColorTests.cs | 16 ++-- .../Bitmaps/BitmapLoaderException.cs | 8 -- .../DefaultPlatformModeDetector.cs | 4 + .../Android/Bitmaps/AndroidBitmap.cs | 2 +- .../Platforms/Android/Bitmaps/BitmapMixins.cs | 20 +++-- .../Android/Bitmaps/PlatformBitmapLoader.cs | 20 +++-- .../Android/Maths/PointExtensions.cs | 12 ++- .../Platforms/Android/Maths/RectExtensions.cs | 12 ++- .../Platforms/Cocoa/Bitmaps/BitmapMixins.cs | 29 ++----- .../Platforms/Cocoa/Bitmaps/CocoaBitmap.cs | 2 +- .../Cocoa/Colors/SplatColorExtensions.cs | 16 +++- .../ServiceLocationDrawingInitialization.cs | 8 +- .../Platforms/net6/Bitmaps/BitmapMixins.cs | 6 +- src/Splat.Drawing/Splat.Drawing.csproj | 14 ++-- src/Splat.DryIoc/DryIocDependencyResolver.cs | 7 +- src/Splat.DryIoc/Splat.DryIoc.csproj | 2 +- .../ExceptionlessSplatLogger.cs | 24 ++++-- .../Splat.Exceptionless.csproj | 4 +- src/Splat.Log4Net/Splat.Log4Net.csproj | 2 +- .../ContainerWrapper.cs | 8 +- .../MicrosoftDependencyResolver.cs | 6 +- ...soft.Extensions.DependencyInjection.csproj | 4 +- .../MicrosoftExtensionsLogProvider.cs | 12 ++- .../MicrosoftExtensionsLoggingExtensions.cs | 10 +++ .../MicrosoftExtensionsLoggingLogger.cs | 8 ++ .../Splat.Microsoft.Extensions.Logging.csproj | 6 +- src/Splat.NLog/Splat.NLog.csproj | 4 +- src/Splat.Ninject/Splat.Ninject.csproj | 2 +- .../Splat.Prism.Forms.csproj | 2 +- src/Splat.Prism/Splat.Prism.csproj | 2 +- src/Splat.Raygun/Splat.Raygun.csproj | 2 +- src/Splat.Serilog/Splat.Serilog.csproj | 6 +- .../SimpleInjectorInitializer.cs | 7 +- .../Splat.SimpleInjector.csproj | 2 +- .../TransientSimpleInjectorRegistration.cs | 2 +- ...lTests.SplatProject.DotNet6_0.verified.txt | 1 - .../Logging/FullLoggers/NLogLoggerTests.cs | 6 +- .../Logging/FullLoggers/SerilogLoggerTests.cs | 8 +- src/Splat.Tests/Logging/StaticLoggerTests.cs | 10 ++- .../WrappingFullLoggers/ConsoleLoggerTests.cs | 4 +- .../ExceptionlessLoggerTests.cs | 2 +- .../WrappingFullLoggers/Log4NetLoggerTests.cs | 11 ++- src/Splat.sln | 2 + .../EnableFeatureUsageTrackingExtensions.cs | 11 +++ src/Splat/Disposables/CompositeDisposable.cs | 4 + src/Splat/Logging/FullLoggerExtensions.cs | 77 +++++++++++++++++++ src/Splat/Logging/LogManagerMixin.cs | 4 + src/Splat/Logging/LoggingException.cs | 8 -- src/Splat/Logging/WrappingPrefixLogger.cs | 12 ++- .../ModeDetection/DefaultModeDetector.cs | 4 + .../DependencyResolverMixins.cs | 45 +++++++++++ .../ServiceLocation/FuncDependencyResolver.cs | 11 +-- src/Splat/ServiceLocation/Locator.cs | 4 + .../ModernDependencyResolver.cs | 34 ++++---- src/Splat/ServiceLocation/ResolverMixins.cs | 42 ++++++++++ .../ServiceLocationInitialization.cs | 4 + src/Splat/Splat.csproj | 2 +- src/global.json | 2 +- 83 files changed, 505 insertions(+), 219 deletions(-) diff --git a/README.md b/README.md index 2dc642323..c45ed5eb6 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Splat currently supports: [Always Be NuGetting](https://nuget.org/packages/Splat/). Package contains binaries for: -* .NET Framework 4.6.2, .NET Framework 4.7.2, .NET Standard 2.0 and .NET 6.0 +* .NET Framework 4.6.2, .NET Framework 4.7.2, .NET Standard 2.0, .NET 6.0, .NET 7.0, and .NET 8.0 * WPF * Windows Forms * UWP diff --git a/src/Directory.build.props b/src/Directory.build.props index c62dbcbd2..730f0f3f8 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -26,7 +26,7 @@ AllEnabledByDefault true preview - $(NoWarn);VSSpell001 + $(NoWarn);VSSpell001;SA1010 false @@ -52,13 +52,13 @@ - + - + @@ -82,7 +82,7 @@ - + diff --git a/src/Directory.build.targets b/src/Directory.build.targets index 66ed5af18..d60f5c6c7 100644 --- a/src/Directory.build.targets +++ b/src/Directory.build.targets @@ -10,22 +10,22 @@ $(DefineConstants);MONO;UIKIT;COCOA;IOS - + $(DefineConstants);MONO;UIKIT;COCOA;IOS $(DefineConstants);MONO;COCOA - + $(DefineConstants);MONO;COCOA $(DefineConstants);MONO;UIKIT;COCOA;TVOS - + $(DefineConstants);MONO;UIKIT;COCOA;TVOS - + $(DefineConstants);MONO;UIKIT;COCOA;MACCATALYST @@ -34,13 +34,13 @@ $(DefineConstants);MONO;ANDROID - + $(DefineConstants);MONO;ANDROID $(DefineConstants);TIZEN - + $(DefineConstants);IS_SHARED_NET diff --git a/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs b/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs index 699e3d60d..85882fece 100644 --- a/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs +++ b/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs @@ -52,7 +52,7 @@ public void OnException(Exception exception) Microsoft.AppCenter.Crashes.Crashes.TrackError(exception, properties); } - private IDictionary GetProperties() + private Dictionary GetProperties() { var properties = new Dictionary { diff --git a/src/Splat.AppCenter/AppCenterViewTracking.cs b/src/Splat.AppCenter/AppCenterViewTracking.cs index aa23a633d..ca20b8ac1 100644 --- a/src/Splat.AppCenter/AppCenterViewTracking.cs +++ b/src/Splat.AppCenter/AppCenterViewTracking.cs @@ -16,16 +16,9 @@ public sealed class AppCenterViewTracking : IViewTracking /// Track a view navigation using just a name. /// /// Name of the view. - public void OnViewNavigation(string name) - { - var properties = GetProperties(name); + public void OnViewNavigation(string name) => + Microsoft.AppCenter.Analytics.Analytics.TrackEvent("PageView", GetProperties(name)); - Microsoft.AppCenter.Analytics.Analytics.TrackEvent("PageView", properties); - } - - private static IDictionary GetProperties(string name) => - new Dictionary - { - { "Name", name }, - }; + private static Dictionary GetProperties(string name) => + new() { { "Name", name }, }; } diff --git a/src/Splat.AppCenter/Splat.AppCenter.csproj b/src/Splat.AppCenter/Splat.AppCenter.csproj index 8e0601246..1ca08beee 100644 --- a/src/Splat.AppCenter/Splat.AppCenter.csproj +++ b/src/Splat.AppCenter/Splat.AppCenter.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0-windows10.0.17763.0;net7.0-windows10.0.17763.0 + netstandard2.0;net6.0-windows10.0.17763.0;net7.0-windows10.0.17763.0;net8.0-windows10.0.17763.0 Splat.AppCenter Splat diff --git a/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj b/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj index 3773bc7c3..8d6194b38 100644 --- a/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj +++ b/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Splat.ApplicationInsights Splat diff --git a/src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj b/src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj index 248ba3c10..0ad8abee5 100644 --- a/src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj +++ b/src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj @@ -4,7 +4,7 @@ net6.0-windows10.0.17763.0 false - $(NoWarn);1591;CA1707;SA1633;CA2000 + $(NoWarn);1591;CA1707;SA1633;CA2000;CA1851 enable diff --git a/src/Splat.Autofac/Splat.Autofac.csproj b/src/Splat.Autofac/Splat.Autofac.csproj index c864049b3..b4e68436d 100644 --- a/src/Splat.Autofac/Splat.Autofac.csproj +++ b/src/Splat.Autofac/Splat.Autofac.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Autofac adapter for Splat enable diff --git a/src/Splat.Avalonia.Autofac/AvaloniaMixins.cs b/src/Splat.Avalonia.Autofac/AvaloniaMixins.cs index 4d7f3f8c2..52da14510 100644 --- a/src/Splat.Avalonia.Autofac/AvaloniaMixins.cs +++ b/src/Splat.Avalonia.Autofac/AvaloniaMixins.cs @@ -35,11 +35,14 @@ public static AppBuilder UseReactiveUIWithAutofac(this AppBuilder builder, Actio { return; } - +#if NETSTANDARD if (containerConfig is null) { throw new ArgumentNullException(nameof(containerConfig)); } +#else + ArgumentNullException.ThrowIfNull(containerConfig); +#endif var builder = new ContainerBuilder(); var autofacResolver = new AutofacDependencyResolver(builder); @@ -85,6 +88,7 @@ public static AppBuilder UseReactiveUIWithDIContainer( return; } +#if NETSTANDARD if (containerFactory is null) { throw new ArgumentNullException(nameof(containerFactory)); @@ -99,6 +103,11 @@ public static AppBuilder UseReactiveUIWithDIContainer( { throw new ArgumentNullException(nameof(dependencyResolverFactory)); } +#else + ArgumentNullException.ThrowIfNull(containerFactory); + ArgumentNullException.ThrowIfNull(containerConfig); + ArgumentNullException.ThrowIfNull(dependencyResolverFactory); +#endif var container = containerFactory(); Locator.CurrentMutable.RegisterConstant(container, typeof(TContainer)); diff --git a/src/Splat.Avalonia.Autofac/Splat.Avalonia.Autofac.csproj b/src/Splat.Avalonia.Autofac/Splat.Avalonia.Autofac.csproj index a9ce1f7e6..5c7b9bf5f 100644 --- a/src/Splat.Avalonia.Autofac/Splat.Avalonia.Autofac.csproj +++ b/src/Splat.Avalonia.Autofac/Splat.Avalonia.Autofac.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 enable enable diff --git a/src/Splat.Avalonia.DryIoc/AvaloniaMixins.cs b/src/Splat.Avalonia.DryIoc/AvaloniaMixins.cs index 6927faae7..9dc24e2e5 100644 --- a/src/Splat.Avalonia.DryIoc/AvaloniaMixins.cs +++ b/src/Splat.Avalonia.DryIoc/AvaloniaMixins.cs @@ -32,10 +32,14 @@ public static AppBuilder UseReactiveUIWithDryIoc(this AppBuilder builder, Action return; } +#if NETSTANDARD if (containerConfig is null) { throw new ArgumentNullException(nameof(containerConfig)); } +#else + ArgumentNullException.ThrowIfNull(containerConfig); +#endif var container = new Container(); Locator.CurrentMutable.RegisterConstant(container, typeof(Container)); @@ -72,6 +76,7 @@ public static AppBuilder UseReactiveUIWithDIContainer( return; } +#if NETSTANDARD if (containerFactory is null) { throw new ArgumentNullException(nameof(containerFactory)); @@ -86,6 +91,11 @@ public static AppBuilder UseReactiveUIWithDIContainer( { throw new ArgumentNullException(nameof(dependencyResolverFactory)); } +#else + ArgumentNullException.ThrowIfNull(containerFactory); + ArgumentNullException.ThrowIfNull(containerConfig); + ArgumentNullException.ThrowIfNull(dependencyResolverFactory); +#endif var container = containerFactory(); Locator.CurrentMutable.RegisterConstant(container, typeof(TContainer)); diff --git a/src/Splat.Avalonia.DryIoc/Splat.Avalonia.DryIoc.csproj b/src/Splat.Avalonia.DryIoc/Splat.Avalonia.DryIoc.csproj index 3323b4b2b..317bb884a 100644 --- a/src/Splat.Avalonia.DryIoc/Splat.Avalonia.DryIoc.csproj +++ b/src/Splat.Avalonia.DryIoc/Splat.Avalonia.DryIoc.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 enable enable diff --git a/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/AvaloniaMixins.cs b/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/AvaloniaMixins.cs index b5f221ecf..33596e4ea 100644 --- a/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/AvaloniaMixins.cs +++ b/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/AvaloniaMixins.cs @@ -34,10 +34,14 @@ public static AppBuilder UseReactiveUIWithMicrosoftDependencyResolver(this AppBu return; } +#if NETSTANDARD if (containerConfig is null) { throw new ArgumentNullException(nameof(containerConfig)); } +#else + ArgumentNullException.ThrowIfNull(containerConfig); +#endif IServiceCollection serviceCollection = new ServiceCollection(); Locator.CurrentMutable.RegisterConstant(serviceCollection, typeof(IServiceCollection)); @@ -88,6 +92,7 @@ public static AppBuilder UseReactiveUIWithDIContainer( return; } +#if NETSTANDARD if (containerFactory is null) { throw new ArgumentNullException(nameof(containerFactory)); @@ -102,6 +107,11 @@ public static AppBuilder UseReactiveUIWithDIContainer( { throw new ArgumentNullException(nameof(dependencyResolverFactory)); } +#else + ArgumentNullException.ThrowIfNull(containerFactory); + ArgumentNullException.ThrowIfNull(containerConfig); + ArgumentNullException.ThrowIfNull(dependencyResolverFactory); +#endif var container = containerFactory(); Locator.CurrentMutable.RegisterConstant(container, typeof(TContainer)); diff --git a/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/Splat.Avalonia.Microsoft.Extensions.DependencyInjection.csproj b/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/Splat.Avalonia.Microsoft.Extensions.DependencyInjection.csproj index b53bd7935..453c8e1c8 100644 --- a/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/Splat.Avalonia.Microsoft.Extensions.DependencyInjection.csproj +++ b/src/Splat.Avalonia.Microsoft.Extensions.DependencyInjection/Splat.Avalonia.Microsoft.Extensions.DependencyInjection.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 enable enable @@ -12,7 +12,7 @@ - + diff --git a/src/Splat.Avalonia.Ninject/AvaloniaMixins.cs b/src/Splat.Avalonia.Ninject/AvaloniaMixins.cs index af53b1ac3..d2518f9af 100644 --- a/src/Splat.Avalonia.Ninject/AvaloniaMixins.cs +++ b/src/Splat.Avalonia.Ninject/AvaloniaMixins.cs @@ -32,10 +32,14 @@ public static AppBuilder UseReactiveUIWithNinject(this AppBuilder builder, Actio return; } +#if NETSTANDARD if (containerConfig is null) { throw new ArgumentNullException(nameof(containerConfig)); } +#else + ArgumentNullException.ThrowIfNull(containerConfig); +#endif var container = new StandardKernel(); Locator.CurrentMutable.RegisterConstant(container, typeof(StandardKernel)); @@ -72,6 +76,7 @@ public static AppBuilder UseReactiveUIWithDIContainer( return; } +#if NETSTANDARD if (containerFactory is null) { throw new ArgumentNullException(nameof(containerFactory)); @@ -86,6 +91,11 @@ public static AppBuilder UseReactiveUIWithDIContainer( { throw new ArgumentNullException(nameof(dependencyResolverFactory)); } +#else + ArgumentNullException.ThrowIfNull(containerFactory); + ArgumentNullException.ThrowIfNull(containerConfig); + ArgumentNullException.ThrowIfNull(dependencyResolverFactory); +#endif var container = containerFactory(); Locator.CurrentMutable.RegisterConstant(container, typeof(TContainer)); diff --git a/src/Splat.Avalonia.Ninject/Splat.Avalonia.Ninject.csproj b/src/Splat.Avalonia.Ninject/Splat.Avalonia.Ninject.csproj index a885d6cd6..e778ca257 100644 --- a/src/Splat.Avalonia.Ninject/Splat.Avalonia.Ninject.csproj +++ b/src/Splat.Avalonia.Ninject/Splat.Avalonia.Ninject.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 enable enable diff --git a/src/Splat.Avalonia.Tests/Mocks/ViewModels/BarViewModel.cs b/src/Splat.Avalonia.Tests/Mocks/ViewModels/BarViewModel.cs index 7c6a7b9ba..ef4623991 100644 --- a/src/Splat.Avalonia.Tests/Mocks/ViewModels/BarViewModel.cs +++ b/src/Splat.Avalonia.Tests/Mocks/ViewModels/BarViewModel.cs @@ -2,7 +2,7 @@ namespace ReactiveUIDemo.ViewModels { - internal class BarViewModel(IScreen screen) : ReactiveObject, IRoutableViewModel + internal sealed class BarViewModel(IScreen screen) : ReactiveObject, IRoutableViewModel { public string UrlPathSegment => "Bar"; diff --git a/src/Splat.Avalonia.Tests/Mocks/ViewModels/FooViewModel.cs b/src/Splat.Avalonia.Tests/Mocks/ViewModels/FooViewModel.cs index b844a584d..a912401e8 100644 --- a/src/Splat.Avalonia.Tests/Mocks/ViewModels/FooViewModel.cs +++ b/src/Splat.Avalonia.Tests/Mocks/ViewModels/FooViewModel.cs @@ -2,7 +2,7 @@ namespace ReactiveUIDemo.ViewModels { - internal class FooViewModel(IScreen screen) : ReactiveObject, IRoutableViewModel + internal sealed class FooViewModel(IScreen screen) : ReactiveObject, IRoutableViewModel { public string UrlPathSegment => "Foo"; diff --git a/src/Splat.Avalonia.Tests/Mocks/ViewModels/MainWindowViewModel.cs b/src/Splat.Avalonia.Tests/Mocks/ViewModels/MainWindowViewModel.cs index 2222137d3..8c3eca9ba 100644 --- a/src/Splat.Avalonia.Tests/Mocks/ViewModels/MainWindowViewModel.cs +++ b/src/Splat.Avalonia.Tests/Mocks/ViewModels/MainWindowViewModel.cs @@ -2,7 +2,7 @@ namespace ReactiveUIDemo.ViewModels { - internal class MainWindowViewModel : ReactiveObject + internal sealed class MainWindowViewModel : ReactiveObject { public RoutedViewHostPageViewModel RoutedViewHost { get; } = new(); } diff --git a/src/Splat.Avalonia.Tests/Mocks/ViewModels/RoutedViewHostPageViewModel.cs b/src/Splat.Avalonia.Tests/Mocks/ViewModels/RoutedViewHostPageViewModel.cs index 3cef041a8..60236c532 100644 --- a/src/Splat.Avalonia.Tests/Mocks/ViewModels/RoutedViewHostPageViewModel.cs +++ b/src/Splat.Avalonia.Tests/Mocks/ViewModels/RoutedViewHostPageViewModel.cs @@ -2,7 +2,7 @@ namespace ReactiveUIDemo.ViewModels { - internal class RoutedViewHostPageViewModel : ReactiveObject, IScreen + internal sealed class RoutedViewHostPageViewModel : ReactiveObject, IScreen { public RoutedViewHostPageViewModel() { diff --git a/src/Splat.Avalonia.Tests/Mocks/Views/BarView.axaml.cs b/src/Splat.Avalonia.Tests/Mocks/Views/BarView.axaml.cs index 8f5be5a7c..79c91e9c0 100644 --- a/src/Splat.Avalonia.Tests/Mocks/Views/BarView.axaml.cs +++ b/src/Splat.Avalonia.Tests/Mocks/Views/BarView.axaml.cs @@ -5,7 +5,7 @@ namespace ReactiveUIDemo.Views { - internal partial class BarView : UserControl, IViewFor + internal sealed partial class BarView : UserControl, IViewFor { public BarView() => InitializeComponent(); diff --git a/src/Splat.Avalonia.Tests/Mocks/Views/FooView.axaml.cs b/src/Splat.Avalonia.Tests/Mocks/Views/FooView.axaml.cs index 5456a0a7d..35bee2d60 100644 --- a/src/Splat.Avalonia.Tests/Mocks/Views/FooView.axaml.cs +++ b/src/Splat.Avalonia.Tests/Mocks/Views/FooView.axaml.cs @@ -5,7 +5,7 @@ namespace ReactiveUIDemo.Views { - internal partial class FooView : UserControl, IViewFor + internal sealed partial class FooView : UserControl, IViewFor { public FooView() => InitializeComponent(); diff --git a/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.DotNet6_0.verified.txt b/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.DotNet6_0.verified.txt index 3bad410d3..56a18c9f3 100644 --- a/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.DotNet6_0.verified.txt +++ b/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.DotNet6_0.verified.txt @@ -17,7 +17,6 @@ namespace Splat { public BitmapLoaderException() { } public BitmapLoaderException(string message) { } - protected BitmapLoaderException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public BitmapLoaderException(string message, System.Exception innerException) { } } public static class BitmapMixins diff --git a/src/Splat.Drawing.Tests/BitmapLoaderTests.cs b/src/Splat.Drawing.Tests/BitmapLoaderTests.cs index b2c61d30c..d7161c8ac 100644 --- a/src/Splat.Drawing.Tests/BitmapLoaderTests.cs +++ b/src/Splat.Drawing.Tests/BitmapLoaderTests.cs @@ -17,12 +17,9 @@ public sealed class BitmapLoaderTests /// /// Gets the test data for the Load Suceeds Unit Test. /// - public static TheoryData> LoadSucceedsTestData { get; } = - [ - GetPngStream, - GetJpegStream, - GetBitmapStream, - ]; +#pragma warning disable IDE0028 // Simplify collection initialization + public static TheoryData> LoadSucceedsTestData { get; } = new() { GetPngStream, GetJpegStream, GetBitmapStream }; +#pragma warning restore IDE0028 // Simplify collection initialization /// /// Test to ensure the bitmap loader initializes properly. @@ -57,10 +54,7 @@ public void Create_Succeeds() [MemberData(nameof(LoadSucceedsTestData))] public void Load_Succeeds(Func getStream) { - if (getStream is null) - { - throw new ArgumentNullException(nameof(getStream)); - } + ArgumentNullException.ThrowIfNull(getStream); var instance = new Splat.PlatformBitmapLoader(); diff --git a/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs b/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs index 7540695ba..0ecfe62af 100644 --- a/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs +++ b/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs @@ -43,12 +43,12 @@ public void FromNameTests(KnownColor knownColor) Assert.NotNull(splatColor.Name); } - private static IEnumerable GetEnumAsTestTheory() - { - var values = Enum.GetValues(typeof(KnownColor)); - var results = new List(values.Length); - results.AddRange(values.Cast().Select(value => new[] { value! })); - - return results; - } + ////private static IEnumerable GetEnumAsTestTheory() + ////{ + //// var values = Enum.GetValues(typeof(KnownColor)); + //// var results = new List(values.Length); + //// results.AddRange(values.Cast().Select(value => new[] { value! })); + + //// return results; + ////} } diff --git a/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs b/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs index 192d4c734..ab5da62fe 100644 --- a/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs +++ b/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs @@ -38,12 +38,4 @@ public BitmapLoaderException(string message, Exception innerException) : base(message, innerException) { } - - /// Initializes a new instance of the class. - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - protected BitmapLoaderException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } diff --git a/src/Splat.Drawing/DefaultPlatformModeDetector.cs b/src/Splat.Drawing/DefaultPlatformModeDetector.cs index 721e5f4b8..3388d37d9 100644 --- a/src/Splat.Drawing/DefaultPlatformModeDetector.cs +++ b/src/Splat.Drawing/DefaultPlatformModeDetector.cs @@ -71,7 +71,11 @@ public class DefaultPlatformModeDetector : IPlatformModeDetector var exeName = new FileInfo(entry.Location).Name; if (designEnvironments.Any(x => +#if NETSTANDARD || NETFRAMEWORK || TIZEN x.IndexOf(exeName, StringComparison.InvariantCultureIgnoreCase) != -1)) +#else + x.Contains(exeName, StringComparison.InvariantCultureIgnoreCase))) +#endif { _cachedInDesignModeResult = true; } diff --git a/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs b/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs index bd4032a7c..5d8602550 100644 --- a/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs +++ b/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs @@ -38,7 +38,7 @@ public Task Save(CompressedBitmapFormat format, float quality, Stream target) return Task.CompletedTask; } - var fmt = format == CompressedBitmapFormat.Jpeg ? Bitmap.CompressFormat.Jpeg : Bitmap.CompressFormat.Png; + var fmt = (format == CompressedBitmapFormat.Jpeg ? Bitmap.CompressFormat.Jpeg : Bitmap.CompressFormat.Png)!; return Task.Run(() => _inner.Compress(fmt, (int)(quality * 100), target)); } diff --git a/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs index 7d7419eea..ad46fb76a 100644 --- a/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs @@ -19,18 +19,12 @@ public static class BitmapMixins /// /// The bitmap to convert. /// A bitmap. - public static Drawable ToNative(this IBitmap value) + public static Drawable ToNative(this IBitmap value) => value switch { - switch (value) - { - case null: - throw new System.ArgumentNullException(nameof(value)); - case AndroidBitmap androidBitmap: - return new BitmapDrawable(Application.Context.Resources, androidBitmap.Inner); - default: - return ((DrawableBitmap)value).Inner; - } - } + null => throw new System.ArgumentNullException(nameof(value)), + AndroidBitmap androidBitmap => new BitmapDrawable(Application.Context.Resources, androidBitmap.Inner), + _ => ((DrawableBitmap)value).Inner, + }; /// /// Converts a to a splat . @@ -40,10 +34,14 @@ public static Drawable ToNative(this IBitmap value) /// A bitmap. public static IBitmap FromNative(this Bitmap value, bool copy = false) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else if (value is null) { throw new System.ArgumentNullException(nameof(value)); } +#endif if (copy) { diff --git a/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs index 0194cde91..34285e3dc 100644 --- a/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs @@ -26,10 +26,14 @@ public class PlatformBitmapLoader : IBitmapLoader, IEnableLogger /// public async Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) { - if (sourceStream is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(sourceStream); +#else + if (sourceStream == null) { throw new ArgumentNullException(nameof(sourceStream)); } +#endif // this is a rough check to do with the termination check for #479 if (sourceStream.Length < 2) @@ -51,7 +55,7 @@ public class PlatformBitmapLoader : IBitmapLoader, IEnableLogger } else { - var opts = new BitmapFactory.Options() + using var opts = new BitmapFactory.Options() { OutWidth = (int)desiredWidth.Value, OutHeight = (int)desiredHeight.Value, @@ -86,19 +90,19 @@ public class PlatformBitmapLoader : IBitmapLoader, IEnableLogger if (int.TryParse(source, out var id)) { - return Task.Run(() => GetFromDrawable(res.GetDrawable(id, theme))); + return Task.Run(() => GetFromDrawable(res.GetDrawable(id, theme))); } if (_drawableList.TryGetValue(source, out var value)) { - return Task.Run(() => GetFromDrawable(res.GetDrawable(value, theme))); + return Task.Run(() => GetFromDrawable(res.GetDrawable(value, theme))); } // NB: On iOS, you have to pass the extension, but on Android it's // stripped - try stripping the extension to see if there's a Drawable. var key = System.IO.Path.GetFileNameWithoutExtension(source); return _drawableList.TryGetValue(key, out var intValue) - ? Task.Run(() => GetFromDrawable(res.GetDrawable(intValue, theme))) + ? Task.Run(() => GetFromDrawable(res.GetDrawable(intValue, theme))) : throw new ArgumentException("Either pass in an integer ID cast to a string, or the name of a drawable resource"); } @@ -107,7 +111,9 @@ public class PlatformBitmapLoader : IBitmapLoader, IEnableLogger { var config = Bitmap.Config.Argb8888 ?? throw new InvalidOperationException("The ARGB8888 bitmap format is unavailable"); +#pragma warning disable CA2000 // Dispose objects before losing scope return Bitmap.CreateBitmap((int)width, (int)height, config)?.FromNative(); +#pragma warning restore CA2000 // Dispose objects before losing scope } internal static Dictionary GetDrawableList(IFullLogger? log) @@ -150,7 +156,7 @@ private static Type[] GetTypesFromAssembly( // as of July 2019. return e.Types is not null ? e.Types.Where(x => x is not null).Select(x => x!).ToArray() - : Array.Empty(); + : []; } } @@ -203,7 +209,7 @@ private static Dictionary GetDrawableList( return result; } - private static IBitmap? GetFromDrawable(Android.Graphics.Drawables.Drawable? drawable) => drawable is null ? null : new DrawableBitmap(drawable); + private static DrawableBitmap? GetFromDrawable(Android.Graphics.Drawables.Drawable? drawable) => drawable is null ? null : new DrawableBitmap(drawable); /// /// Checks to make sure the last 2 bytes are as expected. diff --git a/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs b/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs index f52bab739..165b2c086 100644 --- a/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs +++ b/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs @@ -33,10 +33,14 @@ public static class PointExtensions /// A of the value. public static System.Drawing.Point FromNative(this Point value) { - if (value is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else + if (value == null) { throw new System.ArgumentNullException(nameof(value)); } +#endif return new(value.X, value.Y); } @@ -48,10 +52,14 @@ public static System.Drawing.Point FromNative(this Point value) /// A of the value. public static System.Drawing.PointF FromNative(this PointF value) { - if (value is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else + if (value == null) { throw new System.ArgumentNullException(nameof(value)); } +#endif return new(value.X, value.Y); } diff --git a/src/Splat.Drawing/Platforms/Android/Maths/RectExtensions.cs b/src/Splat.Drawing/Platforms/Android/Maths/RectExtensions.cs index 60c56432e..3215e4379 100644 --- a/src/Splat.Drawing/Platforms/Android/Maths/RectExtensions.cs +++ b/src/Splat.Drawing/Platforms/Android/Maths/RectExtensions.cs @@ -33,10 +33,14 @@ public static class RectExtensions /// A of the value. public static System.Drawing.Rectangle FromNative(this Rect value) { - if (value is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else + if (value == null) { throw new System.ArgumentNullException(nameof(value)); } +#endif return new(value.Left, value.Top, value.Width(), value.Height()); } @@ -48,10 +52,14 @@ public static System.Drawing.Rectangle FromNative(this Rect value) /// A of the value. public static System.Drawing.RectangleF FromNative(this RectF value) { - if (value is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else + if (value == null) { throw new System.ArgumentNullException(nameof(value)); } +#endif return new(value.Left, value.Top, value.Width(), value.Height()); } diff --git a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/BitmapMixins.cs index 17e8aa6b2..08cf6209b 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/BitmapMixins.cs @@ -21,15 +21,11 @@ public static class BitmapMixins /// /// The bitmap to convert. /// A bitmap. - public static UIImage ToNative(this IBitmap value) + public static UIImage ToNative(this IBitmap value) => value switch { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - return ((CocoaBitmap)value).Inner; - } + null => throw new ArgumentNullException(nameof(value)), + _ => ((CocoaBitmap)value).Inner + }; /// /// Converts a to a splat . @@ -37,18 +33,9 @@ public static UIImage ToNative(this IBitmap value) /// The native bitmap to convert from. /// Whether to copy the android bitmap or not. /// A bitmap. - public static IBitmap FromNative(this UIImage value, bool copy = false) + public static IBitmap FromNative(this UIImage value, bool copy = false) => value switch { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - if (copy) - { - return new CocoaBitmap((UIImage)value.Copy()); - } - - return new CocoaBitmap(value); - } + null => throw new ArgumentNullException(nameof(value)), + _ => copy ? new CocoaBitmap((UIImage)value.Copy()) : (IBitmap)new CocoaBitmap(value) + }; } diff --git a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs index f2776d9df..0b2e66b08 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs @@ -51,7 +51,7 @@ public Task Save(CompressedBitmapFormat format, float quality, Stream target) return Task.Run(() => { #if UIKIT - var data = format == CompressedBitmapFormat.Jpeg ? _inner.AsJPEG((float)quality) : _inner.AsPNG(); + var data = (format == CompressedBitmapFormat.Jpeg ? _inner.AsJPEG((float)quality) : _inner.AsPNG())!; data.AsStream().CopyTo(target); #else diff --git a/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs b/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs index 4b2f3fcb0..2800383e4 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs @@ -32,10 +32,14 @@ public static UIColor ToNative(this SplatColor value) => /// The generated. public static SplatColor FromNative(this UIColor value) { - if (value is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else + if (value == null) { - throw new ArgumentNullException(nameof(value)); + throw new System.ArgumentNullException(nameof(value)); } +#endif value.GetRGBA(out var r, out var g, out var b, out var a); return SplatColor.FromArgb((int)(a * 255.0f), (int)(r * 255.0f), (int)(g * 255.0f), (int)(b * 255.0f)); @@ -56,10 +60,14 @@ public static NSColor ToNative(this SplatColor value) => /// The generated. public static SplatColor FromNative(this NSColor value) { - if (value is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else + if (value == null) { - throw new ArgumentNullException(nameof(value)); + throw new System.ArgumentNullException(nameof(value)); } +#endif value.GetRgba(out var r, out var g, out var b, out var a); return SplatColor.FromArgb((int)(a * 255.0f), (int)(r * 255.0f), (int)(g * 255.0f), (int)(b * 255.0f)); diff --git a/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs b/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs index 169f938e0..5e590b715 100644 --- a/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs +++ b/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs @@ -16,10 +16,14 @@ public static class ServiceLocationDrawingInitialization /// The resolver to register against. public static void RegisterPlatformBitmapLoader(this IMutableDependencyResolver resolver) { - if (resolver is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(resolver); +#else + if (resolver == null) { - throw new ArgumentNullException(nameof(resolver)); + throw new System.ArgumentNullException(nameof(resolver)); } +#endif #if !IS_SHARED_NET // not supported in netstandard or NET6 library diff --git a/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs index c330c497e..17d6fdedd 100644 --- a/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs @@ -26,10 +26,14 @@ public static class BitmapMixins /// A bitmap. public static BitmapSource ToNative(this IBitmap value) { - if (value is null) +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(value); +#else + if (value == null) { throw new System.ArgumentNullException(nameof(value)); } +#endif return ((BitmapSourceBitmap)value).Inner ?? throw new InvalidOperationException("The bitmap is not longer valid"); } diff --git a/src/Splat.Drawing/Splat.Drawing.csproj b/src/Splat.Drawing/Splat.Drawing.csproj index 21ef5a47c..35c5e79ef 100644 --- a/src/Splat.Drawing/Splat.Drawing.csproj +++ b/src/Splat.Drawing/Splat.Drawing.csproj @@ -1,8 +1,8 @@ - MonoAndroid12.0;MonoAndroid12.1;MonoAndroid13.0;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;Xamarin.WatchOS10;tizen40;netstandard2.0;net6.0;net7.0;net7.0-android;net7.0-ios;net7.0-tvos;net7.0-macos;net7.0-maccatalyst - $(TargetFrameworks);net462;net472;net6.0-windows;net7.0-windows + MonoAndroid12.0;MonoAndroid12.1;MonoAndroid13.0;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;Xamarin.WatchOS10;tizen40;netstandard2.0;net6.0;net7.0;net7.0-android;net7.0-ios;net7.0-tvos;net7.0-macos;net7.0-maccatalyst;net8.0;net8.0-android;net8.0-ios;net8.0-tvos;net8.0-macos;net8.0-maccatalyst + $(TargetFrameworks);net462;net472;net6.0-windows;net7.0-windows;net8.0-windows Splat .NET Foundation and Contributors A library to make things cross-platform that should be @@ -11,7 +11,7 @@ enable - + true true @@ -59,7 +59,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -93,7 +93,7 @@ - + diff --git a/src/Splat.DryIoc/DryIocDependencyResolver.cs b/src/Splat.DryIoc/DryIocDependencyResolver.cs index eb4a19c2b..14c9f07fb 100644 --- a/src/Splat.DryIoc/DryIocDependencyResolver.cs +++ b/src/Splat.DryIoc/DryIocDependencyResolver.cs @@ -71,16 +71,21 @@ public bool HasRegistration(Type? serviceType, string? contract = null) => /// public virtual void Register(Func factory, Type? serviceType, string? contract = null) { +#pragma warning disable RCS1256 // Invalid argument null check. +#if NETSTANDARD || NETFRAMEWORK if (factory is null) { throw new ArgumentNullException(nameof(factory)); } -#pragma warning disable RCS1256 // Invalid argument null check. if (serviceType is null) { throw new ArgumentNullException(nameof(serviceType)); } +#else + ArgumentNullException.ThrowIfNull(factory); + ArgumentNullException.ThrowIfNull(serviceType); +#endif #pragma warning restore RCS1256 // Invalid argument null check. if (string.IsNullOrEmpty(contract)) diff --git a/src/Splat.DryIoc/Splat.DryIoc.csproj b/src/Splat.DryIoc/Splat.DryIoc.csproj index 89f808088..4db726587 100644 --- a/src/Splat.DryIoc/Splat.DryIoc.csproj +++ b/src/Splat.DryIoc/Splat.DryIoc.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 $(NoWarn);CA1801 DryIoc adapter for Splat diff --git a/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs b/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs index b4ede36f8..0381a70c7 100644 --- a/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs +++ b/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs @@ -16,13 +16,13 @@ namespace Splat.Exceptionless; public sealed class ExceptionlessSplatLogger : ILogger { private static readonly KeyValuePair[] _mappings = - { + [ new(LogLevel.Debug, global::Exceptionless.Logging.LogLevel.Debug), new(LogLevel.Info, global::Exceptionless.Logging.LogLevel.Info), new(LogLevel.Warn, global::Exceptionless.Logging.LogLevel.Warn), new(LogLevel.Error, global::Exceptionless.Logging.LogLevel.Error), new(LogLevel.Fatal, global::Exceptionless.Logging.LogLevel.Fatal), - }; + ]; private static readonly ImmutableDictionary _mappingsDictionary = _mappings.ToImmutableDictionary(); @@ -38,10 +38,14 @@ public ExceptionlessSplatLogger( Type sourceType, ExceptionlessClient exceptionlessClient) { +#if NETSTANDARD || NETFRAMEWORK if (sourceType is null) { throw new ArgumentNullException(nameof(sourceType)); } +#else + ArgumentNullException.ThrowIfNull(sourceType); +#endif _sourceType = sourceType.FullName ?? throw new ArgumentException("Cannot find the source type name", nameof(sourceType)); _exceptionlessClient = exceptionlessClient ?? throw new ArgumentNullException(nameof(exceptionlessClient)); @@ -82,10 +86,14 @@ public void Write(Exception exception, string message, LogLevel logLevel) /// public void Write(string message, Type type, LogLevel logLevel) { +#if NETSTANDARD || NETFRAMEWORK if (type is null) { throw new ArgumentNullException(nameof(type)); } +#else + ArgumentNullException.ThrowIfNull(type); +#endif if ((int)logLevel < (int)Level) { @@ -98,10 +106,14 @@ public void Write(string message, Type type, LogLevel logLevel) /// public void Write(Exception exception, string message, Type type, LogLevel logLevel) { +#if NETSTANDARD || NETFRAMEWORK if (type is null) { throw new ArgumentNullException(nameof(type)); } +#else + ArgumentNullException.ThrowIfNull(type); +#endif if ((int)logLevel < (int)Level) { @@ -113,22 +125,18 @@ public void Write(Exception exception, string message, Type type, LogLevel logLe private void CreateLog(string message, global::Exceptionless.Logging.LogLevel level) => CreateLog(_sourceType, message, level); - private void CreateLog(string type, string message, global::Exceptionless.Logging.LogLevel level) - { + private void CreateLog(string type, string message, global::Exceptionless.Logging.LogLevel level) => _exceptionlessClient.SubmitLog(type, message, level); - } private void CreateLog(Exception exception, string message, global::Exceptionless.Logging.LogLevel level) => CreateLog(exception, _sourceType, message, level); - private void CreateLog(Exception exception, string type, string message, global::Exceptionless.Logging.LogLevel level) - { + private void CreateLog(Exception exception, string type, string message, global::Exceptionless.Logging.LogLevel level) => _exceptionlessClient.CreateLog( type, message, level) .SetException(exception) .Submit(); - } /// /// Works out the log level. diff --git a/src/Splat.Exceptionless/Splat.Exceptionless.csproj b/src/Splat.Exceptionless/Splat.Exceptionless.csproj index 1f2abac40..31ef50c3a 100644 --- a/src/Splat.Exceptionless/Splat.Exceptionless.csproj +++ b/src/Splat.Exceptionless/Splat.Exceptionless.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Splat.Exceptionless Splat @@ -11,7 +11,7 @@ - + diff --git a/src/Splat.Log4Net/Splat.Log4Net.csproj b/src/Splat.Log4Net/Splat.Log4Net.csproj index 3b3c5834a..8b29f727d 100644 --- a/src/Splat.Log4Net/Splat.Log4Net.csproj +++ b/src/Splat.Log4Net/Splat.Log4Net.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Splat.Log4Net Splat diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs index 1279f9819..2ea90a3c8 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs @@ -2,17 +2,13 @@ namespace Splat.Microsoft.Extensions.DependencyInjection.Tests; -internal class ContainerWrapper +internal sealed class ContainerWrapper { private IServiceProvider _serviceProvider; #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - - public ContainerWrapper() + public ContainerWrapper() => ServiceCollection.UseMicrosoftDependencyResolver(); #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - { - ServiceCollection.UseMicrosoftDependencyResolver(); - } public IServiceCollection ServiceCollection { get; } = new ServiceCollection(); diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs b/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs index 692d1ca62..428f321dc 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs @@ -59,10 +59,14 @@ protected virtual IServiceProvider? ServiceProvider /// A ready to use service provider. public void UpdateContainer(IServiceProvider serviceProvider) { +#if NETSTANDARD || NETFRAMEWORK if (serviceProvider is null) { throw new ArgumentNullException(nameof(serviceProvider)); } +#else + ArgumentNullException.ThrowIfNull(serviceProvider); +#endif lock (_syncLock) { @@ -384,7 +388,7 @@ public void RemoveLastFactory(string contract) => } [SuppressMessage("Design", "CA1812: Unused class.", Justification = "Used in reflection.")] - private class ContractDictionary : ContractDictionary + private sealed class ContractDictionary : ContractDictionary { } } diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj b/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj index e8392f3e1..ddd9548a5 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj +++ b/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj @@ -1,13 +1,13 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 enable - + diff --git a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs index a73fe8767..0965eef46 100644 --- a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs +++ b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs @@ -20,9 +20,15 @@ public void Dispose() /// public global::Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName) => new SplatLoggingAdapter(categoryName); - private class SplatLoggingAdapter(string categoryName) : global::Microsoft.Extensions.Logging.ILogger + private sealed class SplatLoggingAdapter(string categoryName) : global::Microsoft.Extensions.Logging.ILogger { +#pragma warning disable CA1823 // Avoid unused private fields +#pragma warning disable IDE0052 // Remove unread private members +#pragma warning disable RCS1213 // Remove unused member declaration. private readonly string _categoryName = categoryName; +#pragma warning restore RCS1213 // Remove unused member declaration. +#pragma warning restore IDE0052 // Remove unread private members +#pragma warning restore CA1823 // Avoid unused private fields /// public void Log(global::Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) @@ -32,10 +38,14 @@ public void Log(global::Microsoft.Extensions.Logging.LogLevel logLevel, return; } +#if NETSTANDARD || NETFRAMEWORK if (formatter is null) { throw new ArgumentNullException(nameof(formatter)); } +#else + ArgumentNullException.ThrowIfNull(formatter); +#endif var splatLogLevel = MsLoggingHelpers.MsLog2SplatDictionary[logLevel]; diff --git a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs index af1a052e4..bcacaa67f 100644 --- a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs +++ b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs @@ -51,10 +51,14 @@ public static void UseMicrosoftExtensionsLoggingWithWrappingFullLogger( /// The logging builder. public static ILoggingBuilder AddSplat(this ILoggingBuilder builder) { +#if NETSTANDARD || NETFRAMEWORK if (builder is null) { throw new System.ArgumentNullException(nameof(builder)); } +#else + ArgumentNullException.ThrowIfNull(builder); +#endif builder.Services.AddSingleton(); @@ -68,12 +72,18 @@ public static ILoggingBuilder AddSplat(this ILoggingBuilder builder) /// The factory. public static ILoggerFactory AddSplat(this ILoggerFactory loggerFactory) { +#if NETSTANDARD || NETFRAMEWORK if (loggerFactory is null) { throw new System.ArgumentNullException(nameof(loggerFactory)); } +#else + ArgumentNullException.ThrowIfNull(loggerFactory); +#endif +#pragma warning disable CA2000 // Dispose objects before losing scope loggerFactory.AddProvider(new MicrosoftExtensionsLogProvider()); +#pragma warning restore CA2000 // Dispose objects before losing scope return loggerFactory; } } diff --git a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs index 6c65a9f7a..f9e002c73 100644 --- a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs +++ b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs @@ -55,10 +55,14 @@ public LogLevel Level [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "Deliberate Usage")] public void Write(string message, Type type, LogLevel logLevel) { +#if NETSTANDARD || NETFRAMEWORK if (type is null) { throw new ArgumentNullException(nameof(type)); } +#else + ArgumentNullException.ThrowIfNull(type); +#endif using (_inner.BeginScope(type.ToString())) { @@ -71,10 +75,14 @@ public void Write(string message, Type type, LogLevel logLevel) [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "Deliberate Usage")] public void Write(Exception exception, string message, Type type, LogLevel logLevel) { +#if NETSTANDARD || NETFRAMEWORK if (type is null) { throw new ArgumentNullException(nameof(type)); } +#else + ArgumentNullException.ThrowIfNull(type); +#endif using (_inner.BeginScope(type.ToString())) { diff --git a/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj b/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj index 4e333d6f4..5adaf35cd 100644 --- a/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj +++ b/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Splat.Microsoft.Extensions.Logging Splat @@ -10,8 +10,8 @@ enable - - + + diff --git a/src/Splat.NLog/Splat.NLog.csproj b/src/Splat.NLog/Splat.NLog.csproj index c5985552a..d2db18c19 100644 --- a/src/Splat.NLog/Splat.NLog.csproj +++ b/src/Splat.NLog/Splat.NLog.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Splat.NLog Splat @@ -11,7 +11,7 @@ - + diff --git a/src/Splat.Ninject/Splat.Ninject.csproj b/src/Splat.Ninject/Splat.Ninject.csproj index 67a46b8e0..a7417a03f 100644 --- a/src/Splat.Ninject/Splat.Ninject.csproj +++ b/src/Splat.Ninject/Splat.Ninject.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Autofac adapter for Splat enable diff --git a/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj b/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj index 8e4f212a6..bf0a021d7 100644 --- a/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj +++ b/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Prism adapter for Splat including Xamarin Forms adapters. enable diff --git a/src/Splat.Prism/Splat.Prism.csproj b/src/Splat.Prism/Splat.Prism.csproj index 8d1503d44..7acb66b24 100644 --- a/src/Splat.Prism/Splat.Prism.csproj +++ b/src/Splat.Prism/Splat.Prism.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Prism adapter for Splat enable diff --git a/src/Splat.Raygun/Splat.Raygun.csproj b/src/Splat.Raygun/Splat.Raygun.csproj index f3da0862b..3fc47ddcc 100644 --- a/src/Splat.Raygun/Splat.Raygun.csproj +++ b/src/Splat.Raygun/Splat.Raygun.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Splat.Raygun Splat diff --git a/src/Splat.Serilog/Splat.Serilog.csproj b/src/Splat.Serilog/Splat.Serilog.csproj index 92a75109a..5e602c5b4 100644 --- a/src/Splat.Serilog/Splat.Serilog.csproj +++ b/src/Splat.Serilog/Splat.Serilog.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 Splat.Serilog Splat @@ -10,8 +10,8 @@ enable - - + + diff --git a/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs b/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs index 9ca61b2ed..4eeb65509 100644 --- a/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs +++ b/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs @@ -62,12 +62,13 @@ public void Register(Func factory, Type? serviceType, string? contract lock (_lockObject) { - if (!RegisteredFactories.ContainsKey(serviceType)) + if (!RegisteredFactories.TryGetValue(serviceType, out var value)) { - RegisteredFactories.Add(serviceType, []); + value = []; + RegisteredFactories.Add(serviceType, value); } - RegisteredFactories[serviceType].Add(() => + value.Add(() => isNull ? new NullServiceType(factory) : factory()); diff --git a/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj b/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj index e0cf9c768..e608bc52e 100644 --- a/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj +++ b/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 $(TargetFrameworks);net462 SimpleInjector adapter for Splat enable diff --git a/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs b/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs index e5d4873bc..11669be5e 100644 --- a/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs +++ b/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs @@ -8,7 +8,7 @@ namespace Splat.SimpleInjector; -internal class TransientSimpleInjectorRegistration(Container container, Type implementationType, Func? instanceCreator = null) : Registration(Lifestyle.Transient, container, implementationType, instanceCreator!) +internal sealed class TransientSimpleInjectorRegistration(Container container, Type implementationType, Func? instanceCreator = null) : Registration(Lifestyle.Transient, container, implementationType, instanceCreator!) { public override Expression BuildExpression() => BuildTransientExpression(); } diff --git a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt index 8315a230e..cf933b68d 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt +++ b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt @@ -491,7 +491,6 @@ namespace Splat { public LoggingException() { } public LoggingException(string message) { } - protected LoggingException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public LoggingException(string message, System.Exception innerException) { } } public sealed class MemoizingMRUCache diff --git a/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs b/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs index 4bc8beb7b..f2e021826 100644 --- a/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs +++ b/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs @@ -16,7 +16,7 @@ namespace Splat.Tests.Logging; /// public class NLogLoggerTests : FullLoggerTestBase { - private static readonly Dictionary _NLog2Splat = new() + private static readonly Dictionary _nLog2Splat = new() { { global::NLog.LogLevel.Debug, LogLevel.Debug }, { global::NLog.LogLevel.Error, LogLevel.Error }, @@ -53,7 +53,7 @@ protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(Log return (new NLogLogger(LogManager.GetCurrentClassLogger()), errorTarget); } - private class MemoryTargetWrapper : TargetWithLayout, IMockLogTarget + private sealed class MemoryTargetWrapper : TargetWithLayout, IMockLogTarget { private readonly List<(LogLevel, string)> _logs = []; @@ -65,6 +65,6 @@ private class MemoryTargetWrapper : TargetWithLayout, IMockLogTarget /// Renders the logging event message and adds it to the internal ArrayList of log messages. /// /// The logging event. - protected override void Write(LogEventInfo logEvent) => _logs.Add((_NLog2Splat[logEvent.Level], RenderLogEvent(Layout, logEvent))); + protected override void Write(LogEventInfo logEvent) => _logs.Add((_nLog2Splat[logEvent.Level], RenderLogEvent(Layout, logEvent))); } } diff --git a/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs b/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs index 202523d2a..30dede74d 100644 --- a/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs +++ b/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs @@ -19,7 +19,7 @@ namespace Splat.Tests.Logging; /// public class SerilogLoggerTests : FullLoggerTestBase { - private static readonly char[] NewLine = Environment.NewLine.ToCharArray(); + private static readonly char[] _newLine = Environment.NewLine.ToCharArray(); /// /// Gets a list of mappings of Serilog levels and equivalent Splat log levels. @@ -66,7 +66,7 @@ public void Configuring_With_Static_Log_Should_Write_Message() logger.Log().Debug("This is a test."); Assert.Equal(1, target.Logs.Count); - Assert.Equal("This is a test.", target.Logs.Last().message!.Trim(NewLine).Trim()); + Assert.Equal("This is a test.", target.Logs.Last().message!.Trim(_newLine).Trim()); } finally { @@ -94,7 +94,7 @@ public void Configuring_With_PreConfigured_Log_Should_Write_Message() logger.Log().Debug("This is a test."); Assert.Equal(1, target.Logs.Count); - Assert.Equal("This is a test.", target.Logs.Last().message!.Trim(NewLine).Trim()); + Assert.Equal("This is a test.", target.Logs.Last().message!.Trim(_newLine).Trim()); } finally { @@ -125,7 +125,7 @@ private static (Logger logger, IMockLogTarget mockTarget) CreateSerilogger(LogLe return (log, messages); } - private class LogTarget : ILogEventSink, IMockLogTarget + private sealed class LogTarget : ILogEventSink, IMockLogTarget { private static readonly MessageTemplateTextFormatter _formatter = new("{Message} {Exception}", CultureInfo.InvariantCulture); private readonly List<(LogLevel logLevel, string message)> _logs = []; diff --git a/src/Splat.Tests/Logging/StaticLoggerTests.cs b/src/Splat.Tests/Logging/StaticLoggerTests.cs index cea275aa9..4fa7e990a 100644 --- a/src/Splat.Tests/Logging/StaticLoggerTests.cs +++ b/src/Splat.Tests/Logging/StaticLoggerTests.cs @@ -315,8 +315,10 @@ public void Logger_Level_AtBoundary_Should_Be_correct() private static StaticFullLogger GetLogger(LogLevel logLevel) { - var textLogger = new TextLogger(); - textLogger.Level = logLevel; + var textLogger = new TextLogger + { + Level = logLevel + }; var wrappingFullLogger = new WrappingFullLogger(textLogger); return new(wrappingFullLogger); @@ -332,10 +334,10 @@ private static void Test_Write_Message(Action testMethodFunc) Assert.Equal(1, textLogger.Logs.Count); var line = textLogger.Logs.First(); - var startOfCallerMemberSuffix = line.message.IndexOf("(", StringComparison.Ordinal); + var startOfCallerMemberSuffix = line.message.IndexOf('(', StringComparison.Ordinal); Assert.True(startOfCallerMemberSuffix > 0); - var endOfCallerMemberSuffix = line.message.IndexOf(")", startOfCallerMemberSuffix, StringComparison.Ordinal); + var endOfCallerMemberSuffix = line.message.IndexOf(')', startOfCallerMemberSuffix); Assert.True(endOfCallerMemberSuffix > startOfCallerMemberSuffix + 1); } } diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs index 38a832481..27152da4a 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs @@ -22,7 +22,7 @@ protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(Log return (new WrappingFullLogger(new WrappingLogLevelLogger(new ConsoleLogger { Level = minimumLogLevel, ExceptionMessageFormat = "{0} {1}" })), outputWriter); } - private class ConsoleWriter : TextWriter, IMockLogTarget + private sealed class ConsoleWriter : TextWriter, IMockLogTarget { private readonly List<(LogLevel logLevel, string message)> _logs = []; @@ -32,7 +32,7 @@ private class ConsoleWriter : TextWriter, IMockLogTarget public override void WriteLine(string? value) { - var colonIndex = value!.IndexOf(":", StringComparison.InvariantCulture); + var colonIndex = value!.IndexOf(':', StringComparison.InvariantCulture); var level = (LogLevel)Enum.Parse(typeof(LogLevel), value.AsSpan(0, colonIndex)); var message = value.Substring(colonIndex + 1).Trim(); _logs.Add((level, message)); diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs index 55542e5dc..1ab678984 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs @@ -75,7 +75,7 @@ private static void PluginAction(EventPluginContext obj, InMemoryExceptionlessLo logTarget.Logs.Add(tuple); } - private class InMemoryExceptionlessLogTarget : IMockLogTarget + private sealed class InMemoryExceptionlessLogTarget : IMockLogTarget { public InMemoryExceptionlessLogTarget() => Logs = new List<(LogLevel logLevel, string message)>(); diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs index ea2da1621..c2b2388b5 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs @@ -77,7 +77,7 @@ private MemoryTargetWrapper CreateRepository(LogLevel minimumLogLevel) return memoryWrapper; } - private class MemoryTargetWrapper(global::log4net.Appender.MemoryAppender memoryTarget) : IMockLogTarget + private sealed class MemoryTargetWrapper(global::log4net.Appender.MemoryAppender memoryTarget) : IMockLogTarget { public global::log4net.Appender.MemoryAppender MemoryTarget { get; } = memoryTarget; @@ -90,12 +90,11 @@ private class MemoryTargetWrapper(global::log4net.Appender.MemoryAppender memory { var currentLevel = _log4Net2Splat[x.Level]; - if (x.ExceptionObject is not null) + return x.ExceptionObject switch { - return (currentLevel, $"{x.MessageObject} {x.ExceptionObject}"); - } - - return (currentLevel, x.MessageObject.ToString()!); + not null => (currentLevel, $"{x.MessageObject} {x.ExceptionObject}"), + _ => (currentLevel, x.MessageObject.ToString()!) + }; }).ToList(); } } diff --git a/src/Splat.sln b/src/Splat.sln index b8993159e..25a0b4147 100644 --- a/src/Splat.sln +++ b/src/Splat.sln @@ -8,10 +8,12 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B370F1-BEF3-4AB7-BA08-CC5D83E74598}" ProjectSection(SolutionItems) = preProject ..\.editorconfig = ..\.editorconfig + ..\.github\workflows\ci-build.yml = ..\.github\workflows\ci-build.yml Directory.build.props = Directory.build.props Directory.build.targets = Directory.build.targets global.json = global.json ..\README.md = ..\README.md + ..\.github\workflows\release.yml = ..\.github\workflows\release.yml stylecop.json = stylecop.json ..\version.json = ..\version.json EndProjectSection diff --git a/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs b/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs index 611a553de..86ed42f29 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs @@ -17,9 +17,11 @@ public static class EnableFeatureUsageTrackingExtensions /// instance of class that uses IEnableFeatureUsageTracking. /// Name of the feature. /// Feature Usage Tracking Session. +#pragma warning disable RCS1175 // Unused 'this' parameter. public static IFeatureUsageTrackingSession FeatureUsageTrackingSession( this IEnableFeatureUsageTracking instance, string featureName) +#pragma warning restore RCS1175 // Unused 'this' parameter. { var featureUsageTrackingSession = Locator.Current.GetService(); return featureUsageTrackingSession switch @@ -40,10 +42,14 @@ public static void WithFeatureUsageTrackingSession( string featureName, Action action) { +#if NETSTANDARD if (action is null) { throw new ArgumentNullException(nameof(action)); } +#else + ArgumentNullException.ThrowIfNull(action); +#endif using var session = instance.FeatureUsageTrackingSession(featureName); try @@ -68,6 +74,7 @@ public static void WithSubFeatureUsageTrackingSession( string featureName, Action action) { +#if NETSTANDARD if (instance is null) { throw new ArgumentNullException(nameof(instance)); @@ -77,6 +84,10 @@ public static void WithSubFeatureUsageTrackingSession( { throw new ArgumentNullException(nameof(action)); } +#else + ArgumentNullException.ThrowIfNull(instance); + ArgumentNullException.ThrowIfNull(action); +#endif using var session = instance.SubFeature(featureName); try diff --git a/src/Splat/Disposables/CompositeDisposable.cs b/src/Splat/Disposables/CompositeDisposable.cs index c1858d920..e1aadc815 100644 --- a/src/Splat/Disposables/CompositeDisposable.cs +++ b/src/Splat/Disposables/CompositeDisposable.cs @@ -47,10 +47,14 @@ public CompositeDisposable(int capacity) /// Any of the disposables in the collection is null. public CompositeDisposable(params IDisposable[] disposables) { +#if NETSTANDARD if (disposables is null) { throw new ArgumentNullException(nameof(disposables)); } +#else + ArgumentNullException.ThrowIfNull(disposables); +#endif _disposables = new(disposables.Length); Init(disposables); diff --git a/src/Splat/Logging/FullLoggerExtensions.cs b/src/Splat/Logging/FullLoggerExtensions.cs index cec7fe79f..e001d46df 100644 --- a/src/Splat/Logging/FullLoggerExtensions.cs +++ b/src/Splat/Logging/FullLoggerExtensions.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; + namespace Splat; /// @@ -17,6 +19,7 @@ public static class FullLoggerExtensions /// The function to evaluate if Debug logging is enabled. public static void Debug(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -26,6 +29,10 @@ public static void Debug(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsDebugEnabled) { @@ -41,6 +48,7 @@ public static void Debug(this IFullLogger logger, Func function) /// The function to evaluate if Debug logging is enabled. public static void Debug(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -50,6 +58,10 @@ public static void Debug(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsDebugEnabled) { @@ -65,6 +77,7 @@ public static void Debug(this IFullLogger logger, Func function) /// A exception to log about. public static void DebugException(this IFullLogger logger, Func function, Exception exception) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -74,6 +87,10 @@ public static void DebugException(this IFullLogger logger, Func function { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsDebugEnabled) { @@ -90,6 +107,7 @@ public static void DebugException(this IFullLogger logger, Func function /// The function to evaluate if Debug logging is enabled. public static void Info(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -99,6 +117,10 @@ public static void Info(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsInfoEnabled) { @@ -114,6 +136,7 @@ public static void Info(this IFullLogger logger, Func function) /// The function to evaluate if Debug logging is enabled. public static void Info(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -123,6 +146,10 @@ public static void Info(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsInfoEnabled) { @@ -138,6 +165,7 @@ public static void Info(this IFullLogger logger, Func function) /// A exception to log about. public static void InfoException(this IFullLogger logger, Func function, Exception exception) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -147,6 +175,10 @@ public static void InfoException(this IFullLogger logger, Func function, { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsInfoEnabled) { @@ -163,6 +195,7 @@ public static void InfoException(this IFullLogger logger, Func function, /// The function to evaluate if Warn logging is enabled. public static void Warn(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -172,6 +205,10 @@ public static void Warn(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsWarnEnabled) { @@ -187,6 +224,7 @@ public static void Warn(this IFullLogger logger, Func function) /// The function to evaluate if Warn logging is enabled. public static void Warn(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -196,6 +234,10 @@ public static void Warn(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsWarnEnabled) { @@ -211,6 +253,7 @@ public static void Warn(this IFullLogger logger, Func function) /// A exception to log about. public static void WarnException(this IFullLogger logger, Func function, Exception exception) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -220,6 +263,10 @@ public static void WarnException(this IFullLogger logger, Func function, { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsWarnEnabled) { @@ -236,6 +283,7 @@ public static void WarnException(this IFullLogger logger, Func function, /// The function to evaluate if Error logging is enabled. public static void Error(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -245,6 +293,10 @@ public static void Error(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsErrorEnabled) { @@ -260,6 +312,7 @@ public static void Error(this IFullLogger logger, Func function) /// The function to evaluate if Error logging is enabled. public static void Error(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -269,6 +322,10 @@ public static void Error(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsErrorEnabled) { @@ -284,6 +341,7 @@ public static void Error(this IFullLogger logger, Func function) /// A exception to log about. public static void ErrorException(this IFullLogger logger, Func function, Exception exception) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -293,6 +351,10 @@ public static void ErrorException(this IFullLogger logger, Func function { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsErrorEnabled) { @@ -309,6 +371,7 @@ public static void ErrorException(this IFullLogger logger, Func function /// The function to evaluate if Fatal logging is enabled. public static void Fatal(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -318,6 +381,10 @@ public static void Fatal(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsFatalEnabled) { @@ -333,6 +400,7 @@ public static void Fatal(this IFullLogger logger, Func function) /// The function to evaluate if Fatal logging is enabled. public static void Fatal(this IFullLogger logger, Func function) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -342,6 +410,10 @@ public static void Fatal(this IFullLogger logger, Func function) { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsFatalEnabled) { @@ -357,6 +429,7 @@ public static void Fatal(this IFullLogger logger, Func function) /// A exception to log about. public static void FatalException(this IFullLogger logger, Func function, Exception exception) { +#if NETSTANDARD if (logger is null) { throw new ArgumentNullException(nameof(logger)); @@ -366,6 +439,10 @@ public static void FatalException(this IFullLogger logger, Func function { throw new ArgumentNullException(nameof(function)); } +#else + ArgumentNullException.ThrowIfNull(logger); + ArgumentNullException.ThrowIfNull(function); +#endif if (logger.IsFatalEnabled) { diff --git a/src/Splat/Logging/LogManagerMixin.cs b/src/Splat/Logging/LogManagerMixin.cs index c45d4c927..e4b12c254 100644 --- a/src/Splat/Logging/LogManagerMixin.cs +++ b/src/Splat/Logging/LogManagerMixin.cs @@ -18,10 +18,14 @@ public static class LogManagerMixin /// A logger for the specified type. public static IFullLogger GetLogger(this ILogManager logManager) { +#if NETSTANDARD if (logManager is null) { throw new System.ArgumentNullException(nameof(logManager)); } +#else + System.ArgumentNullException.ThrowIfNull(logManager); +#endif return logManager.GetLogger(typeof(T)); } diff --git a/src/Splat/Logging/LoggingException.cs b/src/Splat/Logging/LoggingException.cs index 976112f16..bd1364667 100644 --- a/src/Splat/Logging/LoggingException.cs +++ b/src/Splat/Logging/LoggingException.cs @@ -38,12 +38,4 @@ public LoggingException(string message, Exception innerException) : base(message, innerException) { } - - /// Initializes a new instance of the class. - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - protected LoggingException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } diff --git a/src/Splat/Logging/WrappingPrefixLogger.cs b/src/Splat/Logging/WrappingPrefixLogger.cs index e112be3b9..5a7c6bd96 100644 --- a/src/Splat/Logging/WrappingPrefixLogger.cs +++ b/src/Splat/Logging/WrappingPrefixLogger.cs @@ -25,18 +25,22 @@ public class WrappingPrefixLogger(ILogger inner, Type callingType) : ILogger public LogLevel Level => _inner.Level; /// - public void Write([Localizable(false)]string message, LogLevel logLevel) => _inner.Write(_prefix + message, logLevel); + public void Write([Localizable(false)] string message, LogLevel logLevel) => _inner.Write(_prefix + message, logLevel); /// - public void Write(Exception exception, [Localizable(false)]string message, LogLevel logLevel) => _inner.Write(exception, _prefix + message, logLevel); + public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) => _inner.Write(exception, _prefix + message, logLevel); /// public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) { +#if NETSTANDARD if (type is null) { throw new ArgumentNullException(nameof(type)); } +#else + ArgumentNullException.ThrowIfNull(type); +#endif _inner.Write($"{type.Name}: {message}", type, logLevel); } @@ -44,10 +48,14 @@ public void Write([Localizable(false)] string message, [Localizable(false)] Type /// public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) { +#if NETSTANDARD if (type is null) { throw new ArgumentNullException(nameof(type)); } +#else + ArgumentNullException.ThrowIfNull(type); +#endif _inner.Write(exception, $"{type.Name}: {message}", type, logLevel); } diff --git a/src/Splat/ModeDetection/DefaultModeDetector.cs b/src/Splat/ModeDetection/DefaultModeDetector.cs index faa0cdbd8..211c50c0f 100644 --- a/src/Splat/ModeDetection/DefaultModeDetector.cs +++ b/src/Splat/ModeDetection/DefaultModeDetector.cs @@ -44,5 +44,9 @@ private static bool SearchForAssembly(IEnumerable assemblyList) => .Select(x => x.FullName?.ToUpperInvariant()) .Where(x => x is not null) .Select(x => x!) +#if NETSTANDARD .Any(x => assemblyList.Any(name => x.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1)); +#else + .Any(x => assemblyList.Any(name => x.Contains(name, StringComparison.InvariantCultureIgnoreCase))); +#endif } diff --git a/src/Splat/ServiceLocation/DependencyResolverMixins.cs b/src/Splat/ServiceLocation/DependencyResolverMixins.cs index c0bfbdf60..a2f68b847 100644 --- a/src/Splat/ServiceLocation/DependencyResolverMixins.cs +++ b/src/Splat/ServiceLocation/DependencyResolverMixins.cs @@ -20,10 +20,14 @@ public static class DependencyResolverMixins /// The requested object, if found; null otherwise. public static T? GetService(this IReadonlyDependencyResolver resolver, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif return (T?)resolver.GetService(typeof(T), contract); } @@ -39,10 +43,14 @@ public static class DependencyResolverMixins /// should be empty (not null) if no objects of the given type are available. public static IEnumerable GetServices(this IReadonlyDependencyResolver resolver, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif return resolver.GetServices(typeof(T), contract).Cast(); } @@ -56,10 +64,14 @@ public static IEnumerable GetServices(this IReadonlyDependencyResolver res /// A disposable which will stop notifications to the callback. public static IDisposable ServiceRegistrationCallback(this IMutableDependencyResolver resolver, Type serviceType, Action callback) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif return resolver.ServiceRegistrationCallback(serviceType, null, callback); } @@ -73,10 +85,14 @@ public static IDisposable ServiceRegistrationCallback(this IMutableDependencyRes /// A disposable which will reset the resolver back to the original. public static IDisposable WithResolver(this IDependencyResolver resolver, bool suppressResolverCallback = true) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif var notificationDisposable = suppressResolverCallback ? Locator.SuppressResolverCallbackChangedNotifications() : ActionDisposable.Empty; @@ -95,6 +111,7 @@ public static IDisposable WithResolver(this IDependencyResolver resolver, bool s /// A optional contract value which will indicates to only generate the value if this contract is specified. public static void Register(this IMutableDependencyResolver resolver, Func factory, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); @@ -104,6 +121,10 @@ public static void Register(this IMutableDependencyResolver resolver, Func factory(), typeof(T), contract); } @@ -118,10 +139,14 @@ public static void Register(this IMutableDependencyResolver resolver, Func(this IMutableDependencyResolver resolver, string? contract = null) where T : new() { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif resolver.Register(() => new T(), typeof(TAs), contract); } @@ -135,10 +160,14 @@ public static void Register(this IMutableDependencyResolver resolver, st /// A optional contract value which will indicates to only return the value if this contract is specified. public static void RegisterConstant(this IMutableDependencyResolver resolver, object? value, Type? serviceType, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif resolver.Register(() => value, serviceType, contract); } @@ -152,10 +181,14 @@ public static void RegisterConstant(this IMutableDependencyResolver resolver, ob /// A optional contract value which will indicates to only return the value if this contract is specified. public static void RegisterConstant(this IMutableDependencyResolver resolver, T? value, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif RegisterConstant(resolver, value, typeof(T), contract); } @@ -170,10 +203,14 @@ public static void RegisterConstant(this IMutableDependencyResolver resolver, /// A optional contract value which will indicates to only return the value if this contract is specified. public static void RegisterLazySingleton(this IMutableDependencyResolver resolver, Func valueFactory, Type? serviceType, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif var val = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); resolver.Register(() => val.Value, serviceType, contract); @@ -197,10 +234,14 @@ public static void RegisterLazySingleton(this IMutableDependencyResolver resolve /// A optional contract which indicates to only removed the item registered with this contract. public static void UnregisterCurrent(this IMutableDependencyResolver resolver, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif resolver.UnregisterCurrent(typeof(T), contract); } @@ -213,10 +254,14 @@ public static void UnregisterCurrent(this IMutableDependencyResolver resolver /// A optional contract which indicates to only removed those items registered with this contract. public static void UnregisterAll(this IMutableDependencyResolver resolver, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif resolver.UnregisterAll(typeof(T), contract); } diff --git a/src/Splat/ServiceLocation/FuncDependencyResolver.cs b/src/Splat/ServiceLocation/FuncDependencyResolver.cs index 958396c60..0d1231ad8 100644 --- a/src/Splat/ServiceLocation/FuncDependencyResolver.cs +++ b/src/Splat/ServiceLocation/FuncDependencyResolver.cs @@ -86,7 +86,7 @@ public void Register(Func factory, Type? serviceType, string? contract foreach (var callback in callbackList) { - var disp = new BooleanDisposable(); + using var disp = new BooleanDisposable(); callback(disp); @@ -136,14 +136,15 @@ public IDisposable ServiceRegistrationCallback(Type serviceType, string? contrac { var pair = (serviceType, contract ?? string.Empty); - if (!_callbackRegistry.ContainsKey(pair)) + if (!_callbackRegistry.TryGetValue(pair, out var value)) { - _callbackRegistry[pair] = []; + value = []; + _callbackRegistry[pair] = value; } - _callbackRegistry[pair].Add(callback); + value.Add(callback); - return new ActionDisposable(() => _callbackRegistry[pair].Remove(callback)); + return new ActionDisposable(() => value.Remove(callback)); } /// diff --git a/src/Splat/ServiceLocation/Locator.cs b/src/Splat/ServiceLocation/Locator.cs index b60813fed..736c1c114 100644 --- a/src/Splat/ServiceLocation/Locator.cs +++ b/src/Splat/ServiceLocation/Locator.cs @@ -63,10 +63,14 @@ public static class Locator /// ignore this. public static IDisposable RegisterResolverCallbackChanged(Action callback) { +#if NETSTANDARD if (callback is null) { throw new ArgumentNullException(nameof(callback)); } +#else + ArgumentNullException.ThrowIfNull(callback); +#endif return InternalLocator.RegisterResolverCallbackChanged(callback); } diff --git a/src/Splat/ServiceLocation/ModernDependencyResolver.cs b/src/Splat/ServiceLocation/ModernDependencyResolver.cs index aa7ce33a9..e06526875 100644 --- a/src/Splat/ServiceLocation/ModernDependencyResolver.cs +++ b/src/Splat/ServiceLocation/ModernDependencyResolver.cs @@ -75,12 +75,13 @@ public void Register(Func factory, Type? serviceType, string? contract var pair = GetKey(serviceType, contract); - if (!_registry.ContainsKey(pair)) + if (!_registry.TryGetValue(pair, out var value)) { - _registry[pair] = []; + value = []; + _registry[pair] = value; } - _registry[pair].Add(() => + value.Add(() => isNull ? new NullServiceType(factory) : factory()); @@ -94,7 +95,7 @@ public void Register(Func factory, Type? serviceType, string? contract foreach (var callback in callbackList) { - var disp = new BooleanDisposable(); + using var disp = new BooleanDisposable(); callback(disp); @@ -124,12 +125,12 @@ public void Register(Func factory, Type? serviceType, string? contract serviceType ??= typeof(NullServiceType); var pair = GetKey(serviceType, contract); - if (!_registry.ContainsKey(pair)) + if (!_registry.TryGetValue(pair, out var value)) { return default; } - var ret = _registry[pair].LastOrDefault(); + var ret = value.LastOrDefault(); object? returnValue = default; if (ret != null) { @@ -154,12 +155,7 @@ public IEnumerable GetServices(Type? serviceType, string? contract = nul serviceType ??= typeof(NullServiceType); var pair = GetKey(serviceType, contract); - if (!_registry.ContainsKey(pair)) - { - return Array.Empty(); - } - - return _registry[pair].ConvertAll(x => x()!); + return !_registry.TryGetValue(pair, out var value) ? Array.Empty() : value.ConvertAll(x => x()!); } /// @@ -206,6 +202,7 @@ public void UnregisterAll(Type? serviceType, string? contract = null) /// public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) { +#if NETSTANDARD if (serviceType is null) { throw new ArgumentNullException(nameof(serviceType)); @@ -215,6 +212,10 @@ public IDisposable ServiceRegistrationCallback(Type serviceType, string? contrac { throw new ArgumentNullException(nameof(callback)); } +#else + ArgumentNullException.ThrowIfNull(serviceType); + ArgumentNullException.ThrowIfNull(callback); +#endif if (_registry is null) { @@ -223,14 +224,15 @@ public IDisposable ServiceRegistrationCallback(Type serviceType, string? contrac var pair = GetKey(serviceType, contract); - if (!_callbackRegistry.ContainsKey(pair)) + if (!_callbackRegistry.TryGetValue(pair, out var value)) { - _callbackRegistry[pair] = []; + value = []; + _callbackRegistry[pair] = value; } - _callbackRegistry[pair].Add(callback); + value.Add(callback); - var disp = new ActionDisposable(() => _callbackRegistry[pair].Remove(callback)); + var disp = new ActionDisposable(() => value.Remove(callback)); if (!_registry.TryGetValue(pair, out var callbackList)) { diff --git a/src/Splat/ServiceLocation/ResolverMixins.cs b/src/Splat/ServiceLocation/ResolverMixins.cs index 228472680..83da6a753 100644 --- a/src/Splat/ServiceLocation/ResolverMixins.cs +++ b/src/Splat/ServiceLocation/ResolverMixins.cs @@ -20,10 +20,14 @@ public static class ResolverMixins public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, string? contract = null) where T : new() { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif resolver.Register(() => new T(), typeof(T), contract); return resolver; @@ -39,6 +43,7 @@ public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyR /// The resolver. public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, Func factory, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); @@ -48,6 +53,10 @@ public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyR { throw new ArgumentNullException(nameof(factory)); } +#else + ArgumentNullException.ThrowIfNull(resolver); + ArgumentNullException.ThrowIfNull(factory); +#endif resolver.Register(() => factory()!, typeof(T), contract); return resolver; @@ -64,10 +73,14 @@ public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyR public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, string? contract = null) where T : new() { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif resolver.Register(() => new T(), typeof(TAs), contract); return resolver; @@ -84,6 +97,7 @@ public static IMutableDependencyResolver RegisterAnd(this IMutableDepend /// The resolver. public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, Func factory, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); @@ -93,6 +107,10 @@ public static IMutableDependencyResolver RegisterAnd(this IMutableDepend { throw new ArgumentNullException(nameof(factory)); } +#else + ArgumentNullException.ThrowIfNull(resolver); + ArgumentNullException.ThrowIfNull(factory); +#endif resolver.Register(() => factory()!, typeof(TAs), contract); return resolver; @@ -108,10 +126,14 @@ public static IMutableDependencyResolver RegisterAnd(this IMutableDepend /// The resolver. public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, object value, Type serviceType, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif resolver.Register(() => value, serviceType, contract); return resolver; @@ -127,10 +149,14 @@ public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDepend public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, string? contract = null) where T : new() { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif var value = new T(); return resolver.RegisterAnd(() => value, contract); @@ -146,10 +172,14 @@ public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDep /// The resolver. public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, T value, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif return resolver.RegisterAnd(() => value, contract); } @@ -165,10 +195,14 @@ public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDep /// The resolver. public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, Func valueFactory, Type serviceType, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif var val = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); resolver.Register(() => val.Value, serviceType, contract); @@ -186,10 +220,14 @@ public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableD public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, string? contract = null) where T : new() { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif var val = new Lazy(() => new T(), LazyThreadSafetyMode.ExecutionAndPublication); resolver.Register(() => val.Value, typeof(T), contract); @@ -207,10 +245,14 @@ public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutab /// The resolver. public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, Func valueFactory, string? contract = null) { +#if NETSTANDARD if (resolver is null) { throw new ArgumentNullException(nameof(resolver)); } +#else + ArgumentNullException.ThrowIfNull(resolver); +#endif var val = new Lazy(() => valueFactory()!, LazyThreadSafetyMode.ExecutionAndPublication); resolver.Register(() => val.Value, typeof(T), contract); diff --git a/src/Splat/ServiceLocation/ServiceLocationInitialization.cs b/src/Splat/ServiceLocation/ServiceLocationInitialization.cs index 618bda076..85e61340f 100644 --- a/src/Splat/ServiceLocation/ServiceLocationInitialization.cs +++ b/src/Splat/ServiceLocation/ServiceLocationInitialization.cs @@ -18,10 +18,14 @@ public static class ServiceLocationInitialization /// The resolver to register the needed service types against. public static void InitializeSplat(this IMutableDependencyResolver resolver) { +#if NETSTANDARD if (resolver is null) { throw new System.ArgumentNullException(nameof(resolver)); } +#else + System.ArgumentNullException.ThrowIfNull(resolver); +#endif RegisterDefaultLogManager(resolver); RegisterLogger(resolver); diff --git a/src/Splat/Splat.csproj b/src/Splat/Splat.csproj index 61fc9413b..966151c63 100644 --- a/src/Splat/Splat.csproj +++ b/src/Splat/Splat.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 Splat Splat .NET Foundation and Contributors diff --git a/src/global.json b/src/global.json index d0516b067..d9af7e6d6 100644 --- a/src/global.json +++ b/src/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.400", + "version": "8.0.10", "rollForward": "latestMinor", "allowPrerelease": true },