From f5c6079367bbda564aeb01661762b8ce9da0add8 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Mon, 5 Dec 2022 22:42:27 +0000 Subject: [PATCH 1/4] Remove Unsupported Targets Add Net 7.0 Remove MonoAndroid11.0 Add MonoAndroid12.0 and MonoAndroid13.0 --- src/Directory.build.props | 4 ++-- src/Directory.build.targets | 12 +++++------ .../ReactiveUI.DI.Tests.csproj | 2 +- src/Splat.AppCenter/Splat.AppCenter.csproj | 6 +++--- .../Splat.ApplicationInsights.csproj | 4 ++-- src/Splat.Autofac/Splat.Autofac.csproj | 2 +- src/Splat.Drawing/Splat.Drawing.csproj | 20 +++++++------------ src/Splat.DryIoc/Splat.DryIoc.csproj | 4 ++-- .../Splat.Exceptionless.csproj | 2 +- src/Splat.Log4Net/Splat.Log4Net.csproj | 4 ++-- ...soft.Extensions.DependencyInjection.csproj | 2 +- .../Splat.Microsoft.Extensions.Logging.csproj | 2 +- src/Splat.NLog/Splat.NLog.csproj | 4 ++-- src/Splat.Ninject/Splat.Ninject.csproj | 2 +- .../Splat.Prism.Forms.csproj | 4 ++-- src/Splat.Prism/Splat.Prism.csproj | 4 ++-- src/Splat.Raygun/Splat.Raygun.csproj | 4 ++-- src/Splat.Serilog/Splat.Serilog.csproj | 2 +- .../Splat.SimpleInjector.csproj | 2 +- src/Splat/Splat.csproj | 2 +- 20 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src/Directory.build.props b/src/Directory.build.props index de00e5bac..6493a639d 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -52,7 +52,7 @@ - + @@ -76,7 +76,7 @@ - + diff --git a/src/Directory.build.targets b/src/Directory.build.targets index c812b1970..0d12551ec 100644 --- a/src/Directory.build.targets +++ b/src/Directory.build.targets @@ -14,22 +14,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 @@ -38,13 +38,13 @@ $(DefineConstants);MONO;ANDROID - + $(DefineConstants);MONO;ANDROID $(DefineConstants);TIZEN - + $(DefineConstants);IS_SHARED_NET diff --git a/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj b/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj index fd2e2da55..122deda7f 100644 --- a/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj +++ b/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj @@ -28,7 +28,7 @@ - + diff --git a/src/Splat.AppCenter/Splat.AppCenter.csproj b/src/Splat.AppCenter/Splat.AppCenter.csproj index e25aad38e..9a9d2e81b 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 + netstandard2.0;net6.0-windows10.0.17763.0;net7.0-windows10.0.17763.0 Splat.AppCenter Splat @@ -13,8 +13,8 @@ - - + + diff --git a/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj b/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj index 7d41cfadf..1e0b69268 100644 --- a/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj +++ b/src/Splat.ApplicationInsights/Splat.ApplicationInsights.csproj @@ -1,6 +1,6 @@ - + - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Splat.ApplicationInsights Splat diff --git a/src/Splat.Autofac/Splat.Autofac.csproj b/src/Splat.Autofac/Splat.Autofac.csproj index bead20705..2522fbd8b 100644 --- a/src/Splat.Autofac/Splat.Autofac.csproj +++ b/src/Splat.Autofac/Splat.Autofac.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Autofac adapter for Splat latest diff --git a/src/Splat.Drawing/Splat.Drawing.csproj b/src/Splat.Drawing/Splat.Drawing.csproj index 22bf3ba97..8dd41df6b 100644 --- a/src/Splat.Drawing/Splat.Drawing.csproj +++ b/src/Splat.Drawing/Splat.Drawing.csproj @@ -1,8 +1,8 @@ - MonoAndroid11.0;MonoAndroid12.1;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;Xamarin.WatchOS10;tizen40;netstandard2.0;net6.0;net6.0-android;net6.0-ios;net6.0-tvos;net6.0-macos;net6.0-maccatalyst - $(TargetFrameworks);net462;net472;uap10.0.16299;net6.0-windows + MonoAndroid12.0;MonoAndroid12.1;MonoAndroid13.0;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;Xamarin.WatchOS10;tizen40;netstandard2.0;net6.0;net6.0-android;net6.0-ios;net6.0-tvos;net6.0-macos;net6.0-maccatalyst;net7.0;net7.0-android;net7.0-ios;net7.0-tvos;net7.0-macos;net7.0-maccatalyst + $(TargetFrameworks);net462;net472;uap10.0.17763;net6.0-windows;net7.0-windows Splat .NET Foundation and Contributors A library to make things cross-platform that should be @@ -12,7 +12,7 @@ enable - + true true @@ -62,13 +62,7 @@ - - - - - - - + @@ -86,7 +80,7 @@ - + @@ -97,7 +91,7 @@ - + @@ -108,7 +102,7 @@ - + diff --git a/src/Splat.DryIoc/Splat.DryIoc.csproj b/src/Splat.DryIoc/Splat.DryIoc.csproj index 9b0816ede..44e825f37 100644 --- a/src/Splat.DryIoc/Splat.DryIoc.csproj +++ b/src/Splat.DryIoc/Splat.DryIoc.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 $(NoWarn);CA1801 DryIoc adapter for Splat @@ -9,7 +9,7 @@ - + diff --git a/src/Splat.Exceptionless/Splat.Exceptionless.csproj b/src/Splat.Exceptionless/Splat.Exceptionless.csproj index fead34083..40518105e 100644 --- a/src/Splat.Exceptionless/Splat.Exceptionless.csproj +++ b/src/Splat.Exceptionless/Splat.Exceptionless.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Splat.Exceptionless Splat diff --git a/src/Splat.Log4Net/Splat.Log4Net.csproj b/src/Splat.Log4Net/Splat.Log4Net.csproj index e1bc9d2fe..b5157d7f1 100644 --- a/src/Splat.Log4Net/Splat.Log4Net.csproj +++ b/src/Splat.Log4Net/Splat.Log4Net.csproj @@ -1,6 +1,6 @@ - + - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Splat.Log4Net Splat 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 6909012c0..e9ac0769f 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj +++ b/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 latest enable 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 810a20982..f68bceb96 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 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Splat.Microsoft.Extensions.Logging Splat diff --git a/src/Splat.NLog/Splat.NLog.csproj b/src/Splat.NLog/Splat.NLog.csproj index abe9084d3..f6823e80c 100644 --- a/src/Splat.NLog/Splat.NLog.csproj +++ b/src/Splat.NLog/Splat.NLog.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Splat.NLog Splat @@ -11,7 +11,7 @@ enable - + diff --git a/src/Splat.Ninject/Splat.Ninject.csproj b/src/Splat.Ninject/Splat.Ninject.csproj index 0afd720c9..70589d9ae 100644 --- a/src/Splat.Ninject/Splat.Ninject.csproj +++ b/src/Splat.Ninject/Splat.Ninject.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Autofac adapter for Splat latest diff --git a/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj b/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj index 6c3fbe470..d808a78c7 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 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Prism adapter for Splat including Xamarin Forms adapters. latest diff --git a/src/Splat.Prism/Splat.Prism.csproj b/src/Splat.Prism/Splat.Prism.csproj index 672d3a714..ff6464b02 100644 --- a/src/Splat.Prism/Splat.Prism.csproj +++ b/src/Splat.Prism/Splat.Prism.csproj @@ -1,7 +1,7 @@ - + - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Prism adapter for Splat latest diff --git a/src/Splat.Raygun/Splat.Raygun.csproj b/src/Splat.Raygun/Splat.Raygun.csproj index df1a848f6..df7624f48 100644 --- a/src/Splat.Raygun/Splat.Raygun.csproj +++ b/src/Splat.Raygun/Splat.Raygun.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Splat.Raygun Splat @@ -13,7 +13,7 @@ - + diff --git a/src/Splat.Serilog/Splat.Serilog.csproj b/src/Splat.Serilog/Splat.Serilog.csproj index 6a327ffe0..4e5798693 100644 --- a/src/Splat.Serilog/Splat.Serilog.csproj +++ b/src/Splat.Serilog/Splat.Serilog.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 Splat.Serilog Splat diff --git a/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj b/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj index c3ff03a48..91a96fc35 100644 --- a/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj +++ b/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 SimpleInjector adapter for Splat latest diff --git a/src/Splat/Splat.csproj b/src/Splat/Splat.csproj index 6fc4b9061..6790a263d 100644 --- a/src/Splat/Splat.csproj +++ b/src/Splat/Splat.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net6.0 + netstandard2.0;net6.0;net7.0 Splat Splat .NET Foundation and Contributors From 5af86fd8ec7a39505495d1d054a7f562e287b474 Mon Sep 17 00:00:00 2001 From: Glenn Watson <5834289+glennawatson@users.noreply.github.com> Date: Wed, 7 Dec 2022 11:13:51 +1100 Subject: [PATCH 2/4] housekeeping: Fix tests and formatting --- .editorconfig | 40 +- .gitattributes | 5 +- .gitignore | 69 +- src/Directory.build.props | 29 +- .../AutoFacReactiveUIDependencyTests.cs | 119 +- .../DryIocReactiveUIDependencyTests.cs | 61 +- .../Mocks/ActivatingView.cs | 117 +- .../Mocks/ActivatingViewFetcher.cs | 65 +- .../Mocks/ActivatingViewModel.cs | 49 +- ...SimpleInjectorReactiveUIDependencyTests.cs | 77 +- .../ViewWithViewContractThatShouldNotLoad.cs | 43 +- .../AppCenterFeatureUsageTrackingSession.cs | 113 +- src/Splat.AppCenter/AppCenterViewTracking.cs | 38 +- src/Splat.AppCenter/Splat.AppCenter.csproj | 4 +- ...tionInsightsFeatureUsageTrackingSession.cs | 135 +- .../ApplicationInsightsViewTracking.cs | 69 +- .../DependencyResolverTests.cs | 515 +- .../AutofacDependencyResolver.cs | 425 +- src/Splat.Autofac/SplatAutofacExtensions.cs | 28 +- src/Splat.Common.Test/DummyObjectClass1.cs | 15 +- src/Splat.Common.Test/DummyObjectClass2.cs | 15 +- src/Splat.Common.Test/DummyObjectClass3.cs | 15 +- src/Splat.Common.Test/IDummyInterface.cs | 15 +- src/Splat.Common.Test/IScreen.cs | 14 +- src/Splat.Common.Test/IViewFor.cs | 46 +- src/Splat.Common.Test/IViewModelOne.cs | 16 +- src/Splat.Common.Test/MockScreen.cs | 17 +- src/Splat.Common.Test/ViewModelOne.cs | 19 +- src/Splat.Common.Test/ViewModelTwo.cs | 15 +- src/Splat.Common.Test/ViewOne.cs | 31 +- .../ViewThatShouldNotLoad.cs | 41 +- src/Splat.Common.Test/ViewTwo.cs | 31 +- ...ests.SplatUIProject.DotNet6_0.verified.txt | 2 +- .../API/ApiApprovalTests.cs | 23 +- src/Splat.Drawing.Tests/BitmapLoaderTests.cs | 150 +- .../Colors/CoverageColorTests.cs | 436 +- .../Colors/KnownColorTests.cs | 50 +- .../Colors/SplatColorTests.cs | 80 +- .../PlatformBitmapLoaderTests.cs | 88 +- src/Splat.Drawing/Bitmaps/BitmapLoader.cs | 46 +- .../Bitmaps/BitmapLoaderException.cs | 67 +- .../Bitmaps/CompressedBitmapFormat.cs | 25 +- src/Splat.Drawing/Bitmaps/IBitmap.cs | 47 +- src/Splat.Drawing/Bitmaps/IBitmapLoader.cs | 59 +- .../Colors/SplatColor.KnownColors.cs | 1419 +++-- src/Splat.Drawing/Colors/SplatColor.cs | 756 ++- .../DefaultPlatformModeDetector.cs | 118 +- src/Splat.Drawing/IPlatformModeDetector.cs | 19 +- src/Splat.Drawing/PlatformModeDetector.cs | 75 +- .../Android/Bitmaps/AndroidBitmap.cs | 70 +- .../Platforms/Android/Bitmaps/BitmapMixins.cs | 87 +- .../Android/Bitmaps/DrawableBitmap.cs | 60 +- .../Android/Bitmaps/PlatformBitmapLoader.cs | 370 +- .../Android/Colors/ColorExtensions.cs | 41 +- .../Android/Colors/SplatColorExtensions.cs | 41 +- .../Android/Maths/PointExtensions.cs | 89 +- .../Platforms/Android/Maths/RectExtensions.cs | 89 +- .../Platforms/Cocoa/Bitmaps/BitmapMixins.cs | 63 +- .../Platforms/Cocoa/Bitmaps/CocoaBitmap.cs | 99 +- .../Cocoa/Bitmaps/PlatformBitmapLoader.cs | 159 +- .../Cocoa/Colors/SplatColorExtensions.cs | 91 +- .../Platforms/ReflectionStubs.cs | 133 +- .../ServiceLocationDrawingInitialization.cs | 35 +- .../Platforms/Tizen/Bitmaps/BitmapMixins.cs | 49 +- .../Tizen/Bitmaps/PlatformBitmapLoader.cs | 60 +- .../Platforms/Tizen/Bitmaps/TizenBitmap.cs | 200 +- .../WinRT/Bitmaps/BitmapImageBitmap.cs | 76 +- .../Platforms/WinRT/Bitmaps/BitmapMixins.cs | 79 +- .../WinRT/Bitmaps/DispatcherMixin.cs | 57 +- .../WinRT/Bitmaps/PlatformBitmapLoader.cs | 123 +- .../Bitmaps/WriteableBitmapImageBitmap.cs | 83 +- .../Platforms/WinRT/Colors/ColorExtensions.cs | 59 +- .../WinRT/Colors/SplatColorExtensions.cs | 59 +- .../Platforms/net4/Bitmaps/BitmapMixins.cs | 47 +- .../net4/Bitmaps/BitmapSourceBitmap.cs | 77 +- .../net4/Bitmaps/PlatformBitmapLoader.cs | 113 +- .../Platforms/net4/Colors/ColorExtensions.cs | 63 +- .../net4/Colors/SplatColorExtensions.cs | 63 +- .../Platforms/net4/Maths/PointExtensions.cs | 59 +- .../Platforms/net4/Maths/RectExtensions.cs | 59 +- .../Platforms/net4/Maths/SizeExtensions.cs | 59 +- .../Platforms/net6/Bitmaps/BitmapMixins.cs | 47 +- .../net6/Bitmaps/BitmapSourceBitmap.cs | 77 +- .../net6/Bitmaps/PlatformBitmapLoader.cs | 127 +- .../Platforms/net6/Colors/ColorExtensions.cs | 63 +- .../net6/Colors/SplatColorExtensions.cs | 63 +- .../Platforms/net6/Maths/PointExtensions.cs | 59 +- .../Platforms/net6/Maths/RectExtensions.cs | 59 +- .../Platforms/net6/Maths/SizeExtensions.cs | 59 +- src/Splat.Drawing/Splat.Drawing.csproj | 4 + .../DependencyResolverTests.cs | 541 +- src/Splat.DryIoc/DryIocDependencyResolver.cs | 347 +- src/Splat.DryIoc/Splat.DryIoc.csproj | 2 +- src/Splat.DryIoc/SplatDryIocExtensions.cs | 21 +- ...xceptionlessFeatureUsageTrackingSession.cs | 109 +- .../ExceptionlessSplatLogger.cs | 267 +- .../ExceptionlessViewTracking.cs | 62 +- .../MutableDependencyResolverExtensions.cs | 51 +- src/Splat.Log4Net/Log4NetLogger.cs | 329 +- src/Splat.Log4Net/LogResolver.cs | 27 +- .../MutableDependencyResolverExtensions.cs | 43 +- .../ContainerWrapper.cs | 26 +- .../DependencyResolverTests.cs | 308 +- .../MicrosoftDependencyResolverTests.cs | 101 +- .../MicrosoftDependencyResolver.cs | 590 +- .../SplatMicrosoftExtensions.cs | 59 +- .../MicrosoftExtensionsLogProvider.cs | 94 +- .../MicrosoftExtensionsLoggingExtensions.cs | 113 +- .../MicrosoftExtensionsLoggingLogger.cs | 126 +- .../MsLoggingHelpers.cs | 27 +- src/Splat.NLog/LogResolver.cs | 29 +- .../MutableDependencyResolverExtensions.cs | 43 +- src/Splat.NLog/NLogLogger.cs | 1779 +++--- src/Splat.NLog/Splat.NLog.csproj | 2 +- .../DependencyResolverTests.cs | 305 +- .../NInjectDependencyResolverTests.cs | 101 +- .../NinjectDependencyResolver.cs | 235 +- src/Splat.Ninject/SplatNinjectExtensions.cs | 21 +- src/Splat.Prism.Forms/PrismApplication.cs | 34 +- .../DependencyResolverTests.cs | 539 +- src/Splat.Prism/SplatContainerExtension.cs | 459 +- .../RaygunFeatureUsageTrackingSession.cs | 162 +- .../MutableDependencyResolverExtensions.cs | 81 +- src/Splat.Serilog/Registration.cs | 27 +- src/Splat.Serilog/SerilogFullLogger.cs | 1711 +++--- src/Splat.Serilog/SerilogHelper.cs | 40 +- .../DependencyResolverTests.cs | 217 +- .../SimpleInjectorDependencyResolver.cs | 205 +- .../SimpleInjectorInitializer.cs | 186 +- .../SplatSimpleInjectorExtensions.cs | 23 +- .../TransientSimpleInjectorRegistration.cs | 15 +- ...lTests.SplatProject.DotNet6_0.verified.txt | 2 +- src/Splat.Tests/API/ApiApprovalTests.cs | 25 +- src/Splat.Tests/ApiExtensions.cs | 41 +- ...pCenterFeatureUsageTrackingSessionTests.cs | 40 +- .../AppCenterViewTrackingTests.cs | 23 +- ...nsightsFeatureUsageTrackingSessionTests.cs | 61 +- .../ApplicationInsightsViewTrackingTests.cs | 32 +- .../BaseFeatureUsageTrackingTests.cs | 121 +- .../BaseViewTrackingTests.cs | 47 +- ...ableFeatureUsageTrackingExtensionsTests.cs | 197 +- ...ionlessFeatureUsageTrackingSessionTests.cs | 40 +- .../RaygunFeatureUsageTrackingSessionTests.cs | 60 +- src/Splat.Tests/LocatorSerialRegisterTests.cs | 551 +- src/Splat.Tests/LocatorTests.cs | 701 ++- src/Splat.Tests/Logging/ActionLoggerTests.cs | 657 ++- .../AllocateFreeErrorLoggerTestBase.cs | 1994 ++++--- .../AllocationFreeLoggerBaseTestBase.cs | 1994 ++++--- .../Logging/BaseTests/FullLoggerTestBase.cs | 1020 ++-- .../Logging/BaseTests/LoggerBase.cs | 859 ++- .../BaseTests/WrappingFullLoggerTestBase.cs | 649 ++- .../Logging/FullLoggers/NLogLoggerTests.cs | 99 +- .../Logging/FullLoggers/SerilogLoggerTests.cs | 209 +- .../Logging/Helpers/FormatHelper.cs | 27 +- src/Splat.Tests/Logging/StaticLoggerTests.cs | 851 ++- .../WrappingFullLoggers/ConsoleLoggerTests.cs | 53 +- .../ExceptionlessLoggerTests.cs | 125 +- .../WrappingFullLoggers/Log4NetLoggerTests.cs | 145 +- .../MicrosoftExtensionsLoggingLoggerTests.cs | 121 +- .../Logging/WrappingPrefixLoggerTests.cs | 343 +- src/Splat.Tests/MemoizingMRUCacheTests.cs | 357 +- src/Splat.Tests/Mocks/IMockLogTarget.cs | 17 +- src/Splat.Tests/Mocks/TextLogger.cs | 77 +- src/Splat.Tests/ModeDetection/ModeTests.cs | 57 +- .../BaseDependencyResolverTests.cs | 399 +- .../ModernDependencyResolverTests.cs | 20 +- .../TargetFrameworkExtensionsTests.cs | 313 +- src/Splat.Tests/XUnitHelpers.cs | 34 +- .../DefaultFeatureUsageTrackingManager.cs | 19 +- .../DefaultFeatureUsageTrackingSession.cs | 103 +- .../EnableFeatureUsageTrackingExtensions.cs | 137 +- .../FuncFeatureUsageTrackingManager.cs | 41 +- .../IEnableFeatureUsageTracking.cs | 16 +- .../IFeatureUsageTrackingManager.cs | 21 +- .../IFeatureUsageTrackingSession.cs | 39 +- ...ureUsageTrackingSession{TReferenceType}.cs | 27 +- .../IViewTracking.cs | 19 +- src/Splat/AssemblyFinder.cs | 62 +- src/Splat/Disposables/ActionDisposable.cs | 39 +- src/Splat/Disposables/BooleanDisposable.cs | 57 +- src/Splat/Disposables/CompositeDisposable.cs | 209 +- src/Splat/Logging/ActionLogger.cs | 95 +- src/Splat/Logging/AllocationFreeLoggerBase.cs | 4909 ++++++++--------- src/Splat/Logging/ConsoleLogger.cs | 85 +- src/Splat/Logging/DebugLogger.cs | 79 +- src/Splat/Logging/DefaultLogManager.cs | 73 +- src/Splat/Logging/FullLoggerExtensions.cs | 712 ++- src/Splat/Logging/FuncLogManager.cs | 35 +- .../Logging/IAllocationFreeErrorLogger.cs | 1815 +++--- src/Splat/Logging/IAllocationFreeLogger.cs | 1766 +++--- src/Splat/Logging/IEnableLogger.cs | 20 +- src/Splat/Logging/IFullLogger.cs | 1061 ++-- src/Splat/Logging/ILogManager.cs | 21 +- src/Splat/Logging/ILogger.cs | 73 +- src/Splat/Logging/IStaticFullLogger.cs | 697 ++- src/Splat/Logging/LocalizableAttribute.cs | 37 +- src/Splat/Logging/LogHost.cs | 79 +- src/Splat/Logging/LogLevel.cs | 50 +- src/Splat/Logging/LogManagerMixin.cs | 31 +- src/Splat/Logging/LoggingException.cs | 67 +- src/Splat/Logging/NullLogger.cs | 47 +- src/Splat/Logging/StaticFullLogger.cs | 569 +- src/Splat/Logging/WrappingFullLogger.cs | 701 ++- src/Splat/Logging/WrappingLogLevelLogger.cs | 82 +- src/Splat/Logging/WrappingPrefixLogger.cs | 88 +- src/Splat/Maths/PointMathExtensions.cs | 223 +- src/Splat/Maths/RectEdge.cs | 41 +- src/Splat/Maths/RectangleMathExtensions.cs | 249 +- src/Splat/Maths/SizeMathExtensions.cs | 51 +- src/Splat/MemoizingMRUCache.cs | 484 +- .../ModeDetection/DefaultModeDetector.cs | 70 +- src/Splat/ModeDetection/IModeDetector.cs | 19 +- src/Splat/ModeDetection/Mode.cs | 33 +- src/Splat/ModeDetection/ModeDetector.cs | 79 +- src/Splat/Properties/AssemblyInfo.cs | 1 - .../DependencyResolverMixins.cs | 358 +- .../ServiceLocation/FuncDependencyResolver.cs | 281 +- .../ServiceLocation/IDependencyResolver.cs | 16 +- .../IMutableDependencyResolver.cs | 93 +- .../IReadonlyDependencyResolver.cs | 43 +- src/Splat/ServiceLocation/InternalLocator.cs | 229 +- src/Splat/ServiceLocation/Locator.cs | 162 +- .../ModernDependencyResolver.cs | 428 +- src/Splat/ServiceLocation/NullServiceType.cs | 27 +- src/Splat/ServiceLocation/ResolverMixins.cs | 355 +- .../ServiceLocationInitialization.cs | 61 +- src/Splat/TargetFrameworkExtensions.cs | 105 +- 227 files changed, 24011 insertions(+), 24317 deletions(-) diff --git a/.editorconfig b/.editorconfig index 453e3a1ef..bf2e10935 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,9 +12,11 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true +[project.json] +indent_size = 2 + # C# files [*.cs] - # New line preferences csharp_new_line_before_open_brace = all csharp_new_line_before_else = true @@ -151,27 +153,21 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_parentheses = false csharp_space_between_square_brackets = false -# analyzers +# analyzers.ruleset dotnet_diagnostic.AvoidAsyncVoid.severity = suggestion - -dotnet_diagnostic.CA1000.severity = none dotnet_diagnostic.CA1001.severity = error dotnet_diagnostic.CA1009.severity = error -dotnet_diagnostic.CA1014.severity = none dotnet_diagnostic.CA1016.severity = error -dotnet_diagnostic.CA1030.severity = none -dotnet_diagnostic.CA1031.severity = none -dotnet_diagnostic.CA1033.severity = none dotnet_diagnostic.CA1036.severity = none dotnet_diagnostic.CA1049.severity = error dotnet_diagnostic.CA1056.severity = suggestion dotnet_diagnostic.CA1060.severity = error dotnet_diagnostic.CA1061.severity = error +dotnet_diagnostic.CA1062.severity = none dotnet_diagnostic.CA1063.severity = error dotnet_diagnostic.CA1065.severity = error dotnet_diagnostic.CA1301.severity = error -dotnet_diagnostic.CA1303.severity = none -dotnet_diagnostic.CA1308.severity = none +dotnet_diagnostic.CA1305.severity = none dotnet_diagnostic.CA1400.severity = error dotnet_diagnostic.CA1401.severity = error dotnet_diagnostic.CA1403.severity = error @@ -186,7 +182,7 @@ dotnet_diagnostic.CA1810.severity = none dotnet_diagnostic.CA1821.severity = error dotnet_diagnostic.CA1900.severity = error dotnet_diagnostic.CA1901.severity = error -dotnet_diagnostic.CA2000.severity = none +dotnet_diagnostic.CA2000.severity = suggestion dotnet_diagnostic.CA2002.severity = error dotnet_diagnostic.CA2007.severity = none dotnet_diagnostic.CA2100.severity = error @@ -230,7 +226,6 @@ dotnet_diagnostic.CA2238.severity = error dotnet_diagnostic.CA2240.severity = error dotnet_diagnostic.CA2241.severity = error dotnet_diagnostic.CA2242.severity = error - dotnet_diagnostic.RCS1001.severity = error dotnet_diagnostic.RCS1018.severity = error dotnet_diagnostic.RCS1037.severity = error @@ -243,7 +238,6 @@ dotnet_diagnostic.RCS1074.severity = error dotnet_diagnostic.RCS1090.severity = error dotnet_diagnostic.RCS1138.severity = error dotnet_diagnostic.RCS1139.severity = error -dotnet_diagnostic.RCS1158.severity = none dotnet_diagnostic.RCS1163.severity = suggestion dotnet_diagnostic.RCS1168.severity = suggestion dotnet_diagnostic.RCS1188.severity = error @@ -251,7 +245,6 @@ dotnet_diagnostic.RCS1201.severity = error dotnet_diagnostic.RCS1207.severity = error dotnet_diagnostic.RCS1211.severity = error dotnet_diagnostic.RCS1507.severity = error - dotnet_diagnostic.SA1000.severity = error dotnet_diagnostic.SA1001.severity = error dotnet_diagnostic.SA1002.severity = error @@ -348,10 +341,9 @@ dotnet_diagnostic.SA1311.severity = none dotnet_diagnostic.SA1312.severity = error dotnet_diagnostic.SA1313.severity = error dotnet_diagnostic.SA1314.severity = error -dotnet_diagnostic.SA1316.severity = none dotnet_diagnostic.SA1400.severity = error dotnet_diagnostic.SA1401.severity = error -dotnet_diagnostic.SA1402.severity = error +dotnet_diagnostic.SA1402.severity = none dotnet_diagnostic.SA1403.severity = error dotnet_diagnostic.SA1404.severity = error dotnet_diagnostic.SA1405.severity = error @@ -362,9 +354,9 @@ dotnet_diagnostic.SA1410.severity = error dotnet_diagnostic.SA1411.severity = error dotnet_diagnostic.SA1413.severity = none dotnet_diagnostic.SA1500.severity = error -dotnet_diagnostic.SA1501.severity = error +dotnet_diagnostic.SA1501.severity = none dotnet_diagnostic.SA1502.severity = error -dotnet_diagnostic.SA1503.severity = error +dotnet_diagnostic.SA1503.severity = none dotnet_diagnostic.SA1504.severity = error dotnet_diagnostic.SA1505.severity = error dotnet_diagnostic.SA1506.severity = error @@ -419,28 +411,22 @@ dotnet_diagnostic.SA1640.severity = error dotnet_diagnostic.SA1641.severity = error dotnet_diagnostic.SA1642.severity = error dotnet_diagnostic.SA1643.severity = error +dotnet_diagnostic.SA1648.severity = error dotnet_diagnostic.SA1649.severity = error dotnet_diagnostic.SA1651.severity = error - dotnet_diagnostic.SX1101.severity = error dotnet_diagnostic.SX1309.severity = error dotnet_diagnostic.SX1623.severity = none -dotnet_diagnostic.IDE0046.severity = suggestion -dotnet_diagnostic.IDE0060.severity = none - # C++ Files [*.{cpp,h,in}] curly_bracket_next_line = true indent_brace_style = Allman # Xml project files -[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] indent_size = 2 -[*.{csproj,vbproj,proj,nativeproj,locproj}] -charset = utf-8 - # Xml build files [*.builds] indent_size = 2 @@ -461,5 +447,5 @@ indent_size = 2 [*.sh] end_of_line = lf -[*.{cmd,bat}] +[*.{cmd, bat}] end_of_line = crlf diff --git a/.gitattributes b/.gitattributes index 269bc192f..2dbab83b2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,7 +2,7 @@ * text=auto # Text files that should be normalized to LF in odb. -*.cs text eol=lf diff=csharp +*.cs text diff=csharp *.xaml text *.config text *.c text @@ -40,6 +40,3 @@ *.pdb binary *.sdf binary *.7z binary - -# Generated file should just use CRLF, it's fiiine -SolutionInfo.cs text eol=crlf diff=csharp diff --git a/.gitignore b/.gitignore index 4e0bfccfc..8062720c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore # User-specific files *.rsuser @@ -23,12 +23,14 @@ mono_crash.* [Rr]eleases/ x64/ x86/ +[Ww][Ii][Nn]32/ [Aa][Rr][Mm]/ [Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ +[Ll]ogs/ # Visual Studio 2015/2017 cache/options directory .vs/ @@ -42,7 +44,7 @@ Generated\ Files/ [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* -# NUNIT +# NUnit *.VisualState.xml TestResult.xml nunit-*.xml @@ -60,6 +62,9 @@ project.lock.json project.fragment.lock.json artifacts/ +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + # StyleCop StyleCopReport.xml @@ -85,6 +90,7 @@ StyleCopReport.xml *.tmp_proj *_wpftmp.csproj *.log +*.tlog *.vspscc *.vssscc .builds @@ -126,9 +132,6 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user -# JustCode is a .NET coding add-in -.JustCode - # TeamCity is a build add-in _TeamCity* @@ -139,6 +142,11 @@ _TeamCity* .axoCover/* !.axoCover/settings.json +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + # Visual Studio code coverage results *.coverage *.coveragexml @@ -286,6 +294,17 @@ node_modules/ # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) *.vbw +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts @@ -309,8 +328,8 @@ __pycache__/ *.pyc # Cake - Uncomment if you are using it -tools/** -!tools/packages.config +# tools/** +# !tools/packages.config # Tabs Studio *.tss @@ -342,24 +361,42 @@ ASALocalRun/ # Local History for Visual Studio .localhistory/ +# Visual Studio History (VSHistory) files +.vshistory/ + # BeatPulse healthcheck temp database healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 MigrationBackup/ -# ReactiveUI -artifacts/ -src/ReactiveUI.Events*/Events_*.cs +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ -# macOS -.DS_Store +# Fody - auto-generated XML schema +FodyWeavers.xsd -# Jetbrains -.idea/ +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace -# API Approval -src/*.Tests/API/*.received.txt +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains +.idea/ +*.sln.iml # Fody Weavers (for tests) src/Tools/ diff --git a/src/Directory.build.props b/src/Directory.build.props index 99eadd9ae..a1236fe5f 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -19,17 +19,18 @@ git true true - nullable + nullable True latest AllEnabledByDefault + true false - $(EnableSourceLink) + $(EnableSourceLink) - true + true true @@ -40,11 +41,11 @@ Full - + true - + @@ -52,7 +53,7 @@ - + @@ -60,25 +61,25 @@ - + - + - - + + $(MSBuildThisFileDirectory) - - - + + + - + diff --git a/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs b/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs index 157b6e0d2..6927f1a3f 100644 --- a/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs +++ b/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs @@ -13,80 +13,79 @@ using Splat.Autofac; using Xunit; -namespace ReactiveUI.DI.Tests +namespace ReactiveUI.DI.Tests; + +/// +/// AutoFac ReactiveUI DependencyTests. +/// +public class AutoFacReactiveUIDependencyTests { /// - /// AutoFac ReactiveUI DependencyTests. + /// Should register ReactiveUI binding type converters. /// - public class AutoFacReactiveUIDependencyTests + [Fact] + public void AutofacDependencyResolverShouldRegisterReactiveUIBindingTypeConverters() { - /// - /// Should register ReactiveUI binding type converters. - /// - [Fact] - public void AutofacDependencyResolverShouldRegisterReactiveUIBindingTypeConverters() - { - // Invoke RxApp which initializes the ReactiveUI platform. - var builder = new ContainerBuilder(); - var locator = new AutofacDependencyResolver(builder); - locator.InitializeReactiveUI(); - Locator.SetLocator(locator); - var container = builder.Build(); + // Invoke RxApp which initializes the ReactiveUI platform. + var builder = new ContainerBuilder(); + var locator = new AutofacDependencyResolver(builder); + locator.InitializeReactiveUI(); + Locator.SetLocator(locator); + var container = builder.Build(); - var converters = container.Resolve>().ToList(); + var converters = container.Resolve>().ToList(); - converters.Should().NotBeNull(); - converters.Should().Contain(x => x.GetType() == typeof(StringConverter)); - converters.Should().Contain(x => x.GetType() == typeof(EqualityTypeConverter)); - } + converters.Should().NotBeNull(); + converters.Should().Contain(x => x.GetType() == typeof(StringConverter)); + converters.Should().Contain(x => x.GetType() == typeof(EqualityTypeConverter)); + } - /// - /// Should register ReactiveUI creates command bindings. - /// - [Fact] - public void AutofacDependencyResolverShouldRegisterReactiveUICreatesCommandBinding() - { - // Invoke RxApp which initializes the ReactiveUI platform. - var builder = new ContainerBuilder(); - var locator = new AutofacDependencyResolver(builder); - locator.InitializeReactiveUI(); - Locator.SetLocator(locator); - var container = builder.Build(); + /// + /// Should register ReactiveUI creates command bindings. + /// + [Fact] + public void AutofacDependencyResolverShouldRegisterReactiveUICreatesCommandBinding() + { + // Invoke RxApp which initializes the ReactiveUI platform. + var builder = new ContainerBuilder(); + var locator = new AutofacDependencyResolver(builder); + locator.InitializeReactiveUI(); + Locator.SetLocator(locator); + var container = builder.Build(); - var converters = container.Resolve>().ToList(); + var converters = container.Resolve>().ToList(); - converters.Should().NotBeNull(); - converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent)); - converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter)); - } + converters.Should().NotBeNull(); + converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent)); + converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter)); + } - /// - /// Automatics the fac when any test. - /// - [Fact] - public void AutoFacWhenAnyTest() - { - var builder = new ContainerBuilder(); + /// + /// Automatics the fac when any test. + /// + [Fact] + public void AutoFacWhenAnyTest() + { + var builder = new ContainerBuilder(); - var autofacResolver = builder.UseAutofacDependencyResolver(); - Locator.CurrentMutable.RegisterConstant(new ActivatingViewFetcher(), typeof(IActivationForViewFetcher)); - autofacResolver.InitializeSplat(); - autofacResolver.InitializeReactiveUI(); - var container = builder.Build(); + var autofacResolver = builder.UseAutofacDependencyResolver(); + Locator.CurrentMutable.RegisterConstant(new ActivatingViewFetcher(), typeof(IActivationForViewFetcher)); + autofacResolver.InitializeSplat(); + autofacResolver.InitializeReactiveUI(); + var container = builder.Build(); - var vm = new ActivatingViewModel(); - var fixture = new ActivatingView { ViewModel = vm }; + var vm = new ActivatingViewModel(); + var fixture = new ActivatingView { ViewModel = vm }; - Assert.Equal(0, vm.IsActiveCount); - Assert.Equal(0, fixture.IsActiveCount); + Assert.Equal(0, vm.IsActiveCount); + Assert.Equal(0, fixture.IsActiveCount); - fixture.Loaded.OnNext(Unit.Default); - Assert.Equal(1, vm.IsActiveCount); - Assert.Equal(1, fixture.IsActiveCount); + fixture.Loaded.OnNext(Unit.Default); + Assert.Equal(1, vm.IsActiveCount); + Assert.Equal(1, fixture.IsActiveCount); - fixture.Unloaded.OnNext(Unit.Default); - Assert.Equal(0, vm.IsActiveCount); - Assert.Equal(0, fixture.IsActiveCount); - } + fixture.Unloaded.OnNext(Unit.Default); + Assert.Equal(0, vm.IsActiveCount); + Assert.Equal(0, fixture.IsActiveCount); } } diff --git a/src/ReactiveUI.DI.Tests/DryIocReactiveUIDependencyTests.cs b/src/ReactiveUI.DI.Tests/DryIocReactiveUIDependencyTests.cs index 27cfe2a9b..c200992ac 100644 --- a/src/ReactiveUI.DI.Tests/DryIocReactiveUIDependencyTests.cs +++ b/src/ReactiveUI.DI.Tests/DryIocReactiveUIDependencyTests.cs @@ -5,44 +5,45 @@ using System.Collections.Generic; using System.Linq; + using DryIoc; + using FluentAssertions; -using Splat; -using Splat.Common.Test; + using Splat.DryIoc; + using Xunit; -namespace ReactiveUI.DI.Tests +namespace ReactiveUI.DI.Tests; + +/// +/// DryIoc ReactiveUI Dependency Tests. +/// +public class DryIocReactiveUIDependencyTests { /// - /// DryIoc ReactiveUI Dependency Tests. + /// DyyIoC dependency resolver should register reactive UI creates command binding. /// - public class DryIocReactiveUIDependencyTests + [Fact] + public void DryIocDependencyResolverShouldRegisterReactiveUI() { - /// - /// DyyIoC dependency resolver should register reactive UI creates command binding. - /// - [Fact] - public void DryIocDependencyResolverShouldRegisterReactiveUI() - { - // Invoke RxApp which initializes the ReactiveUI platform. - var container = new Container(); - - var locator = new DryIocDependencyResolver(container); - locator.RegisterViewsForViewModels(typeof(ViewWithViewContractThatShouldNotLoad).Assembly); - locator.InitializeReactiveUI(); - - var converters = container.Resolve>().ToList(); - - converters.Should().NotBeNull(); - converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent)); - converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter)); - - var convertersb = container.Resolve>().ToList(); - - convertersb.Should().NotBeNull(); - convertersb.Should().Contain(x => x.GetType() == typeof(StringConverter)); - convertersb.Should().Contain(x => x.GetType() == typeof(EqualityTypeConverter)); - } + // Invoke RxApp which initializes the ReactiveUI platform. + var container = new Container(); + + var locator = new DryIocDependencyResolver(container); + locator.RegisterViewsForViewModels(typeof(ViewWithViewContractThatShouldNotLoad).Assembly); + locator.InitializeReactiveUI(); + + var converters = container.Resolve>().ToList(); + + converters.Should().NotBeNull(); + converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent)); + converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter)); + + var convertersb = container.Resolve>().ToList(); + + convertersb.Should().NotBeNull(); + convertersb.Should().Contain(x => x.GetType() == typeof(StringConverter)); + convertersb.Should().Contain(x => x.GetType() == typeof(EqualityTypeConverter)); } } diff --git a/src/ReactiveUI.DI.Tests/Mocks/ActivatingView.cs b/src/ReactiveUI.DI.Tests/Mocks/ActivatingView.cs index ef4a1fab9..0a5dcbe84 100644 --- a/src/ReactiveUI.DI.Tests/Mocks/ActivatingView.cs +++ b/src/ReactiveUI.DI.Tests/Mocks/ActivatingView.cs @@ -8,75 +8,74 @@ using System.Reactive.Disposables; using System.Reactive.Subjects; -namespace ReactiveUI.DI.Tests.Mocks +namespace ReactiveUI.DI.Tests.Mocks; + +/// +/// Activating View. +/// +/// +/// +public sealed class ActivatingView : ReactiveObject, IViewFor, IDisposable { + private int _count; + private ActivatingViewModel? _viewModel; + /// - /// Activating View. + /// Initializes a new instance of the class. /// - /// - /// - public sealed class ActivatingView : ReactiveObject, IViewFor, IDisposable + public ActivatingView() { - private int _count; - private ActivatingViewModel? _viewModel; - - /// - /// Initializes a new instance of the class. - /// - public ActivatingView() + this.WhenActivated(d => { - this.WhenActivated(d => - { - _count++; - d(Disposable.Create(() => _count--)); - }); - } + _count++; + d(Disposable.Create(() => _count--)); + }); + } - /// - /// Gets the count. - /// - /// - /// The count. - /// - public int IsActiveCount => _count; + /// + /// Gets the count. + /// + /// + /// The count. + /// + public int IsActiveCount => _count; - /// - /// Gets the loaded. - /// - public Subject Loaded { get; } = new(); + /// + /// Gets the loaded. + /// + public Subject Loaded { get; } = new(); - /// - /// Gets the unloaded. - /// - public Subject Unloaded { get; } = new(); + /// + /// Gets the unloaded. + /// + public Subject Unloaded { get; } = new(); - /// - /// Gets or sets the view model. - /// - public ActivatingViewModel? ViewModel - { - get => _viewModel; - set => this.RaiseAndSetIfChanged(ref _viewModel, value); - } + /// + /// Gets or sets the view model. + /// + public ActivatingViewModel? ViewModel + { + get => _viewModel; + set => this.RaiseAndSetIfChanged(ref _viewModel, value); + } - /// - /// Gets or sets the view model. - /// - object? IViewFor.ViewModel - { - get => ViewModel; - set => ViewModel = (ActivatingViewModel?)value; - } + /// + /// Gets or sets the view model. + /// + object? IViewFor.ViewModel + { + get => ViewModel; + set => ViewModel = (ActivatingViewModel?)value; + } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Loaded.Dispose(); - Unloaded.Dispose(); - GC.SuppressFinalize(this); - } + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Loaded.Dispose(); + Unloaded.Dispose(); + GC.SuppressFinalize(this); } } diff --git a/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewFetcher.cs b/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewFetcher.cs index dc6dc9c53..71a6954eb 100644 --- a/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewFetcher.cs +++ b/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewFetcher.cs @@ -6,44 +6,43 @@ using System; using System.Reactive.Linq; -namespace ReactiveUI.DI.Tests.Mocks +namespace ReactiveUI.DI.Tests.Mocks; + +/// +/// Simulates a activating view fetcher. +/// +public class ActivatingViewFetcher : IActivationForViewFetcher { /// - /// Simulates a activating view fetcher. + /// Determines the priority that the Activation View Fetcher + /// will be able to process the view type. + /// 0 means it cannot activate the View, value larger than 0 + /// indicates it can activate the View. + /// The class derived off IActivationForViewFetcher which returns + /// the highest affinity value will be used to activate the View. /// - public class ActivatingViewFetcher : IActivationForViewFetcher - { - /// - /// Determines the priority that the Activation View Fetcher - /// will be able to process the view type. - /// 0 means it cannot activate the View, value larger than 0 - /// indicates it can activate the View. - /// The class derived off IActivationForViewFetcher which returns - /// the highest affinity value will be used to activate the View. - /// - /// The type for the View. - /// - /// The affinity value which is equal to 0 or above. - /// - public int GetAffinityForView(Type view) => view == typeof(ActivatingView) ? 100 : 0; + /// The type for the View. + /// + /// The affinity value which is equal to 0 or above. + /// + public int GetAffinityForView(Type view) => view == typeof(ActivatingView) ? 100 : 0; - /// - /// Gets a Observable which will activate the View. - /// This is called after the GetAffinityForView method. - /// - /// The view to get the activation observable for. - /// - /// A Observable which will returns if Activation was successful. - /// - /// The view is null. - public IObservable GetActivationForView(IActivatableView view) + /// + /// Gets a Observable which will activate the View. + /// This is called after the GetAffinityForView method. + /// + /// The view to get the activation observable for. + /// + /// A Observable which will returns if Activation was successful. + /// + /// The view is null. + public IObservable GetActivationForView(IActivatableView view) + { + if (view is not ActivatingView av) { - if (view is not ActivatingView av) - { - throw new ArgumentNullException(nameof(view)); - } - - return av.Loaded.Select(_ => true).Merge(av.Unloaded.Select(_ => false)); + throw new ArgumentNullException(nameof(view)); } + + return av.Loaded.Select(_ => true).Merge(av.Unloaded.Select(_ => false)); } } diff --git a/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewModel.cs b/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewModel.cs index d0a1b1508..9380845a4 100644 --- a/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewModel.cs +++ b/src/ReactiveUI.DI.Tests/Mocks/ActivatingViewModel.cs @@ -5,36 +5,35 @@ using System.Reactive.Disposables; -namespace ReactiveUI.DI.Tests.Mocks +namespace ReactiveUI.DI.Tests.Mocks; + +/// +/// ActivatingViewModel. +/// +/// +public class ActivatingViewModel : ReactiveObject, IActivatableViewModel { /// - /// ActivatingViewModel. + /// Initializes a new instance of the class. /// - /// - public class ActivatingViewModel : ReactiveObject, IActivatableViewModel + public ActivatingViewModel() { - /// - /// Initializes a new instance of the class. - /// - public ActivatingViewModel() - { - Activator = new ViewModelActivator(); + Activator = new ViewModelActivator(); - this.WhenActivated(d => - { - IsActiveCount++; - d(Disposable.Create(() => IsActiveCount--)); - }); - } + this.WhenActivated(d => + { + IsActiveCount++; + d(Disposable.Create(() => IsActiveCount--)); + }); + } - /// - /// Gets or sets the Activator which will be used by the View when Activation/Deactivation occurs. - /// - public ViewModelActivator Activator { get; protected set; } + /// + /// Gets or sets the Activator which will be used by the View when Activation/Deactivation occurs. + /// + public ViewModelActivator Activator { get; protected set; } - /// - /// Gets or sets the active count. - /// - public int IsActiveCount { get; protected set; } - } + /// + /// Gets or sets the active count. + /// + public int IsActiveCount { get; protected set; } } diff --git a/src/ReactiveUI.DI.Tests/SimpleInjectorReactiveUIDependencyTests.cs b/src/ReactiveUI.DI.Tests/SimpleInjectorReactiveUIDependencyTests.cs index 9ac025389..87471c85b 100644 --- a/src/ReactiveUI.DI.Tests/SimpleInjectorReactiveUIDependencyTests.cs +++ b/src/ReactiveUI.DI.Tests/SimpleInjectorReactiveUIDependencyTests.cs @@ -10,48 +10,47 @@ using Splat.SimpleInjector; using Xunit; -namespace ReactiveUI.DI.Tests +namespace ReactiveUI.DI.Tests; + +/// +/// SimpleInjector ReactiveUI Dependency Tests. +/// +public class SimpleInjectorReactiveUIDependencyTests { /// - /// SimpleInjector ReactiveUI Dependency Tests. + /// Should register ReactiveUI binding type converters. /// - public class SimpleInjectorReactiveUIDependencyTests + [Fact] + public void SimpleInjectorDependencyResolverShouldRegisterReactiveUIBindingTypeConverters() { - /// - /// Should register ReactiveUI binding type converters. - /// - [Fact] - public void SimpleInjectorDependencyResolverShouldRegisterReactiveUIBindingTypeConverters() - { - // Invoke RxApp which initializes the ReactiveUI platform. - Container container = new(); - SimpleInjectorInitializer initializer = new(); - - initializer.InitializeReactiveUI(); - var converters = initializer.GetServices().ToList(); - - converters.Should().NotBeNull(); - converters.Should().Contain(x => x.GetType() == typeof(StringConverter)); - converters.Should().Contain(x => x.GetType() == typeof(EqualityTypeConverter)); - } - - /// - /// Should register ReactiveUI creates command bindings. - /// - [Fact] - public void SimpleInjectorDependencyResolverShouldRegisterReactiveUICreatesCommandBinding() - { - // Invoke RxApp which initializes the ReactiveUI platform. - Container container = new(); - SimpleInjectorInitializer initializer = new(); - - initializer.InitializeReactiveUI(); - - var converters = initializer.GetServices().ToList(); - - converters.Should().NotBeNull(); - converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent)); - converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter)); - } + // Invoke RxApp which initializes the ReactiveUI platform. + Container container = new(); + SimpleInjectorInitializer initializer = new(); + + initializer.InitializeReactiveUI(); + var converters = initializer.GetServices().ToList(); + + converters.Should().NotBeNull(); + converters.Should().Contain(x => x.GetType() == typeof(StringConverter)); + converters.Should().Contain(x => x.GetType() == typeof(EqualityTypeConverter)); + } + + /// + /// Should register ReactiveUI creates command bindings. + /// + [Fact] + public void SimpleInjectorDependencyResolverShouldRegisterReactiveUICreatesCommandBinding() + { + // Invoke RxApp which initializes the ReactiveUI platform. + Container container = new(); + SimpleInjectorInitializer initializer = new(); + + initializer.InitializeReactiveUI(); + + var converters = initializer.GetServices().ToList(); + + converters.Should().NotBeNull(); + converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent)); + converters.Should().Contain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter)); } } diff --git a/src/ReactiveUI.DI.Tests/ViewWithViewContractThatShouldNotLoad.cs b/src/ReactiveUI.DI.Tests/ViewWithViewContractThatShouldNotLoad.cs index f4bbfa11b..369c9c94c 100644 --- a/src/ReactiveUI.DI.Tests/ViewWithViewContractThatShouldNotLoad.cs +++ b/src/ReactiveUI.DI.Tests/ViewWithViewContractThatShouldNotLoad.cs @@ -1,32 +1,31 @@ using System; using Splat.Common.Test; -namespace ReactiveUI.DI.Tests +namespace ReactiveUI.DI.Tests; + +/// +/// This is a test view relating to issue #889. +/// It's intended to ensure that view registration by different DI\IoC implementations +/// does not create an instance at the point of registration. +/// +[ViewContract("somecontract")] +public sealed class ViewWithViewContractThatShouldNotLoad : IViewFor { /// - /// This is a test view relating to issue #889. - /// It's intended to ensure that view registration by different DI\IoC implementations - /// does not create an instance at the point of registration. + /// Initializes a new instance of the class. /// - [ViewContract("somecontract")] - public sealed class ViewWithViewContractThatShouldNotLoad : IViewFor + public ViewWithViewContractThatShouldNotLoad() { - /// - /// Initializes a new instance of the class. - /// - public ViewWithViewContractThatShouldNotLoad() - { - throw new InvalidOperationException("This view should not be created."); - } - - /// - object? IViewFor.ViewModel - { - get => ViewModel; - set => ViewModel = (ViewModelOne?)value; - } + throw new InvalidOperationException("This view should not be created."); + } - /// - public ViewModelOne? ViewModel { get; set; } + /// + object? IViewFor.ViewModel + { + get => ViewModel; + set => ViewModel = (ViewModelOne?)value; } + + /// + public ViewModelOne? ViewModel { get; set; } } diff --git a/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs b/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs index a25aba710..ce86f39da 100644 --- a/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs +++ b/src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs @@ -7,80 +7,79 @@ using System.Collections.Generic; using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// Feature Usage Tracking Client for AppCenter. +/// +public sealed class AppCenterFeatureUsageTrackingSession : IFeatureUsageTrackingSession { /// - /// Feature Usage Tracking Client for AppCenter. + /// Initializes a new instance of the class. /// - public sealed class AppCenterFeatureUsageTrackingSession : IFeatureUsageTrackingSession + /// The name of the feature. + public AppCenterFeatureUsageTrackingSession(string featureName) + : this(featureName, Guid.Empty) { - /// - /// Initializes a new instance of the class. - /// - /// The name of the feature. - public AppCenterFeatureUsageTrackingSession(string featureName) - : this(featureName, Guid.Empty) - { - } + } - internal AppCenterFeatureUsageTrackingSession(string featureName, Guid parentReference) - { - FeatureName = featureName; - FeatureReference = Guid.NewGuid(); - ParentReference = parentReference; + internal AppCenterFeatureUsageTrackingSession(string featureName, Guid parentReference) + { + FeatureName = featureName; + FeatureReference = Guid.NewGuid(); + ParentReference = parentReference; - TrackEvent("Feature Usage Start"); - } + TrackEvent("Feature Usage Start"); + } - /// - public string FeatureName { get; } + /// + public string FeatureName { get; } - /// - public Guid FeatureReference { get; } + /// + public Guid FeatureReference { get; } - /// - public Guid ParentReference { get; } + /// + public Guid ParentReference { get; } - /// - public void Dispose() - { - TrackEvent("Feature Usage End"); - } + /// + public void Dispose() + { + TrackEvent("Feature Usage End"); + } - /// - public IFeatureUsageTrackingSession SubFeature(string description) - { - return new AppCenterFeatureUsageTrackingSession(description, FeatureReference); - } + /// + public IFeatureUsageTrackingSession SubFeature(string description) + { + return new AppCenterFeatureUsageTrackingSession(description, FeatureReference); + } - /// - public void OnException(Exception exception) + /// + public void OnException(Exception exception) + { + var properties = GetProperties(); + Microsoft.AppCenter.Crashes.Crashes.TrackError(exception, properties); + } + + private IDictionary GetProperties() + { + var properties = new Dictionary { - var properties = GetProperties(); - Microsoft.AppCenter.Crashes.Crashes.TrackError(exception, properties); - } + { "Name", FeatureName }, + { "Reference", FeatureReference.ToString() }, + }; - private IDictionary GetProperties() + if (ParentReference != Guid.Empty) { - var properties = new Dictionary - { - { "Name", FeatureName }, - { "Reference", FeatureReference.ToString() }, - }; - - if (ParentReference != Guid.Empty) - { - properties.Add("ParentReference", ParentReference.ToString()); - } - - return properties; + properties.Add("ParentReference", ParentReference.ToString()); } - private void TrackEvent(string eventName) - { - var properties = GetProperties(); + return properties; + } - Microsoft.AppCenter.Analytics.Analytics.TrackEvent(eventName, properties); - } + private void TrackEvent(string eventName) + { + var properties = GetProperties(); + + Microsoft.AppCenter.Analytics.Analytics.TrackEvent(eventName, properties); } } diff --git a/src/Splat.AppCenter/AppCenterViewTracking.cs b/src/Splat.AppCenter/AppCenterViewTracking.cs index 3de860f13..c0ac7ace0 100644 --- a/src/Splat.AppCenter/AppCenterViewTracking.cs +++ b/src/Splat.AppCenter/AppCenterViewTracking.cs @@ -3,35 +3,33 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; -using System.Text; + using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// View Tracking integration for AppCenter. +/// +public sealed class AppCenterViewTracking : IViewTracking { /// - /// View Tracking integration for AppCenter. + /// Track a view navigation using just a name. /// - public sealed class AppCenterViewTracking : IViewTracking + /// Name of the view. + public void OnViewNavigation(string name) { - /// - /// Track a view navigation using just a name. - /// - /// Name of the view. - public void OnViewNavigation(string name) - { - var properties = GetProperties(name); + var properties = GetProperties(name); - Microsoft.AppCenter.Analytics.Analytics.TrackEvent("PageView", properties); - } + Microsoft.AppCenter.Analytics.Analytics.TrackEvent("PageView", properties); + } - private static IDictionary GetProperties(string name) + private static IDictionary GetProperties(string name) + { + return new Dictionary { - return new Dictionary - { - { "Name", name }, - }; - } + { "Name", name }, + }; } } diff --git a/src/Splat.AppCenter/Splat.AppCenter.csproj b/src/Splat.AppCenter/Splat.AppCenter.csproj index e25aad38e..29a6cae51 100644 --- a/src/Splat.AppCenter/Splat.AppCenter.csproj +++ b/src/Splat.AppCenter/Splat.AppCenter.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs b/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs index fec265191..1a4a021b9 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs @@ -8,91 +8,90 @@ using Microsoft.ApplicationInsights.DataContracts; using Splat.ApplicationPerformanceMonitoring; -namespace Splat.ApplicationInsights +namespace Splat.ApplicationInsights; + +/// +/// Feature Usage Tracking Client for Application Insights. +/// +public sealed class ApplicationInsightsFeatureUsageTrackingSession : IFeatureUsageTrackingSession { + private readonly TelemetryClient _telemetryClient; + /// - /// Feature Usage Tracking Client for Application Insights. + /// Initializes a new instance of the class. /// - public sealed class ApplicationInsightsFeatureUsageTrackingSession : IFeatureUsageTrackingSession + /// The name of the feature. + /// The Application Insights telemetry client instance to use. + public ApplicationInsightsFeatureUsageTrackingSession( + string featureName, + TelemetryClient telemetryClient) + : this(featureName, Guid.Empty, telemetryClient) { - private readonly TelemetryClient _telemetryClient; - - /// - /// Initializes a new instance of the class. - /// - /// The name of the feature. - /// The Application Insights telemetry client instance to use. - public ApplicationInsightsFeatureUsageTrackingSession( - string featureName, - TelemetryClient telemetryClient) - : this(featureName, Guid.Empty, telemetryClient) - { - } + } - internal ApplicationInsightsFeatureUsageTrackingSession( - string featureName, - Guid parentReference, - TelemetryClient telemetryClient) - { - _telemetryClient = telemetryClient; - FeatureName = featureName; - FeatureReference = Guid.NewGuid(); - ParentReference = parentReference; + internal ApplicationInsightsFeatureUsageTrackingSession( + string featureName, + Guid parentReference, + TelemetryClient telemetryClient) + { + _telemetryClient = telemetryClient; + FeatureName = featureName; + FeatureReference = Guid.NewGuid(); + ParentReference = parentReference; - TrackEvent("Feature Usage Start"); - } + TrackEvent("Feature Usage Start"); + } - /// - public Guid FeatureReference { get; } + /// + public Guid FeatureReference { get; } - /// - public Guid ParentReference { get; } + /// + public Guid ParentReference { get; } - /// - public string FeatureName { get; } + /// + public string FeatureName { get; } - /// - public void Dispose() - { - TrackEvent("Feature Usage End"); - } + /// + public void Dispose() + { + TrackEvent("Feature Usage End"); + } - /// - public IFeatureUsageTrackingSession SubFeature(string description) - { - return new ApplicationInsightsFeatureUsageTrackingSession( - description, - FeatureReference, - _telemetryClient); - } + /// + public IFeatureUsageTrackingSession SubFeature(string description) + { + return new ApplicationInsightsFeatureUsageTrackingSession( + description, + FeatureReference, + _telemetryClient); + } - /// - public void OnException(Exception exception) - { - var telemetry = new ExceptionTelemetry(exception); - PrepareEventData(telemetry); + /// + public void OnException(Exception exception) + { + var telemetry = new ExceptionTelemetry(exception); + PrepareEventData(telemetry); - _telemetryClient.TrackException(telemetry); - } + _telemetryClient.TrackException(telemetry); + } - private void TrackEvent(string eventName) - { - var eventTelemetry = new EventTelemetry(eventName); - PrepareEventData(eventTelemetry); + private void TrackEvent(string eventName) + { + var eventTelemetry = new EventTelemetry(eventName); + PrepareEventData(eventTelemetry); - _telemetryClient.TrackEvent(eventTelemetry); - } + _telemetryClient.TrackEvent(eventTelemetry); + } - private void PrepareEventData(TTelemetry eventTelemetry) - where TTelemetry : ISupportProperties - { - eventTelemetry.Properties.Add("Name", FeatureName); - eventTelemetry.Properties.Add("Reference", FeatureReference.ToString()); + private void PrepareEventData(TTelemetry eventTelemetry) + where TTelemetry : ISupportProperties + { + eventTelemetry.Properties.Add("Name", FeatureName); + eventTelemetry.Properties.Add("Reference", FeatureReference.ToString()); - if (ParentReference != Guid.Empty) - { - eventTelemetry.Properties.Add("ParentReference", ParentReference.ToString()); - } + if (ParentReference != Guid.Empty) + { + eventTelemetry.Properties.Add("ParentReference", ParentReference.ToString()); } } } diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs index 4ccda6bdf..65f3cb16a 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs @@ -7,47 +7,46 @@ using Microsoft.ApplicationInsights.DataContracts; using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// View Tracking integration for Application Insights. +/// +public sealed class ApplicationInsightsViewTracking : IViewTracking { + private readonly TelemetryClient _telemetryClient; + /// - /// View Tracking integration for Application Insights. + /// Initializes a new instance of the class. /// - public sealed class ApplicationInsightsViewTracking : IViewTracking + /// The Application Insights telemetry client instance to use. + public ApplicationInsightsViewTracking(TelemetryClient telemetryClient) { - private readonly TelemetryClient _telemetryClient; - - /// - /// Initializes a new instance of the class. - /// - /// The Application Insights telemetry client instance to use. - public ApplicationInsightsViewTracking(TelemetryClient telemetryClient) - { - _telemetryClient = telemetryClient; - } + _telemetryClient = telemetryClient; + } - /// - /// Track a view navigation using just a name. - /// - /// Name of the view. - public void OnViewNavigation(string name) - { - _telemetryClient.TrackPageView(name); - } + /// + /// Track a view navigation using just a name. + /// + /// Name of the view. + public void OnViewNavigation(string name) + { + _telemetryClient.TrackPageView(name); + } - /// - /// Track a View Navigation with Extended Data. - /// - /// Telemetry data. - public void OnViewNavigation(PageViewTelemetry telemetry) - { - var pageViewTelemetry = GetPageViewTelemetry(); - _telemetryClient.TrackPageView(telemetry); - } + /// + /// Track a View Navigation with Extended Data. + /// + /// Telemetry data. + public void OnViewNavigation(PageViewTelemetry telemetry) + { + var pageViewTelemetry = GetPageViewTelemetry(); + _telemetryClient.TrackPageView(telemetry); + } - internal static PageViewTelemetry GetPageViewTelemetry() - { - var result = new PageViewTelemetry(); - return result; - } + internal static PageViewTelemetry GetPageViewTelemetry() + { + var result = new PageViewTelemetry(); + return result; } } diff --git a/src/Splat.Autofac.Tests/DependencyResolverTests.cs b/src/Splat.Autofac.Tests/DependencyResolverTests.cs index 99a88784c..646c17f9d 100644 --- a/src/Splat.Autofac.Tests/DependencyResolverTests.cs +++ b/src/Splat.Autofac.Tests/DependencyResolverTests.cs @@ -13,271 +13,270 @@ using Splat.Tests.ServiceLocation; using Xunit; -namespace Splat.Autofac.Tests +namespace Splat.Autofac.Tests; + +/// +/// Tests to show the works correctly. +/// +public class DependencyResolverTests : BaseDependencyResolverTests { /// - /// Tests to show the works correctly. + /// Shoulds the resolve nulls. + /// + [Fact] + public void Can_Register_And_Resolve_Null_Types() + { + var builder = new ContainerBuilder(); + var autofacResolver = builder.UseAutofacDependencyResolver(); + + var foo = 5; + Locator.CurrentMutable.Register(() => foo, null); + + var bar = 4; + var contract = "foo"; + Locator.CurrentMutable.Register(() => bar, null, contract); + autofacResolver.SetLifetimeScope(builder.Build()); + + Assert.True(Locator.CurrentMutable.HasRegistration(null)); + var value = Locator.Current.GetService(null); + Assert.Equal(foo, value); + + Assert.True(Locator.CurrentMutable.HasRegistration(null, contract)); + value = Locator.Current.GetService(null, contract); + Assert.Equal(bar, value); + + var values = Locator.Current.GetServices(null); + Assert.Equal(foo, (int)values.First()); + Assert.Equal(1, values.Count()); + + Assert.Throws(() => Locator.CurrentMutable.UnregisterCurrent(null)); + var valuesNC = Locator.Current.GetServices(null); + Assert.Equal(1, valuesNC.Count()); + Assert.Equal(foo, (int)valuesNC.First()); + var valuesC = Locator.Current.GetServices(null, contract); + Assert.Equal(1, valuesC.Count()); + Assert.Equal(bar, (int)valuesC.First()); + } + + /// + /// Shoulds the resolve views. + /// + [Fact] + public void AutofacDependencyResolver_Should_Resolve_Views() + { + var builder = new ContainerBuilder(); + builder.RegisterType().As>(); + builder.RegisterType().As>(); + + var autofacResolver = builder.UseAutofacDependencyResolver(); + autofacResolver.SetLifetimeScope(builder.Build()); + + var viewOne = Locator.Current.GetService(typeof(IViewFor)); + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewOne.Should().NotBeNull(); + viewOne.Should().BeOfType(); + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Shoulds the resolve views. + /// + [Fact] + public void AutofacDependencyResolver_Should_Resolve_Named_View() + { + var builder = new ContainerBuilder(); + builder.RegisterType().Named>("Other"); + + var autofacResolver = builder.UseAutofacDependencyResolver(); + autofacResolver.SetLifetimeScope(builder.Build()); + + var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other"); + + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Shoulds the resolve view models. + /// + [Fact] + public void AutofacDependencyResolver_Should_Resolve_View_Models() + { + var builder = new ContainerBuilder(); + builder.RegisterType().AsSelf(); + builder.RegisterType().AsSelf(); + + var autofacResolver = builder.UseAutofacDependencyResolver(); + autofacResolver.SetLifetimeScope(builder.Build()); + + var vmOne = Locator.Current.GetService(); + var vmTwo = Locator.Current.GetService(); + + vmOne.Should().NotBeNull(); + vmTwo.Should().NotBeNull(); + } + + /// + /// Shoulds the resolve screen. + /// + [Fact] + public void AutofacDependencyResolver_Should_Resolve_Screen() + { + var builder = new ContainerBuilder(); + builder.RegisterType().As().SingleInstance(); + + var autofacResolver = builder.UseAutofacDependencyResolver(); + autofacResolver.SetLifetimeScope(builder.Build()); + + var screen = Locator.Current.GetService(); + + screen.Should().NotBeNull(); + screen.Should().BeOfType(); + } + + /// + /// Should throw an exception if service registration call back called. + /// + [Fact] + public void AutofacDependencyResolver_Should_Throw_If_ServiceRegistrationCallback_Called() + { + var builder = new ContainerBuilder(); + + var autofacResolver = builder.UseAutofacDependencyResolver(); + autofacResolver.SetLifetimeScope(builder.Build()); + + var result = Record.Exception(() => + Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); + + result.Should().BeOfType(); + } + + /// + /// Check to ensure the correct logger is returned. /// - public class DependencyResolverTests : BaseDependencyResolverTests + /// + /// Introduced for Splat #331. + /// + [Fact] + public void AutofacDependencyResolver_Should_ReturnRegisteredLogger() + { + var builder = new ContainerBuilder(); + + var autofacResolver = builder.UseAutofacDependencyResolver(); + + Locator.CurrentMutable.RegisterConstant( + new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), + typeof(ILogManager)); + + autofacResolver.SetLifetimeScope(builder.Build()); + + var logManager = Locator.Current.GetService(); + Assert.IsType(logManager); + } + + /// + /// Test that a pre-init logger isn't overriden. + /// + /// + /// Introduced for Splat #331. + /// + [Fact] + public void AutofacDependencyResolver_PreInit_Should_ReturnRegisteredLogger() + { + var builder = new ContainerBuilder(); + + var autofacResolver = builder.UseAutofacDependencyResolver(); + + builder.Register(_ => new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))).As(typeof(ILogManager)) + .AsImplementedInterfaces(); + + autofacResolver.SetLifetimeScope(builder.Build()); + + var logManager = Locator.Current.GetService(); + Assert.IsType(logManager); + } + + /// + /// + /// + [Fact] + public override void UnregisterCurrent_Doesnt_Throw_When_List_Empty() + { + } + + /// + /// + /// + [Fact] + public override void UnregisterCurrent_Remove_Last() + { + } + + /// + /// + /// + [Fact] + public override void UnregisterCurrentByName_Doesnt_Throw_When_List_Empty() + { + } + + /// + /// + /// + [Fact] + public override void UnregisterAll_UnregisterCurrent_Doesnt_Throw_When_List_Empty() + { + } + + /// + /// + /// + [Fact] + public override void UnregisterAllByContract_UnregisterCurrent_Doesnt_Throw_When_List_Empty() + { + } + + /// + /// + /// + /// + [Fact] + public override void HasRegistration() { - /// - /// Shoulds the resolve nulls. - /// - [Fact] - public void Can_Register_And_Resolve_Null_Types() - { - var builder = new ContainerBuilder(); - var autofacResolver = builder.UseAutofacDependencyResolver(); - - var foo = 5; - Locator.CurrentMutable.Register(() => foo, null); - - var bar = 4; - var contract = "foo"; - Locator.CurrentMutable.Register(() => bar, null, contract); - autofacResolver.SetLifetimeScope(builder.Build()); - - Assert.True(Locator.CurrentMutable.HasRegistration(null)); - var value = Locator.Current.GetService(null); - Assert.Equal(foo, value); - - Assert.True(Locator.CurrentMutable.HasRegistration(null, contract)); - value = Locator.Current.GetService(null, contract); - Assert.Equal(bar, value); - - var values = Locator.Current.GetServices(null); - Assert.Equal(foo, (int)values.First()); - Assert.Equal(1, values.Count()); - - Assert.Throws(() => Locator.CurrentMutable.UnregisterCurrent(null)); - var valuesNC = Locator.Current.GetServices(null); - Assert.Equal(1, valuesNC.Count()); - Assert.Equal(foo, (int)valuesNC.First()); - var valuesC = Locator.Current.GetServices(null, contract); - Assert.Equal(1, valuesC.Count()); - Assert.Equal(bar, (int)valuesC.First()); - } - - /// - /// Shoulds the resolve views. - /// - [Fact] - public void AutofacDependencyResolver_Should_Resolve_Views() - { - var builder = new ContainerBuilder(); - builder.RegisterType().As>(); - builder.RegisterType().As>(); - - var autofacResolver = builder.UseAutofacDependencyResolver(); - autofacResolver.SetLifetimeScope(builder.Build()); - - var viewOne = Locator.Current.GetService(typeof(IViewFor)); - var viewTwo = Locator.Current.GetService(typeof(IViewFor)); - - viewOne.Should().NotBeNull(); - viewOne.Should().BeOfType(); - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Shoulds the resolve views. - /// - [Fact] - public void AutofacDependencyResolver_Should_Resolve_Named_View() - { - var builder = new ContainerBuilder(); - builder.RegisterType().Named>("Other"); - - var autofacResolver = builder.UseAutofacDependencyResolver(); - autofacResolver.SetLifetimeScope(builder.Build()); - - var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other"); - - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Shoulds the resolve view models. - /// - [Fact] - public void AutofacDependencyResolver_Should_Resolve_View_Models() - { - var builder = new ContainerBuilder(); - builder.RegisterType().AsSelf(); - builder.RegisterType().AsSelf(); - - var autofacResolver = builder.UseAutofacDependencyResolver(); - autofacResolver.SetLifetimeScope(builder.Build()); - - var vmOne = Locator.Current.GetService(); - var vmTwo = Locator.Current.GetService(); - - vmOne.Should().NotBeNull(); - vmTwo.Should().NotBeNull(); - } - - /// - /// Shoulds the resolve screen. - /// - [Fact] - public void AutofacDependencyResolver_Should_Resolve_Screen() - { - var builder = new ContainerBuilder(); - builder.RegisterType().As().SingleInstance(); - - var autofacResolver = builder.UseAutofacDependencyResolver(); - autofacResolver.SetLifetimeScope(builder.Build()); - - var screen = Locator.Current.GetService(); - - screen.Should().NotBeNull(); - screen.Should().BeOfType(); - } - - /// - /// Should throw an exception if service registration call back called. - /// - [Fact] - public void AutofacDependencyResolver_Should_Throw_If_ServiceRegistrationCallback_Called() - { - var builder = new ContainerBuilder(); - - var autofacResolver = builder.UseAutofacDependencyResolver(); - autofacResolver.SetLifetimeScope(builder.Build()); - - var result = Record.Exception(() => - Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); - - result.Should().BeOfType(); - } - - /// - /// Check to ensure the correct logger is returned. - /// - /// - /// Introduced for Splat #331. - /// - [Fact] - public void AutofacDependencyResolver_Should_ReturnRegisteredLogger() - { - var builder = new ContainerBuilder(); - - var autofacResolver = builder.UseAutofacDependencyResolver(); - - Locator.CurrentMutable.RegisterConstant( - new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), - typeof(ILogManager)); - - autofacResolver.SetLifetimeScope(builder.Build()); - - var logManager = Locator.Current.GetService(); - Assert.IsType(logManager); - } - - /// - /// Test that a pre-init logger isn't overriden. - /// - /// - /// Introduced for Splat #331. - /// - [Fact] - public void AutofacDependencyResolver_PreInit_Should_ReturnRegisteredLogger() - { - var builder = new ContainerBuilder(); - - var autofacResolver = builder.UseAutofacDependencyResolver(); - - builder.Register(_ => new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))).As(typeof(ILogManager)) - .AsImplementedInterfaces(); - - autofacResolver.SetLifetimeScope(builder.Build()); - - var logManager = Locator.Current.GetService(); - Assert.IsType(logManager); - } - - /// - /// - /// - [Fact] - public override void UnregisterCurrent_Doesnt_Throw_When_List_Empty() - { - } - - /// - /// - /// - [Fact] - public override void UnregisterCurrent_Remove_Last() - { - } - - /// - /// - /// - [Fact] - public override void UnregisterCurrentByName_Doesnt_Throw_When_List_Empty() - { - } - - /// - /// - /// - [Fact] - public override void UnregisterAll_UnregisterCurrent_Doesnt_Throw_When_List_Empty() - { - } - - /// - /// - /// - [Fact] - public override void UnregisterAllByContract_UnregisterCurrent_Doesnt_Throw_When_List_Empty() - { - } - - /// - /// - /// - /// - [Fact] - public override void HasRegistration() - { #pragma warning disable CS0618 // Type or member is obsolete - var type = typeof(string); - const string contractOne = "ContractOne"; - const string contractTwo = "ContractTwo"; - var resolver = GetDependencyResolver(); - - Assert.False(resolver.HasRegistration(type)); - Assert.False(resolver.HasRegistration(type, contractOne)); - Assert.False(resolver.HasRegistration(type, contractTwo)); - - resolver.Register(() => "unnamed", type); - Assert.True(resolver.HasRegistration(type)); - Assert.False(resolver.HasRegistration(type, contractOne)); - Assert.False(resolver.HasRegistration(type, contractTwo)); - - resolver.Register(() => contractOne, type, contractOne); - Assert.True(resolver.HasRegistration(type)); - Assert.True(resolver.HasRegistration(type, contractOne)); - Assert.False(resolver.HasRegistration(type, contractTwo)); - - resolver.Register(() => contractTwo, type, contractTwo); - Assert.True(resolver.HasRegistration(type)); - Assert.True(resolver.HasRegistration(type, contractOne)); - Assert.True(resolver.HasRegistration(type, contractTwo)); + var type = typeof(string); + const string contractOne = "ContractOne"; + const string contractTwo = "ContractTwo"; + var resolver = GetDependencyResolver(); + + Assert.False(resolver.HasRegistration(type)); + Assert.False(resolver.HasRegistration(type, contractOne)); + Assert.False(resolver.HasRegistration(type, contractTwo)); + + resolver.Register(() => "unnamed", type); + Assert.True(resolver.HasRegistration(type)); + Assert.False(resolver.HasRegistration(type, contractOne)); + Assert.False(resolver.HasRegistration(type, contractTwo)); + + resolver.Register(() => contractOne, type, contractOne); + Assert.True(resolver.HasRegistration(type)); + Assert.True(resolver.HasRegistration(type, contractOne)); + Assert.False(resolver.HasRegistration(type, contractTwo)); + + resolver.Register(() => contractTwo, type, contractTwo); + Assert.True(resolver.HasRegistration(type)); + Assert.True(resolver.HasRegistration(type, contractOne)); + Assert.True(resolver.HasRegistration(type, contractTwo)); #pragma warning restore CS0618 // Type or member is obsolete - } + } - /// - protected override AutofacDependencyResolver GetDependencyResolver() - { - var builder = new ContainerBuilder(); + /// + protected override AutofacDependencyResolver GetDependencyResolver() + { + var builder = new ContainerBuilder(); - return builder.UseAutofacDependencyResolver(); - } + return builder.UseAutofacDependencyResolver(); } } diff --git a/src/Splat.Autofac/AutofacDependencyResolver.cs b/src/Splat.Autofac/AutofacDependencyResolver.cs index d94434d26..665b2830a 100644 --- a/src/Splat.Autofac/AutofacDependencyResolver.cs +++ b/src/Splat.Autofac/AutofacDependencyResolver.cs @@ -7,280 +7,279 @@ using System.Collections; using System.Collections.Generic; using System.Linq; + using Autofac; -using Autofac.Core; -namespace Splat.Autofac +namespace Splat.Autofac; + +/// +/// Autofac implementation for . +/// +public class AutofacDependencyResolver : IDependencyResolver { + private readonly object _lockObject = new(); + private readonly ContainerBuilder _builder; + /// - /// Autofac implementation for . + /// The internal container, which takes care of mutability needed for ReactiveUI initialization procedure. + /// It is disposed of once the user sets the actual lifetime scope from which to resolve by calling SetLifetimeScope. /// - public class AutofacDependencyResolver : IDependencyResolver - { - private readonly object _lockObject = new(); - private readonly ContainerBuilder _builder; + private IContainer _internalContainer; - /// - /// The internal container, which takes care of mutability needed for ReactiveUI initialization procedure. - /// It is disposed of once the user sets the actual lifetime scope from which to resolve by calling SetLifetimeScope. - /// - private IContainer _internalContainer; - - private ILifetimeScope? _lifetimeScope; + private ILifetimeScope? _lifetimeScope; #pragma warning disable CA2213 // _internalLifetimeScope will be disposed, because it is a child of _internalContainer - private ILifetimeScope _internalLifetimeScope; + private ILifetimeScope _internalLifetimeScope; #pragma warning restore CA2213 // Disposable fields should be disposed - /// - /// Set to true, when SetLifetimeScope has been called. - /// Prevents mutating the ContainerBuilder or setting the lifetime again. - /// - private bool _lifetimeScopeSet; - - /// - /// Initializes a new instance of the class. - /// - /// Autofac container builder. - public AutofacDependencyResolver(ContainerBuilder builder) + /// + /// Set to true, when SetLifetimeScope has been called. + /// Prevents mutating the ContainerBuilder or setting the lifetime again. + /// + private bool _lifetimeScopeSet; + + /// + /// Initializes a new instance of the class. + /// + /// Autofac container builder. + public AutofacDependencyResolver(ContainerBuilder builder) + { + _builder = builder; + + _internalContainer = new ContainerBuilder().Build(); + _internalLifetimeScope = _internalContainer.BeginLifetimeScope(); + } + + /// + public virtual object? GetService(Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; + if (serviceType is null) { - _builder = builder; + serviceType = typeof(NullServiceType); + } - _internalContainer = new ContainerBuilder().Build(); - _internalLifetimeScope = _internalContainer.BeginLifetimeScope(); + lock (_lockObject) + { + var result = Resolve(serviceType, contract); + return isNull ? (result as NullServiceType)?.Factory() : result; } + } - /// - public virtual object? GetService(Type? serviceType, string? contract = null) + /// + /// Sets the lifetime scope which will be used to resolve ReactiveUI services. + /// It should be set after Autofac application-wide container is built. + /// + /// Lifetime scope, which will be used to resolve ReactiveUI services. + public void SetLifetimeScope(ILifetimeScope lifetimeScope) + { + lock (_lockObject) { - var isNull = serviceType is null; - if (serviceType is null) + if (_lifetimeScopeSet) { - serviceType = typeof(NullServiceType); + throw new InvalidOperationException("Lifetime scope of the Autofac resolver has already been set"); } - lock (_lockObject) - { - var result = Resolve(serviceType, contract); - return isNull ? (result as NullServiceType)?.Factory() : result; - } + _lifetimeScopeSet = true; + _lifetimeScope = lifetimeScope; + + // We dispose on the internal container, since it and its many child lifetime scopes are not needed anymore. + _internalContainer.Dispose(); + _internalContainer = new ContainerBuilder().Build(); + _internalLifetimeScope = _internalContainer.BeginLifetimeScope(); } + } - /// - /// Sets the lifetime scope which will be used to resolve ReactiveUI services. - /// It should be set after Autofac application-wide container is built. - /// - /// Lifetime scope, which will be used to resolve ReactiveUI services. - public void SetLifetimeScope(ILifetimeScope lifetimeScope) + /// + public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; + if (serviceType is null) { - lock (_lockObject) - { - if (_lifetimeScopeSet) - { - throw new InvalidOperationException("Lifetime scope of the Autofac resolver has already been set"); - } - - _lifetimeScopeSet = true; - _lifetimeScope = lifetimeScope; - - // We dispose on the internal container, since it and its many child lifetime scopes are not needed anymore. - _internalContainer.Dispose(); - _internalContainer = new ContainerBuilder().Build(); - _internalLifetimeScope = _internalContainer.BeginLifetimeScope(); - } + serviceType = typeof(NullServiceType); } - /// - public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + lock (_lockObject) { - var isNull = serviceType is null; - if (serviceType is null) + try { - serviceType = typeof(NullServiceType); - } + var enumerableType = typeof(IEnumerable<>).MakeGenericType(serviceType); + var instance = Resolve(enumerableType, contract); - lock (_lockObject) - { - try + if (isNull && instance is IEnumerable nullService) { - var enumerableType = typeof(IEnumerable<>).MakeGenericType(serviceType); - var instance = Resolve(enumerableType, contract); - - if (isNull && instance is IEnumerable nullService) - { - return nullService.Select(item => item.Factory()!); - } - else if (!isNull && instance is not null) - { - return ((IEnumerable)instance).Cast(); - } + return nullService.Select(item => item.Factory()!); } - finally + else if (!isNull && instance is not null) { - // no op + return ((IEnumerable)instance).Cast(); } - - return Array.Empty(); } + finally + { + // no op + } + + return Array.Empty(); } + } - /// - public bool HasRegistration(Type? serviceType, string? contract = null) + /// + public bool HasRegistration(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + serviceType = typeof(NullServiceType); + } - lock (_lockObject) - { - var lifeTimeScope = _lifetimeScope ?? _internalLifetimeScope; + lock (_lockObject) + { + var lifeTimeScope = _lifetimeScope ?? _internalLifetimeScope; - return contract is null || string.IsNullOrWhiteSpace(contract) ? - lifeTimeScope.IsRegistered(serviceType) : - lifeTimeScope.IsRegisteredWithName(contract, serviceType); - } + return contract is null || string.IsNullOrWhiteSpace(contract) ? + lifeTimeScope.IsRegistered(serviceType) : + lifeTimeScope.IsRegisteredWithName(contract, serviceType); + } + } + + /// + /// Important: Because Autofac 5+ containers are immutable, + /// this method should not be used by the end-user. + /// It is still needed to satisfy ReactiveUI initialization procedure. + /// Register a function with the resolver which will generate a object + /// for the specified service type. + /// Optionally a contract can be registered which will indicate + /// that registration will only work with that contract. + /// Most implementations will use a stack based approach to allow for multiple items to be registered. + /// + /// The factory function which generates our object. + /// The type which is used for the registration. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")] + public virtual void Register(Func factory, Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; + if (serviceType is null) + { + serviceType = typeof(NullServiceType); } - /// - /// Important: Because Autofac 5+ containers are immutable, - /// this method should not be used by the end-user. - /// It is still needed to satisfy ReactiveUI initialization procedure. - /// Register a function with the resolver which will generate a object - /// for the specified service type. - /// Optionally a contract can be registered which will indicate - /// that registration will only work with that contract. - /// Most implementations will use a stack based approach to allow for multiple items to be registered. - /// - /// The factory function which generates our object. - /// The type which is used for the registration. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")] - public virtual void Register(Func factory, Type? serviceType, string? contract = null) + lock (_lockObject) { - var isNull = serviceType is null; - if (serviceType is null) + if (_lifetimeScopeSet) { - serviceType = typeof(NullServiceType); + throw new InvalidOperationException("Container has already been built and the lifetime scope set, so it is not possible to modify it anymore."); } - lock (_lockObject) + // We register every ReactiveUI service twice. + // First to the application-wide container, which we are still building. + // Second to child lifetimes in a temporary container, that is used only to satisfy ReactiveUI dependencies. + if (contract is null || string.IsNullOrWhiteSpace(contract)) { - if (_lifetimeScopeSet) - { - throw new InvalidOperationException("Container has already been built and the lifetime scope set, so it is not possible to modify it anymore."); - } - - // We register every ReactiveUI service twice. - // First to the application-wide container, which we are still building. - // Second to child lifetimes in a temporary container, that is used only to satisfy ReactiveUI dependencies. - if (contract is null || string.IsNullOrWhiteSpace(contract)) - { - _builder.Register(_ => + _builder.Register(_ => + isNull + ? new NullServiceType(factory) + : factory()!) + .As(serviceType) + .AsImplementedInterfaces(); + _internalLifetimeScope = _internalLifetimeScope.BeginLifetimeScope(internalBuilder => + internalBuilder.Register(_ => isNull ? new NullServiceType(factory) : factory()!) .As(serviceType) - .AsImplementedInterfaces(); - _internalLifetimeScope = _internalLifetimeScope.BeginLifetimeScope(internalBuilder => - internalBuilder.Register(_ => - isNull - ? new NullServiceType(factory) - : factory()!) - .As(serviceType) - .AsImplementedInterfaces()); - } - else - { - _builder.Register(_ => + .AsImplementedInterfaces()); + } + else + { + _builder.Register(_ => + isNull + ? new NullServiceType(factory) + : factory()!) + .Named(contract, serviceType) + .AsImplementedInterfaces(); + _internalLifetimeScope = _internalLifetimeScope.BeginLifetimeScope(internalBuilder => + internalBuilder.Register(_ => isNull ? new NullServiceType(factory) : factory()!) .Named(contract, serviceType) - .AsImplementedInterfaces(); - _internalLifetimeScope = _internalLifetimeScope.BeginLifetimeScope(internalBuilder => - internalBuilder.Register(_ => - isNull - ? new NullServiceType(factory) - : factory()!) - .Named(contract, serviceType) - .AsImplementedInterfaces()); - } + .AsImplementedInterfaces()); } } + } - /// - /// Because Autofac 5+ containers are immutable, - /// UnregisterCurrent method is not available anymore. - /// Instead, simply register your service after InitializeReactiveUI to override it. - /// - /// The service type to unregister. - /// The optional contract value, which will only remove the value associated with the contract. - /// This is not implemented by default. - /// - [Obsolete("Because Autofac 5+ containers are immutable, UnregisterCurrent method is not available anymore. " + - "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations.")] - public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) => - throw new NotImplementedException("Because Autofac 5+ containers are immutable, UnregisterCurrent method is not available anymore. " + - "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations."); - - /// - /// Because Autofac 5+ containers are immutable, - /// UnregisterAll method is not available anymore. - /// Instead, simply register your service after InitializeReactiveUI to override it. - /// - /// The service type to unregister. - /// The optional contract value, which will only remove the value associated with the contract. - /// This is not implemented by default. - /// - [Obsolete("Because Autofac 5+ containers are immutable, UnregisterAll method is not available anymore. " + - "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations.")] - public virtual void UnregisterAll(Type? serviceType, string? contract = null) => - throw new NotImplementedException("Because Autofac 5+ containers are immutable, UnregisterAll method is not available anymore. " + - "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations."); - - /// - public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) => - throw new NotImplementedException(); - - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + /// + /// Because Autofac 5+ containers are immutable, + /// UnregisterCurrent method is not available anymore. + /// Instead, simply register your service after InitializeReactiveUI to override it. + /// + /// The service type to unregister. + /// The optional contract value, which will only remove the value associated with the contract. + /// This is not implemented by default. + /// + [Obsolete("Because Autofac 5+ containers are immutable, UnregisterCurrent method is not available anymore. " + + "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations.")] + public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) => + throw new NotImplementedException("Because Autofac 5+ containers are immutable, UnregisterCurrent method is not available anymore. " + + "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations."); + + /// + /// Because Autofac 5+ containers are immutable, + /// UnregisterAll method is not available anymore. + /// Instead, simply register your service after InitializeReactiveUI to override it. + /// + /// The service type to unregister. + /// The optional contract value, which will only remove the value associated with the contract. + /// This is not implemented by default. + /// + [Obsolete("Because Autofac 5+ containers are immutable, UnregisterAll method is not available anymore. " + + "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations.")] + public virtual void UnregisterAll(Type? serviceType, string? contract = null) => + throw new NotImplementedException("Because Autofac 5+ containers are immutable, UnregisterAll method is not available anymore. " + + "Instead, simply register your service after InitializeReactiveUI to override it https://autofaccn.readthedocs.io/en/latest/register/registration.html#default-registrations."); + + /// + public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) => + throw new NotImplementedException(); - /// - /// Disposes of the instance. - /// - /// Whether or not the instance is disposing. - protected virtual void Dispose(bool disposing) + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Disposes of the instance. + /// + /// Whether or not the instance is disposing. + protected virtual void Dispose(bool disposing) + { + lock (_lockObject) { - lock (_lockObject) + if (disposing) { - if (disposing) - { - _lifetimeScope?.ComponentRegistry.Dispose(); - _internalContainer?.Dispose(); - } + _lifetimeScope?.ComponentRegistry.Dispose(); + _internalContainer?.Dispose(); } } + } - private object? Resolve(Type serviceType, string? contract) - { - object serviceInstance; - - var lifeTimeScope = _lifetimeScope ?? _internalLifetimeScope; + private object? Resolve(Type serviceType, string? contract) + { + object serviceInstance; - if (contract is null || string.IsNullOrWhiteSpace(contract)) - { - lifeTimeScope.TryResolve(serviceType, out serviceInstance!); - } - else - { - lifeTimeScope.TryResolveNamed(contract, serviceType, out serviceInstance!); - } + var lifeTimeScope = _lifetimeScope ?? _internalLifetimeScope; - return serviceInstance; + if (contract is null || string.IsNullOrWhiteSpace(contract)) + { + lifeTimeScope.TryResolve(serviceType, out serviceInstance!); } + else + { + lifeTimeScope.TryResolveNamed(contract, serviceType, out serviceInstance!); + } + + return serviceInstance; } } diff --git a/src/Splat.Autofac/SplatAutofacExtensions.cs b/src/Splat.Autofac/SplatAutofacExtensions.cs index 200afbc5a..6211e249f 100644 --- a/src/Splat.Autofac/SplatAutofacExtensions.cs +++ b/src/Splat.Autofac/SplatAutofacExtensions.cs @@ -3,26 +3,24 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using Autofac; -namespace Splat.Autofac +namespace Splat.Autofac; + +/// +/// Extension methods for the Autofac adapter. +/// +public static class SplatAutofacExtensions { /// - /// Extension methods for the Autofac adapter. + /// Initializes an instance of that overrides the default . /// - public static class SplatAutofacExtensions + /// Autofac container builder. + /// The Autofac dependency resolver. + public static AutofacDependencyResolver UseAutofacDependencyResolver(this ContainerBuilder builder) { - /// - /// Initializes an instance of that overrides the default . - /// - /// Autofac container builder. - /// The Autofac dependency resolver. - public static AutofacDependencyResolver UseAutofacDependencyResolver(this ContainerBuilder builder) - { - var autofacResolver = new AutofacDependencyResolver(builder); - Locator.SetLocator(autofacResolver); - return autofacResolver; - } + var autofacResolver = new AutofacDependencyResolver(builder); + Locator.SetLocator(autofacResolver); + return autofacResolver; } } diff --git a/src/Splat.Common.Test/DummyObjectClass1.cs b/src/Splat.Common.Test/DummyObjectClass1.cs index 65151b4c4..50a3ad55d 100644 --- a/src/Splat.Common.Test/DummyObjectClass1.cs +++ b/src/Splat.Common.Test/DummyObjectClass1.cs @@ -5,13 +5,12 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Tests.Mocks +namespace Splat.Tests.Mocks; + +/// +/// A dummy class used during Locator testing. +/// +[ExcludeFromCodeCoverage] +public class DummyObjectClass1 : IDummyInterface { - /// - /// A dummy class used during Locator testing. - /// - [ExcludeFromCodeCoverage] - public class DummyObjectClass1 : IDummyInterface - { - } } diff --git a/src/Splat.Common.Test/DummyObjectClass2.cs b/src/Splat.Common.Test/DummyObjectClass2.cs index 199c574ad..5802c76fa 100644 --- a/src/Splat.Common.Test/DummyObjectClass2.cs +++ b/src/Splat.Common.Test/DummyObjectClass2.cs @@ -5,13 +5,12 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Tests.Mocks +namespace Splat.Tests.Mocks; + +/// +/// A dummy class used during Locator testing. +/// +[ExcludeFromCodeCoverage] +public class DummyObjectClass2 : IDummyInterface { - /// - /// A dummy class used during Locator testing. - /// - [ExcludeFromCodeCoverage] - public class DummyObjectClass2 : IDummyInterface - { - } } diff --git a/src/Splat.Common.Test/DummyObjectClass3.cs b/src/Splat.Common.Test/DummyObjectClass3.cs index 4cd476c71..871cbe7f9 100644 --- a/src/Splat.Common.Test/DummyObjectClass3.cs +++ b/src/Splat.Common.Test/DummyObjectClass3.cs @@ -5,13 +5,12 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Tests.Mocks +namespace Splat.Tests.Mocks; + +/// +/// A dummy class used during Locator testing. +/// +[ExcludeFromCodeCoverage] +public class DummyObjectClass3 : IDummyInterface { - /// - /// A dummy class used during Locator testing. - /// - [ExcludeFromCodeCoverage] - public class DummyObjectClass3 : IDummyInterface - { - } } diff --git a/src/Splat.Common.Test/IDummyInterface.cs b/src/Splat.Common.Test/IDummyInterface.cs index 9a61fbe84..e7bcb2d9f 100644 --- a/src/Splat.Common.Test/IDummyInterface.cs +++ b/src/Splat.Common.Test/IDummyInterface.cs @@ -3,14 +3,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.Tests.Mocks +namespace Splat.Tests.Mocks; + +/// +/// A dummy interface used during Locator testing. +/// +public interface IDummyInterface { - /// - /// A dummy interface used during Locator testing. - /// -#pragma warning disable CA1040 // Avoid empty interfaces - public interface IDummyInterface -#pragma warning restore CA1040 // Avoid empty interfaces - { - } } diff --git a/src/Splat.Common.Test/IScreen.cs b/src/Splat.Common.Test/IScreen.cs index 29d49701b..b0522f0f7 100644 --- a/src/Splat.Common.Test/IScreen.cs +++ b/src/Splat.Common.Test/IScreen.cs @@ -3,13 +3,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.Common.Test +namespace Splat.Common.Test; + +/// +/// Represents a screen. +/// +public interface IScreen { - /// - /// Represents a screen. - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1040:Avoid empty interfaces", Justification = "For mocks only.")] - public interface IScreen - { - } } diff --git a/src/Splat.Common.Test/IViewFor.cs b/src/Splat.Common.Test/IViewFor.cs index 2bb25ef3d..f3c8b6b07 100644 --- a/src/Splat.Common.Test/IViewFor.cs +++ b/src/Splat.Common.Test/IViewFor.cs @@ -3,35 +3,35 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.Common.Test -{ +namespace Splat.Common.Test; + #pragma warning disable SA1402 // File may only contain a single type +/// +/// Represents a view bound to a view model. +/// +/// The view model type. +/// +public interface IViewFor : IViewFor + where T : class +{ /// - /// Represents a view bound to a view model. + /// Gets or sets the view model. /// - /// The view model type. - /// - public interface IViewFor : IViewFor - where T : class - { - /// - /// Gets or sets the view model. - /// - new T? ViewModel { get; set; } - } + new T? ViewModel { get; set; } +} +/// +/// Represents a view bound to a view model. +/// +/// +public interface IViewFor +{ /// - /// Represents a view bound to a view model. + /// Gets or sets the view model. /// - /// - public interface IViewFor - { - /// - /// Gets or sets the view model. - /// - object? ViewModel { get; set; } - } + object? ViewModel { get; set; } +} #pragma warning restore SA1402 // File may only contain a single type -} + diff --git a/src/Splat.Common.Test/IViewModelOne.cs b/src/Splat.Common.Test/IViewModelOne.cs index 09b270320..0a348d5e9 100644 --- a/src/Splat.Common.Test/IViewModelOne.cs +++ b/src/Splat.Common.Test/IViewModelOne.cs @@ -3,15 +3,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.Common.Test -{ - /// - /// Interface for ViewModelOne. - /// -#pragma warning disable CA1040 // Avoid empty interfaces +namespace Splat.Common.Test; - public interface IViewModelOne -#pragma warning restore CA1040 // Avoid empty interfaces - { - } +/// +/// Interface for ViewModelOne. +/// +public interface IViewModelOne +{ } diff --git a/src/Splat.Common.Test/MockScreen.cs b/src/Splat.Common.Test/MockScreen.cs index 2f0bf0f84..a99c0e4ed 100644 --- a/src/Splat.Common.Test/MockScreen.cs +++ b/src/Splat.Common.Test/MockScreen.cs @@ -5,14 +5,13 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Common.Test +namespace Splat.Common.Test; + +/// +/// An implementation. +/// +/// +[ExcludeFromCodeCoverage] +public class MockScreen : IScreen { - /// - /// An implementation. - /// - /// - [ExcludeFromCodeCoverage] - public class MockScreen : IScreen - { - } } diff --git a/src/Splat.Common.Test/ViewModelOne.cs b/src/Splat.Common.Test/ViewModelOne.cs index f2b68af09..1859ce6be 100644 --- a/src/Splat.Common.Test/ViewModelOne.cs +++ b/src/Splat.Common.Test/ViewModelOne.cs @@ -5,19 +5,18 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Common.Test +namespace Splat.Common.Test; + +/// +/// View Model One. +/// +[ExcludeFromCodeCoverage] +public class ViewModelOne : IViewModelOne { /// - /// View Model One. + /// Initializes a new instance of the class. /// - [ExcludeFromCodeCoverage] - public class ViewModelOne : IViewModelOne + public ViewModelOne() { - /// - /// Initializes a new instance of the class. - /// - public ViewModelOne() - { - } } } diff --git a/src/Splat.Common.Test/ViewModelTwo.cs b/src/Splat.Common.Test/ViewModelTwo.cs index 42e0ec53b..b1daef8cd 100644 --- a/src/Splat.Common.Test/ViewModelTwo.cs +++ b/src/Splat.Common.Test/ViewModelTwo.cs @@ -5,13 +5,12 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Common.Test +namespace Splat.Common.Test; + +/// +/// View Model Two. +/// +[ExcludeFromCodeCoverage] +public class ViewModelTwo { - /// - /// View Model Two. - /// - [ExcludeFromCodeCoverage] - public class ViewModelTwo - { - } } diff --git a/src/Splat.Common.Test/ViewOne.cs b/src/Splat.Common.Test/ViewOne.cs index fdaee051a..5a0ef942c 100644 --- a/src/Splat.Common.Test/ViewOne.cs +++ b/src/Splat.Common.Test/ViewOne.cs @@ -5,23 +5,22 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Common.Test +namespace Splat.Common.Test; + +/// +/// View One. +/// +/// +[ExcludeFromCodeCoverage] +public class ViewOne : IViewFor { - /// - /// View One. - /// - /// - [ExcludeFromCodeCoverage] - public class ViewOne : IViewFor + /// + object? IViewFor.ViewModel { - /// - object? IViewFor.ViewModel - { - get => ViewModel; - set => ViewModel = (ViewModelOne?)value; - } - - /// - public ViewModelOne? ViewModel { get; set; } + get => ViewModel; + set => ViewModel = (ViewModelOne?)value; } + + /// + public ViewModelOne? ViewModel { get; set; } } diff --git a/src/Splat.Common.Test/ViewThatShouldNotLoad.cs b/src/Splat.Common.Test/ViewThatShouldNotLoad.cs index f49b05958..9f89cf776 100644 --- a/src/Splat.Common.Test/ViewThatShouldNotLoad.cs +++ b/src/Splat.Common.Test/ViewThatShouldNotLoad.cs @@ -5,31 +5,30 @@ using System; -namespace Splat.Common.Test +namespace Splat.Common.Test; + +/// +/// This is a test view relating to issue #889. +/// It's intended to ensure that view registration by different DI\IoC implementations +/// does not create an instance at the point of registration. +/// +public sealed class ViewThatShouldNotLoad : IViewFor { /// - /// This is a test view relating to issue #889. - /// It's intended to ensure that view registration by different DI\IoC implementations - /// does not create an instance at the point of registration. + /// Initializes a new instance of the class. /// - public sealed class ViewThatShouldNotLoad : IViewFor + public ViewThatShouldNotLoad() { - /// - /// Initializes a new instance of the class. - /// - public ViewThatShouldNotLoad() - { - throw new InvalidOperationException("This view should not be created."); - } - - /// - object? IViewFor.ViewModel - { - get => ViewModel; - set => ViewModel = (ViewModelOne?)value; - } + throw new InvalidOperationException("This view should not be created."); + } - /// - public ViewModelOne? ViewModel { get; set; } + /// + object? IViewFor.ViewModel + { + get => ViewModel; + set => ViewModel = (ViewModelOne?)value; } + + /// + public ViewModelOne? ViewModel { get; set; } } diff --git a/src/Splat.Common.Test/ViewTwo.cs b/src/Splat.Common.Test/ViewTwo.cs index ed019d12d..743f8c184 100644 --- a/src/Splat.Common.Test/ViewTwo.cs +++ b/src/Splat.Common.Test/ViewTwo.cs @@ -5,23 +5,22 @@ using System.Diagnostics.CodeAnalysis; -namespace Splat.Common.Test +namespace Splat.Common.Test; + +/// +/// View Two. +/// +/// +[ExcludeFromCodeCoverage] +public class ViewTwo : IViewFor { - /// - /// View Two. - /// - /// - [ExcludeFromCodeCoverage] - public class ViewTwo : IViewFor + /// + object? IViewFor.ViewModel { - /// - object? IViewFor.ViewModel - { - get => ViewModel; - set => ViewModel = (ViewModelTwo?)value; - } - - /// - public ViewModelTwo? ViewModel { get; set; } + get => ViewModel; + set => ViewModel = (ViewModelTwo?)value; } + + /// + public ViewModelTwo? ViewModel { get; set; } } 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 879a4c96e..3bad410d3 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 @@ -4,7 +4,7 @@ [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Uwp")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.Tests")] [assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows7.0")] -[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName="")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")] [assembly: System.Runtime.Versioning.TargetPlatform("Windows7.0")] namespace Splat { diff --git a/src/Splat.Drawing.Tests/API/ApiApprovalTests.cs b/src/Splat.Drawing.Tests/API/ApiApprovalTests.cs index 0f69a27a5..53a85a654 100644 --- a/src/Splat.Drawing.Tests/API/ApiApprovalTests.cs +++ b/src/Splat.Drawing.Tests/API/ApiApprovalTests.cs @@ -10,19 +10,18 @@ #pragma warning disable SA1615 // Element return value should be documented -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Tests to make sure that the API matches the approved ones. +/// +[ExcludeFromCodeCoverage] +[UsesVerify] +public class ApiApprovalTests { /// - /// Tests to make sure that the API matches the approved ones. + /// Tests to make sure the splat project is approved. /// - [ExcludeFromCodeCoverage] - [UsesVerify] - public class ApiApprovalTests - { - /// - /// Tests to make sure the splat project is approved. - /// - [Fact] - public Task SplatUIProject() => typeof(IPlatformModeDetector).Assembly.CheckApproval(); - } + [Fact] + public Task SplatUIProject() => typeof(IPlatformModeDetector).Assembly.CheckApproval(); } diff --git a/src/Splat.Drawing.Tests/BitmapLoaderTests.cs b/src/Splat.Drawing.Tests/BitmapLoaderTests.cs index dd57aad95..44babe965 100644 --- a/src/Splat.Drawing.Tests/BitmapLoaderTests.cs +++ b/src/Splat.Drawing.Tests/BitmapLoaderTests.cs @@ -4,106 +4,104 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; using System.Reflection; -using System.Text; + using Xunit; #if !NETSTANDARD2_0 -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Unit Tests for the Bitmap Loader. +/// +public sealed class BitmapLoaderTests { /// - /// Unit Tests for the Bitmap Loader. + /// Gets the test data for the Load Suceeds Unit Test. /// - public sealed class BitmapLoaderTests + public static TheoryData> LoadSucceedsTestData { get; } = new() { - /// - /// Gets the test data for the Load Suceeds Unit Test. - /// - public static TheoryData> LoadSucceedsTestData { get; } = new() - { - GetPngStream, - GetJpegStream, - GetBitmapStream, - }; - - /// - /// Test to ensure the bitmap loader initializes properly. - /// - /// - /// Looks crude and pointless, but was produced to track an issue on Android between VS2017 and VS2019. - /// - [Fact] - public void ReturnsInstance() - { - var instance = new Splat.PlatformBitmapLoader(); - Assert.NotNull(instance); - } + GetPngStream, + GetJpegStream, + GetBitmapStream, + }; - /// - /// Test to ensure creating a default bitmap succeeds on all platforms. - /// - [Fact] - public void Create_Succeeds() - { - var instance = new Splat.PlatformBitmapLoader(); - var result = instance.Create(1, 1); + /// + /// Test to ensure the bitmap loader initializes properly. + /// + /// + /// Looks crude and pointless, but was produced to track an issue on Android between VS2017 and VS2019. + /// + [Fact] + public void ReturnsInstance() + { + var instance = new Splat.PlatformBitmapLoader(); + Assert.NotNull(instance); + } - Assert.NotNull(result); - } + /// + /// Test to ensure creating a default bitmap succeeds on all platforms. + /// + [Fact] + public void Create_Succeeds() + { + var instance = new Splat.PlatformBitmapLoader(); + var result = instance.Create(1, 1); - /// - /// Test to ensure loading a bitmap succeeds on all platforms. - /// - /// Function to load a file stream. - [Theory] - [MemberData(nameof(LoadSucceedsTestData))] - public void Load_Succeeds(Func getStream) - { - if (getStream is null) - { - throw new ArgumentNullException(nameof(getStream)); - } - - var instance = new Splat.PlatformBitmapLoader(); - - using (var sourceStream = getStream()) - { - var result = instance.Load( - sourceStream, - 640, - 480); - - Assert.NotNull(result); - } - } + Assert.NotNull(result); + } - private static Stream GetBitmapStream() + /// + /// Test to ensure loading a bitmap succeeds on all platforms. + /// + /// Function to load a file stream. + [Theory] + [MemberData(nameof(LoadSucceedsTestData))] + public void Load_Succeeds(Func getStream) + { + if (getStream is null) { - return GetStream("splatlogo.bmp"); + throw new ArgumentNullException(nameof(getStream)); } - private static Stream GetJpegStream() - { - return GetStream("splatlogo.jpg"); - } + var instance = new Splat.PlatformBitmapLoader(); - private static Stream GetPngStream() + using (var sourceStream = getStream()) { - return GetStream("splatlogo.png"); + var result = instance.Load( + sourceStream, + 640, + 480); + + Assert.NotNull(result); } + } - private static Stream GetStream(string imageName) - { + private static Stream GetBitmapStream() + { + return GetStream("splatlogo.bmp"); + } + + private static Stream GetJpegStream() + { + return GetStream("splatlogo.jpg"); + } + + private static Stream GetPngStream() + { + return GetStream("splatlogo.png"); + } + + private static Stream GetStream(string imageName) + { #if ANDROID - return Android.App.Application.Context.Assets.Open(imageName); + return Android.App.Application.Context.Assets.Open(imageName); #else - var assembly = Assembly.GetExecutingAssembly(); - return assembly.GetManifestResourceStream(imageName)!; + var assembly = Assembly.GetExecutingAssembly(); + return assembly.GetManifestResourceStream(imageName)!; #endif - } } } diff --git a/src/Splat.Drawing.Tests/Colors/CoverageColorTests.cs b/src/Splat.Drawing.Tests/Colors/CoverageColorTests.cs index 09fc2a297..bc256942b 100644 --- a/src/Splat.Drawing.Tests/Colors/CoverageColorTests.cs +++ b/src/Splat.Drawing.Tests/Colors/CoverageColorTests.cs @@ -1,226 +1,224 @@ using System; -using System.Collections.Generic; -using System.Text; + using Xunit; -namespace Splat.Drawing.Tests.Colors +namespace Splat.Drawing.Tests.Colors; + +/// +/// Coverage Color Tests. +/// +public class CoverageColorTests { /// - /// Coverage Color Tests. - /// - public class CoverageColorTests - { - /// - /// Colors the is empty. - /// - [Fact] - public void ColorIsEmpty() - { - var fixture = SplatColor.Empty; - Assert.True(fixture.IsEmpty); - Assert.Equal((byte)0, fixture.A); - Assert.Equal((byte)0, fixture.R); - Assert.Equal((byte)0, fixture.G); - Assert.Equal((byte)0, fixture.B); - } - - /// - /// Colors the is equal. - /// - [Fact] - public void ColorIsEqual() - { - var fixture1 = SplatColor.FromArgb(255, 0, 0, 139); - var fixture2 = SplatColor.FromKnownColor(KnownColor.DarkBlue); - Assert.True(fixture1 == fixture2); - } - - /// - /// ARGBs the color is equal. - /// - [Fact] - public void ARGBColorIsEqual() - { - var fixture1 = SplatColor.FromArgb(255, 0, 0, 139); - var fixture2 = SplatColor.FromArgb(0, 0, 139); - Assert.True(fixture1 == fixture2); - } - - /// - /// ARGBs the hexadecimal color is equal. - /// - [Fact] - public void ARGBHexColorIsEqual() - { - var fixture1 = SplatColor.FromArgb(0xFF00008B); - var fixture2 = SplatColor.FromArgb(0, 0, 139); - Assert.True(fixture1 == fixture2); - } - - /// - /// ARGBs the and named color is equal. - /// - [Fact] - public void ARGBAndNamedColorIsEqual() - { - var fixture1 = SplatColor.FromName("DarkBlue"); - var fixture2 = SplatColor.FromArgb(0, 0, 139); - Assert.True(fixture1 == fixture2); - } - - /// - /// ARGBs the based on named color is equal. - /// - [Fact] - public void ARGBBasedOnNamedColorIsEqual() - { - var fixture1 = SplatColor.FromName("DarkBlue"); - var fixture2 = SplatColor.FromArgb(255, fixture1); - Assert.True(fixture1 == fixture2); - } - - /// - /// Incorrect named color is equal to empty. - /// - [Fact] - public void IncorrectNamedColorIsEqualToEmpty() - { - var fixture1 = SplatColor.FromName("TheBestColor"); - var fixture2 = SplatColor.Empty; - Assert.True(fixture1 == fixture2); - Assert.Equal("TheBestColor", fixture1.Name); - } - - /// - /// Colors the is not equal. - /// - [Fact] - public void ColorIsNotEqual() - { - var fixture1 = SplatColor.FromArgb(255, 0, 0, 138); - var fixture2 = SplatColor.FromKnownColor(KnownColor.DarkBlue); - Assert.True(fixture1 != fixture2); - } - - /// - /// Colors the brightness. - /// - [Fact] - public void ColorBrightnessHasCorrectValue() - { - var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); - var brightness = fixture.GetBrightness(); - Assert.Equal(0.272549033f, brightness); - } - - /// - /// Colors the saturation has correct value. - /// - [Fact] - public void ColorSaturationHasCorrectValue() - { - var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); - var saturation = fixture.GetSaturation(); - Assert.Equal(1, saturation); - } - - /// - /// Colors the hue has correct value. - /// - [Fact] - public void ColorHueHasCorrectValue() - { - var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); - var hue = fixture.GetHue(); - Assert.Equal(240f, hue); - } - - /// - /// Colors to known color has correct value. - /// - [Fact] - public void ColorToKnownColorHasCorrectValue() - { - var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); - var color = fixture.ToKnownColor(); - Assert.Equal(KnownColor.DarkBlue, color); - } - - /// - /// Colors the is equals. - /// - [Fact] - public void ColorIsEquals() - { - object fixture1 = SplatColor.FromArgb(0xFF00008B); - object fixture2 = SplatColor.FromArgb(0, 0, 139); - Assert.True(fixture1.Equals(fixture2)); - } - - /// - /// Incorrects the named color to string gives value. - /// - [Fact] - public void IncorrectNamedColorToStringGivesValue() - { - var fixture1 = SplatColor.FromName("TheBestColor"); - Assert.Equal("SplatColor [TheBestColor]", fixture1.ToString()); - } - - /// - /// Nameds the color to string gives value. - /// - [Fact] - public void NamedColorToStringGivesValue() - { - var fixture1 = SplatColor.FromKnownColor(KnownColor.DarkBlue); - Assert.Equal("SplatColor [DarkBlue]", fixture1.ToString()); - } - - /// - /// ARGBs the color to string gives value. - /// - [Fact] - public void ARGBColorToStringGivesValue() - { - var fixture1 = SplatColor.FromArgb(255, 0, 0, 138); - Assert.Equal("SplatColor [A=255, R=0, G=0, B=138]", fixture1.ToString()); - } - - /// - /// Invalids the ARGB color A throws. - /// - [Fact] - public void InvalidARGBColorAThrows() - { - Assert.Throws(() => SplatColor.FromArgb(256, 0, 0, 0)); - } - - /// - /// Invalids the ARGB color r throws. - /// - [Fact] - public void InvalidARGBColorRThrows() - { - Assert.Throws(() => SplatColor.FromArgb(0, 256, 0, 0)); - } - - /// - /// Invalids the ARGB color g throws. - /// - [Fact] - public void InvalidARGBColorGThrows() - { - Assert.Throws(() => SplatColor.FromArgb(0, 0, 256, 0)); - } - - /// - /// Invalids the ARGB color b throws. - /// - [Fact] - public void InvalidARGBColorBThrows() - { - Assert.Throws(() => SplatColor.FromArgb(0, 0, 0, 256)); - } + /// Colors the is empty. + /// + [Fact] + public void ColorIsEmpty() + { + var fixture = SplatColor.Empty; + Assert.True(fixture.IsEmpty); + Assert.Equal((byte)0, fixture.A); + Assert.Equal((byte)0, fixture.R); + Assert.Equal((byte)0, fixture.G); + Assert.Equal((byte)0, fixture.B); + } + + /// + /// Colors the is equal. + /// + [Fact] + public void ColorIsEqual() + { + var fixture1 = SplatColor.FromArgb(255, 0, 0, 139); + var fixture2 = SplatColor.FromKnownColor(KnownColor.DarkBlue); + Assert.True(fixture1 == fixture2); + } + + /// + /// ARGBs the color is equal. + /// + [Fact] + public void ARGBColorIsEqual() + { + var fixture1 = SplatColor.FromArgb(255, 0, 0, 139); + var fixture2 = SplatColor.FromArgb(0, 0, 139); + Assert.True(fixture1 == fixture2); + } + + /// + /// ARGBs the hexadecimal color is equal. + /// + [Fact] + public void ARGBHexColorIsEqual() + { + var fixture1 = SplatColor.FromArgb(0xFF00008B); + var fixture2 = SplatColor.FromArgb(0, 0, 139); + Assert.True(fixture1 == fixture2); + } + + /// + /// ARGBs the and named color is equal. + /// + [Fact] + public void ARGBAndNamedColorIsEqual() + { + var fixture1 = SplatColor.FromName("DarkBlue"); + var fixture2 = SplatColor.FromArgb(0, 0, 139); + Assert.True(fixture1 == fixture2); + } + + /// + /// ARGBs the based on named color is equal. + /// + [Fact] + public void ARGBBasedOnNamedColorIsEqual() + { + var fixture1 = SplatColor.FromName("DarkBlue"); + var fixture2 = SplatColor.FromArgb(255, fixture1); + Assert.True(fixture1 == fixture2); + } + + /// + /// Incorrect named color is equal to empty. + /// + [Fact] + public void IncorrectNamedColorIsEqualToEmpty() + { + var fixture1 = SplatColor.FromName("TheBestColor"); + var fixture2 = SplatColor.Empty; + Assert.True(fixture1 == fixture2); + Assert.Equal("TheBestColor", fixture1.Name); + } + + /// + /// Colors the is not equal. + /// + [Fact] + public void ColorIsNotEqual() + { + var fixture1 = SplatColor.FromArgb(255, 0, 0, 138); + var fixture2 = SplatColor.FromKnownColor(KnownColor.DarkBlue); + Assert.True(fixture1 != fixture2); + } + + /// + /// Colors the brightness. + /// + [Fact] + public void ColorBrightnessHasCorrectValue() + { + var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); + var brightness = fixture.GetBrightness(); + Assert.Equal(0.272549033f, brightness); + } + + /// + /// Colors the saturation has correct value. + /// + [Fact] + public void ColorSaturationHasCorrectValue() + { + var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); + var saturation = fixture.GetSaturation(); + Assert.Equal(1, saturation); + } + + /// + /// Colors the hue has correct value. + /// + [Fact] + public void ColorHueHasCorrectValue() + { + var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); + var hue = fixture.GetHue(); + Assert.Equal(240f, hue); + } + + /// + /// Colors to known color has correct value. + /// + [Fact] + public void ColorToKnownColorHasCorrectValue() + { + var fixture = SplatColor.FromKnownColor(KnownColor.DarkBlue); + var color = fixture.ToKnownColor(); + Assert.Equal(KnownColor.DarkBlue, color); + } + + /// + /// Colors the is equals. + /// + [Fact] + public void ColorIsEquals() + { + object fixture1 = SplatColor.FromArgb(0xFF00008B); + object fixture2 = SplatColor.FromArgb(0, 0, 139); + Assert.True(fixture1.Equals(fixture2)); + } + + /// + /// Incorrects the named color to string gives value. + /// + [Fact] + public void IncorrectNamedColorToStringGivesValue() + { + var fixture1 = SplatColor.FromName("TheBestColor"); + Assert.Equal("SplatColor [TheBestColor]", fixture1.ToString()); + } + + /// + /// Nameds the color to string gives value. + /// + [Fact] + public void NamedColorToStringGivesValue() + { + var fixture1 = SplatColor.FromKnownColor(KnownColor.DarkBlue); + Assert.Equal("SplatColor [DarkBlue]", fixture1.ToString()); + } + + /// + /// ARGBs the color to string gives value. + /// + [Fact] + public void ARGBColorToStringGivesValue() + { + var fixture1 = SplatColor.FromArgb(255, 0, 0, 138); + Assert.Equal("SplatColor [A=255, R=0, G=0, B=138]", fixture1.ToString()); + } + + /// + /// Invalids the ARGB color A throws. + /// + [Fact] + public void InvalidARGBColorAThrows() + { + Assert.Throws(() => SplatColor.FromArgb(256, 0, 0, 0)); + } + + /// + /// Invalids the ARGB color r throws. + /// + [Fact] + public void InvalidARGBColorRThrows() + { + Assert.Throws(() => SplatColor.FromArgb(0, 256, 0, 0)); + } + + /// + /// Invalids the ARGB color g throws. + /// + [Fact] + public void InvalidARGBColorGThrows() + { + Assert.Throws(() => SplatColor.FromArgb(0, 0, 256, 0)); + } + + /// + /// Invalids the ARGB color b throws. + /// + [Fact] + public void InvalidARGBColorBThrows() + { + Assert.Throws(() => SplatColor.FromArgb(0, 0, 0, 256)); } } diff --git a/src/Splat.Drawing.Tests/Colors/KnownColorTests.cs b/src/Splat.Drawing.Tests/Colors/KnownColorTests.cs index 8ad8ccecc..aa4881fa9 100644 --- a/src/Splat.Drawing.Tests/Colors/KnownColorTests.cs +++ b/src/Splat.Drawing.Tests/Colors/KnownColorTests.cs @@ -3,41 +3,39 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; -using System.Text; + using Xunit; -namespace Splat.Tests.Colors +namespace Splat.Tests.Colors; + +/// +/// Unit Tests for Known Color logic. +/// +public class KnownColorTests { /// - /// Unit Tests for Known Color logic. + /// Gets the test data for FromKnownColor. /// - public class KnownColorTests - { - /// - /// Gets the test data for FromKnownColor. - /// - public static IEnumerable KnownColorEnums { get; } = XUnitHelpers.GetEnumAsTestTheory(); + public static IEnumerable KnownColorEnums { get; } = XUnitHelpers.GetEnumAsTestTheory(); - /// - /// Tests to ensure a name is returned from a number akin to a KnownColor. - /// - /// Known Color Enum to check. - [Theory] - [MemberData(nameof(KnownColorEnums))] - public void GetNameReturnsName(KnownColor knownColor) - { + /// + /// Tests to ensure a name is returned from a number akin to a KnownColor. + /// + /// Known Color Enum to check. + [Theory] + [MemberData(nameof(KnownColorEnums))] + public void GetNameReturnsName(KnownColor knownColor) + { #if !NET_2_0 - if ((short)knownColor > 167) - { - // can't assess these. - return; - } + if ((short)knownColor > 167) + { + // can't assess these. + return; + } #endif - var name = KnownColors.GetName(knownColor); - Assert.False(string.IsNullOrWhiteSpace(name)); - } + var name = KnownColors.GetName(knownColor); + Assert.False(string.IsNullOrWhiteSpace(name)); } } diff --git a/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs b/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs index 7beb4d505..7714edcb1 100644 --- a/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs +++ b/src/Splat.Drawing.Tests/Colors/SplatColorTests.cs @@ -5,60 +5,58 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; + using Xunit; [module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldShouldBePrivate", Justification = "XUnit Theories.")] -namespace Splat.Tests.Colors +namespace Splat.Tests.Colors; + +/// +/// Unit Tests for the Splat Color logic. +/// +public class SplatColorTests { /// - /// Unit Tests for the Splat Color logic. + /// Gets the test data for FromKnownColor. /// - public class SplatColorTests - { - /// - /// Gets the test data for FromKnownColor. - /// - public static IEnumerable KnownColorEnums { get; } = XUnitHelpers.GetEnumAsTestTheory(); + public static IEnumerable KnownColorEnums { get; } = XUnitHelpers.GetEnumAsTestTheory(); - /// - /// Tests to check you can get a SplatColor from a KnownColor. - /// - /// The Known Colour to convert. - [Theory] - [MemberData(nameof(KnownColorEnums))] - public void FromKnownColorTests(KnownColor knownColor) - { - var splatColor = SplatColor.FromKnownColor(knownColor); + /// + /// Tests to check you can get a SplatColor from a KnownColor. + /// + /// The Known Colour to convert. + [Theory] + [MemberData(nameof(KnownColorEnums))] + public void FromKnownColorTests(KnownColor knownColor) + { + var splatColor = SplatColor.FromKnownColor(knownColor); - Assert.NotNull(splatColor.Name); - } + Assert.NotNull(splatColor.Name); + } - /// - /// Tests to check you can get a SplatColor from a name. - /// - /// The Known Colour to convert. - [Theory] - [MemberData(nameof(KnownColorEnums))] - public void FromNameTests(KnownColor knownColor) - { - var splatColor = SplatColor.FromName(knownColor.ToString()); + /// + /// Tests to check you can get a SplatColor from a name. + /// + /// The Known Colour to convert. + [Theory] + [MemberData(nameof(KnownColorEnums))] + public void FromNameTests(KnownColor knownColor) + { + var splatColor = SplatColor.FromName(knownColor.ToString()); - Assert.NotNull(splatColor.Name); - } + Assert.NotNull(splatColor.Name); + } - private static IEnumerable GetEnumAsTestTheory() + private static IEnumerable GetEnumAsTestTheory() + { + var values = Enum.GetValues(typeof(KnownColor)); + var results = new List(values.Length); + foreach (var value in values) { - var values = Enum.GetValues(typeof(KnownColor)); - var results = new List(values.Length); - foreach (var value in values) - { - results.Add(new[] { value! }); - } - - return results; + results.Add(new[] { value! }); } + + return results; } } diff --git a/src/Splat.Drawing.Tests/PlatformBitmapLoaderTests.cs b/src/Splat.Drawing.Tests/PlatformBitmapLoaderTests.cs index 4a4d5d1a3..7682ec341 100644 --- a/src/Splat.Drawing.Tests/PlatformBitmapLoaderTests.cs +++ b/src/Splat.Drawing.Tests/PlatformBitmapLoaderTests.cs @@ -3,63 +3,57 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; -using System.Text; using Xunit; -namespace Splat.Tests.Platform +namespace Splat.Tests.Platform; + +/// +/// Unit tests for the platform specific Bitmap loader. +/// +public sealed class PlatformBitmapLoaderTests { +#if !NETSTANDARD && !NETCOREAPP2 /// - /// Unit tests for the platform specific Bitmap loader. + /// Check to ensure an instance is returned. /// - public sealed class PlatformBitmapLoaderTests + [Fact] + public void Constructor_ReturnsInstance() { -#if !NETSTANDARD && !NETCOREAPP2 - /// - /// Check to ensure an instance is returned. - /// - [Fact] - public void Constructor_ReturnsInstance() - { - var instance = new Splat.PlatformBitmapLoader(); - Assert.NotNull(instance); - } + var instance = new Splat.PlatformBitmapLoader(); + Assert.NotNull(instance); + } #endif #if ANDROID - /// - /// Checks to ensure a dynamic assembly behaves on android. - /// - /// - /// Introduced because of Splat #330. - /// - [Fact] - public void GetTypesFromAssembly_ReturnsResultsOnDynamicAssembly() - { - var name = new AssemblyName("SomeRandomDynamicAssembly"); - var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly( - name, AssemblyBuilderAccess.Run); + /// + /// Checks to ensure a dynamic assembly behaves on android. + /// + /// + /// Introduced because of Splat #330. + /// + [Fact] + public void GetTypesFromAssembly_ReturnsResultsOnDynamicAssembly() + { + var name = new AssemblyName("SomeRandomDynamicAssembly"); + var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly( + name, AssemblyBuilderAccess.Run); - // can't test with a logger, as it invokes the splat init, which puts the test in a false state as it will init the platform bitmap loader - var drawableList = Splat.PlatformBitmapLoader.GetTypesFromAssembly(assemblyBuilder, null); - Assert.NotNull(drawableList); - Assert.Equal(0, drawableList.Length); - } + // can't test with a logger, as it invokes the splat init, which puts the test in a false state as it will init the platform bitmap loader + var drawableList = Splat.PlatformBitmapLoader.GetTypesFromAssembly(assemblyBuilder, null); + Assert.NotNull(drawableList); + Assert.Equal(0, drawableList.Length); + } - /// - /// Checks to ensure a list of drawable items is returned. - /// - [Fact] - public void GetDrawableList_ReturnsResults() - { - // can't test with a logger, as it invokes the splat init, which puts the test in a false state as it will init the platform bitmap loader - var drawableList = Splat.PlatformBitmapLoader.GetDrawableList(null); - Assert.NotNull(drawableList); - Assert.True(drawableList.Count > 0); - } -#endif + /// + /// Checks to ensure a list of drawable items is returned. + /// + [Fact] + public void GetDrawableList_ReturnsResults() + { + // can't test with a logger, as it invokes the splat init, which puts the test in a false state as it will init the platform bitmap loader + var drawableList = Splat.PlatformBitmapLoader.GetDrawableList(null); + Assert.NotNull(drawableList); + Assert.True(drawableList.Count > 0); } +#endif } diff --git a/src/Splat.Drawing/Bitmaps/BitmapLoader.cs b/src/Splat.Drawing/Bitmaps/BitmapLoader.cs index 9b018763a..74510d3a5 100644 --- a/src/Splat.Drawing/Bitmaps/BitmapLoader.cs +++ b/src/Splat.Drawing/Bitmaps/BitmapLoader.cs @@ -3,39 +3,37 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Diagnostics.CodeAnalysis; -namespace Splat +namespace Splat; + +/// +/// This class loads and creates bitmap resources in a platform-independent. +/// way. +/// +public static class BitmapLoader { + // TODO: This needs to be improved once we move the "Detect in Unit Test + // Runner" code into Splat + private static IBitmapLoader? _current = Locator.Current.GetService(); + /// - /// This class loads and creates bitmap resources in a platform-independent. - /// way. + /// Gets or sets the current bitmap loader. /// - public static class BitmapLoader + /// When there is no exception loader having been found. + [SuppressMessage("Design", "CA1065: Do not raise exceptions in properties", Justification = "Very rare scenario")] + public static IBitmapLoader Current { - // TODO: This needs to be improved once we move the "Detect in Unit Test - // Runner" code into Splat - private static IBitmapLoader? _current = Locator.Current.GetService(); - - /// - /// Gets or sets the current bitmap loader. - /// - /// When there is no exception loader having been found. - [SuppressMessage("Design", "CA1065: Do not raise exceptions in properties", Justification = "Very rare scenario")] - public static IBitmapLoader Current + get { - get + var ret = _current; + if (ret is null) { - var ret = _current; - if (ret is null) - { - throw new BitmapLoaderException("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken"); - } - - return ret; + throw new BitmapLoaderException("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken"); } - set => _current = value; + + return ret; } + set => _current = value; } } diff --git a/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs b/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs index c14140b14..105696934 100644 --- a/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs +++ b/src/Splat.Drawing/Bitmaps/BitmapLoaderException.cs @@ -6,46 +6,45 @@ using System; using System.Runtime.Serialization; -namespace Splat +namespace Splat; + +/// +/// A exception that occurs when there is a problem using or retrieving the . +/// +[Serializable] +public class BitmapLoaderException : Exception { /// - /// A exception that occurs when there is a problem using or retrieving the . + /// Initializes a new instance of the class. /// - [Serializable] - public class BitmapLoaderException : Exception + public BitmapLoaderException() { - /// - /// Initializes a new instance of the class. - /// - public BitmapLoaderException() - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// The message about the exception. - public BitmapLoaderException(string message) - : base(message) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The message about the exception. + public BitmapLoaderException(string message) + : base(message) + { + } - /// - /// Initializes a new instance of the class. - /// - /// The message about the exception. - /// Any other internal exceptions we are mapping. - public BitmapLoaderException(string message, Exception innerException) - : base(message, innerException) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The message about the exception. + /// Any other internal exceptions we are mapping. + 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) - { - } + /// 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/Bitmaps/CompressedBitmapFormat.cs b/src/Splat.Drawing/Bitmaps/CompressedBitmapFormat.cs index 566fe4eb0..6636db080 100644 --- a/src/Splat.Drawing/Bitmaps/CompressedBitmapFormat.cs +++ b/src/Splat.Drawing/Bitmaps/CompressedBitmapFormat.cs @@ -3,21 +3,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// Specifies that compressed bitmap format. +/// +public enum CompressedBitmapFormat { /// - /// Specifies that compressed bitmap format. + /// Store the bitmap as a PNG format. /// - public enum CompressedBitmapFormat - { - /// - /// Store the bitmap as a PNG format. - /// - Png, + Png, - /// - /// Store the bitmap as a JPEG format. - /// - Jpeg, - } + /// + /// Store the bitmap as a JPEG format. + /// + Jpeg, } diff --git a/src/Splat.Drawing/Bitmaps/IBitmap.cs b/src/Splat.Drawing/Bitmaps/IBitmap.cs index 15aeb5048..9c4cdbd9f 100644 --- a/src/Splat.Drawing/Bitmaps/IBitmap.cs +++ b/src/Splat.Drawing/Bitmaps/IBitmap.cs @@ -7,33 +7,32 @@ using System.IO; using System.Threading.Tasks; -namespace Splat +namespace Splat; + +/// +/// Represents a bitmap image that was loaded via a ViewModel. Every platform +/// provides FromNative and ToNative methods to convert this object to the +/// platform-specific versions. +/// +public interface IBitmap : IDisposable { /// - /// Represents a bitmap image that was loaded via a ViewModel. Every platform - /// provides FromNative and ToNative methods to convert this object to the - /// platform-specific versions. + /// Gets the width in pixel units (depending on platform). /// - public interface IBitmap : IDisposable - { - /// - /// Gets the width in pixel units (depending on platform). - /// - float Width { get; } + float Width { get; } - /// - /// Gets the height in pixel units (depending on platform). - /// - float Height { get; } + /// + /// Gets the height in pixel units (depending on platform). + /// + float Height { get; } - /// - /// Saves an image to a target stream. - /// - /// The format to save the image in. - /// If JPEG is specified, this is a quality - /// factor between 0.0 and 1.0f where 1.0f is the best quality. - /// The target stream to save to. - /// A signal indicating the Save has completed. - Task Save(CompressedBitmapFormat format, float quality, Stream target); - } + /// + /// Saves an image to a target stream. + /// + /// The format to save the image in. + /// If JPEG is specified, this is a quality + /// factor between 0.0 and 1.0f where 1.0f is the best quality. + /// The target stream to save to. + /// A signal indicating the Save has completed. + Task Save(CompressedBitmapFormat format, float quality, Stream target); } diff --git a/src/Splat.Drawing/Bitmaps/IBitmapLoader.cs b/src/Splat.Drawing/Bitmaps/IBitmapLoader.cs index 18c05fd9a..09f38a035 100644 --- a/src/Splat.Drawing/Bitmaps/IBitmapLoader.cs +++ b/src/Splat.Drawing/Bitmaps/IBitmapLoader.cs @@ -6,39 +6,38 @@ using System.IO; using System.Threading.Tasks; -namespace Splat +namespace Splat; + +/// +/// Represents the platform-specific image loader class. Unless you are +/// testing image loading, you don't usually need to implement this. +/// +public interface IBitmapLoader { /// - /// Represents the platform-specific image loader class. Unless you are - /// testing image loading, you don't usually need to implement this. + /// Loads a bitmap from a byte stream. /// - public interface IBitmapLoader - { - /// - /// Loads a bitmap from a byte stream. - /// - /// The stream to load the image from. - /// The desired width of the image. - /// The desired height of the image. - /// A future result representing the loaded image. - Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight); + /// The stream to load the image from. + /// The desired width of the image. + /// The desired height of the image. + /// A future result representing the loaded image. + Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight); - /// - /// Loads from the application's resources (i.e. from bundle on Cocoa, - /// from Pack URIs on Windows, etc). - /// - /// The source resource, as a relative path. - /// Desired width. - /// Desired height. - /// A future result representing the loaded image. - Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight); + /// + /// Loads from the application's resources (i.e. from bundle on Cocoa, + /// from Pack URIs on Windows, etc). + /// + /// The source resource, as a relative path. + /// Desired width. + /// Desired height. + /// A future result representing the loaded image. + Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight); - /// - /// Creates an empty bitmap of the specified dimensions. - /// - /// The width of the canvas. - /// The height of the canvas. - /// A new image. Use ToNative() to convert this to a native bitmap. - IBitmap? Create(float width, float height); - } + /// + /// Creates an empty bitmap of the specified dimensions. + /// + /// The width of the canvas. + /// The height of the canvas. + /// A new image. Use ToNative() to convert this to a native bitmap. + IBitmap? Create(float width, float height); } diff --git a/src/Splat.Drawing/Colors/SplatColor.KnownColors.cs b/src/Splat.Drawing/Colors/SplatColor.KnownColors.cs index 4c407a09d..982e9044a 100644 --- a/src/Splat.Drawing/Colors/SplatColor.KnownColors.cs +++ b/src/Splat.Drawing/Colors/SplatColor.KnownColors.cs @@ -3,716 +3,715 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// A platform independent color structure. +/// +public partial struct SplatColor { /// - /// A platform independent color structure. - /// - public partial struct SplatColor - { - /// - /// Gets a color which is fully transparent. - /// - public static SplatColor Transparent => KnownColors.FromKnownColor(KnownColor.Transparent); - - /// - /// Gets a color which is alice blue. - /// - public static SplatColor AliceBlue => KnownColors.FromKnownColor(KnownColor.AliceBlue); - - /// - /// Gets a color which is antique white. - /// - public static SplatColor AntiqueWhite => KnownColors.FromKnownColor(KnownColor.AntiqueWhite); - - /// - /// Gets a color which is aqua. - /// - public static SplatColor Aqua => KnownColors.FromKnownColor(KnownColor.Aqua); - - /// - /// Gets a color which is aquamarine. - /// - public static SplatColor Aquamarine => KnownColors.FromKnownColor(KnownColor.Aquamarine); - - /// - /// Gets a color which is azure. - /// - public static SplatColor Azure => KnownColors.FromKnownColor(KnownColor.Azure); - - /// - /// Gets a color which is beige. - /// - public static SplatColor Beige => KnownColors.FromKnownColor(KnownColor.Beige); - - /// - /// Gets a color which is bisque. - /// - public static SplatColor Bisque => KnownColors.FromKnownColor(KnownColor.Bisque); - - /// - /// Gets a color which is black. - /// - public static SplatColor Black => KnownColors.FromKnownColor(KnownColor.Black); - - /// - /// Gets a color which is blanched almond. - /// - public static SplatColor BlanchedAlmond => KnownColors.FromKnownColor(KnownColor.BlanchedAlmond); - - /// - /// Gets a color which is blue. - /// - public static SplatColor Blue => KnownColors.FromKnownColor(KnownColor.Blue); - - /// - /// Gets a color which is blue violet. - /// - public static SplatColor BlueViolet => KnownColors.FromKnownColor(KnownColor.BlueViolet); - - /// - /// Gets a color which is brown. - /// - public static SplatColor Brown => KnownColors.FromKnownColor(KnownColor.Brown); - - /// - /// Gets a color which is burly wood. - /// - public static SplatColor BurlyWood => KnownColors.FromKnownColor(KnownColor.BurlyWood); - - /// - /// Gets a color which is cadet blue. - /// - public static SplatColor CadetBlue => KnownColors.FromKnownColor(KnownColor.CadetBlue); - - /// - /// Gets a color which is churtreuse. - /// - public static SplatColor Chartreuse => KnownColors.FromKnownColor(KnownColor.Chartreuse); - - /// - /// Gets a color which is chocolate. - /// - public static SplatColor Chocolate => KnownColors.FromKnownColor(KnownColor.Chocolate); - - /// - /// Gets a color which is coral. - /// - public static SplatColor Coral => KnownColors.FromKnownColor(KnownColor.Coral); - - /// - /// Gets a color which is cornflower blue. - /// - public static SplatColor CornflowerBlue => KnownColors.FromKnownColor(KnownColor.CornflowerBlue); - - /// - /// Gets a color which is cornsilk. - /// - public static SplatColor Cornsilk => KnownColors.FromKnownColor(KnownColor.Cornsilk); - - /// - /// Gets a color which is crimson. - /// - public static SplatColor Crimson => KnownColors.FromKnownColor(KnownColor.Crimson); - - /// - /// Gets a color which is cyan. - /// - public static SplatColor Cyan => KnownColors.FromKnownColor(KnownColor.Cyan); - - /// - /// Gets a color which is dark blue. - /// - public static SplatColor DarkBlue => KnownColors.FromKnownColor(KnownColor.DarkBlue); - - /// - /// Gets a color which is dark cyan. - /// - public static SplatColor DarkCyan => KnownColors.FromKnownColor(KnownColor.DarkCyan); - - /// - /// Gets a color which is dark goldenrod. - /// - public static SplatColor DarkGoldenrod => KnownColors.FromKnownColor(KnownColor.DarkGoldenrod); - - /// - /// Gets a color which is dark gray. - /// - public static SplatColor DarkGray => KnownColors.FromKnownColor(KnownColor.DarkGray); - - /// - /// Gets a color which is dark green. - /// - public static SplatColor DarkGreen => KnownColors.FromKnownColor(KnownColor.DarkGreen); - - /// - /// Gets a color which is dark khaki. - /// - public static SplatColor DarkKhaki => KnownColors.FromKnownColor(KnownColor.DarkKhaki); - - /// - /// Gets a color which is dark magenta. - /// - public static SplatColor DarkMagenta => KnownColors.FromKnownColor(KnownColor.DarkMagenta); - - /// - /// Gets a color which is dark olive green. - /// - public static SplatColor DarkOliveGreen => KnownColors.FromKnownColor(KnownColor.DarkOliveGreen); - - /// - /// Gets a color which is dark orange. - /// - public static SplatColor DarkOrange => KnownColors.FromKnownColor(KnownColor.DarkOrange); - - /// - /// Gets a color which is dark orchid. - /// - public static SplatColor DarkOrchid => KnownColors.FromKnownColor(KnownColor.DarkOrchid); - - /// - /// Gets a color which is dark red. - /// - public static SplatColor DarkRed => KnownColors.FromKnownColor(KnownColor.DarkRed); - - /// - /// Gets a color which is dark salmon. - /// - public static SplatColor DarkSalmon => KnownColors.FromKnownColor(KnownColor.DarkSalmon); - - /// - /// Gets a color which is dark sea green. - /// - public static SplatColor DarkSeaGreen => KnownColors.FromKnownColor(KnownColor.DarkSeaGreen); - - /// - /// Gets a color which is dark slate blue. - /// - public static SplatColor DarkSlateBlue => KnownColors.FromKnownColor(KnownColor.DarkSlateBlue); - - /// - /// Gets a color which is dark slate gray. - /// - public static SplatColor DarkSlateGray => KnownColors.FromKnownColor(KnownColor.DarkSlateGray); - - /// - /// Gets a color which is dark torquoise. - /// - public static SplatColor DarkTurquoise => KnownColors.FromKnownColor(KnownColor.DarkTurquoise); - - /// - /// Gets a color which is dark violet. - /// - public static SplatColor DarkViolet => KnownColors.FromKnownColor(KnownColor.DarkViolet); - - /// - /// Gets a color which is deep pink. - /// - public static SplatColor DeepPink => KnownColors.FromKnownColor(KnownColor.DeepPink); - - /// - /// Gets a color which is deep sky blue. - /// - public static SplatColor DeepSkyBlue => KnownColors.FromKnownColor(KnownColor.DeepSkyBlue); - - /// - /// Gets a color which is dim gray. - /// - public static SplatColor DimGray => KnownColors.FromKnownColor(KnownColor.DimGray); - - /// - /// Gets a color which is dodger blue. - /// - public static SplatColor DodgerBlue => KnownColors.FromKnownColor(KnownColor.DodgerBlue); - - /// - /// Gets a color which is fire brick. - /// - public static SplatColor Firebrick => KnownColors.FromKnownColor(KnownColor.Firebrick); - - /// - /// Gets a color which is floral white. - /// - public static SplatColor FloralWhite => KnownColors.FromKnownColor(KnownColor.FloralWhite); - - /// - /// Gets a color which is forest green. - /// - public static SplatColor ForestGreen => KnownColors.FromKnownColor(KnownColor.ForestGreen); - - /// - /// Gets a color which is fuchsia. - /// - public static SplatColor Fuchsia => KnownColors.FromKnownColor(KnownColor.Fuchsia); - - /// - /// Gets a color which is gainsboro. - /// - public static SplatColor Gainsboro => KnownColors.FromKnownColor(KnownColor.Gainsboro); - - /// - /// Gets a color which is ghost white. - /// - public static SplatColor GhostWhite => KnownColors.FromKnownColor(KnownColor.GhostWhite); - - /// - /// Gets a color which is gold. - /// - public static SplatColor Gold => KnownColors.FromKnownColor(KnownColor.Gold); - - /// - /// Gets a color which is golden rod. - /// - public static SplatColor Goldenrod => KnownColors.FromKnownColor(KnownColor.Goldenrod); - - /// - /// Gets a color which is gray. - /// - public static SplatColor Gray => KnownColors.FromKnownColor(KnownColor.Gray); - - /// - /// Gets a color which is green. - /// - public static SplatColor Green => KnownColors.FromKnownColor(KnownColor.Green); - - /// - /// Gets a color which is green yellow. - /// - public static SplatColor GreenYellow => KnownColors.FromKnownColor(KnownColor.GreenYellow); - - /// - /// Gets a color which is honeydew. - /// - public static SplatColor Honeydew => KnownColors.FromKnownColor(KnownColor.Honeydew); - - /// - /// Gets a color which is hot pink. - /// - public static SplatColor HotPink => KnownColors.FromKnownColor(KnownColor.HotPink); - - /// - /// Gets a color which is indian red. - /// - public static SplatColor IndianRed => KnownColors.FromKnownColor(KnownColor.IndianRed); - - /// - /// Gets a color which is indigo. - /// - public static SplatColor Indigo => KnownColors.FromKnownColor(KnownColor.Indigo); - - /// - /// Gets a color which is ivory. - /// - public static SplatColor Ivory => KnownColors.FromKnownColor(KnownColor.Ivory); - - /// - /// Gets a color which is khaki. - /// - public static SplatColor Khaki => KnownColors.FromKnownColor(KnownColor.Khaki); - - /// - /// Gets a color which is lavender. - /// - public static SplatColor Lavender => KnownColors.FromKnownColor(KnownColor.Lavender); - - /// - /// Gets a color which is lavender blush. - /// - public static SplatColor LavenderBlush => KnownColors.FromKnownColor(KnownColor.LavenderBlush); - - /// - /// Gets a color which is lawn green. - /// - public static SplatColor LawnGreen => KnownColors.FromKnownColor(KnownColor.LawnGreen); - - /// - /// Gets a color which is lemon chiffon. - /// - public static SplatColor LemonChiffon => KnownColors.FromKnownColor(KnownColor.LemonChiffon); - - /// - /// Gets a color which is light blue. - /// - public static SplatColor LightBlue => KnownColors.FromKnownColor(KnownColor.LightBlue); - - /// - /// Gets a color which is light coral. - /// - public static SplatColor LightCoral => KnownColors.FromKnownColor(KnownColor.LightCoral); - - /// - /// Gets a color which is light cyan. - /// - public static SplatColor LightCyan => KnownColors.FromKnownColor(KnownColor.LightCyan); - - /// - /// Gets a color which is light golden rod yellow. - /// - public static SplatColor LightGoldenrodYellow => KnownColors.FromKnownColor(KnownColor.LightGoldenrodYellow); - - /// - /// Gets a value which is light green. - /// - public static SplatColor LightGreen => KnownColors.FromKnownColor(KnownColor.LightGreen); - - /// - /// Gets a color which is light gray. - /// - public static SplatColor LightGray => KnownColors.FromKnownColor(KnownColor.LightGray); - - /// - /// Gets a color which is light pink. - /// - public static SplatColor LightPink => KnownColors.FromKnownColor(KnownColor.LightPink); - - /// - /// Gets a color which is light salmon. - /// - public static SplatColor LightSalmon => KnownColors.FromKnownColor(KnownColor.LightSalmon); - - /// - /// Gets a color which is light sea green. - /// - public static SplatColor LightSeaGreen => KnownColors.FromKnownColor(KnownColor.LightSeaGreen); - - /// - /// Gets a color which is light sky blue. - /// - public static SplatColor LightSkyBlue => KnownColors.FromKnownColor(KnownColor.LightSkyBlue); - - /// - /// Gets a color which is light slate gray. - /// - public static SplatColor LightSlateGray => KnownColors.FromKnownColor(KnownColor.LightSlateGray); - - /// - /// Gets a color which is light steel blue. - /// - public static SplatColor LightSteelBlue => KnownColors.FromKnownColor(KnownColor.LightSteelBlue); - - /// - /// Gets a color which is light yellow. - /// - public static SplatColor LightYellow => KnownColors.FromKnownColor(KnownColor.LightYellow); - - /// - /// Gets a color which is lime. - /// - public static SplatColor Lime => KnownColors.FromKnownColor(KnownColor.Lime); - - /// - /// Gets a color which is lime green. - /// - public static SplatColor LimeGreen => KnownColors.FromKnownColor(KnownColor.LimeGreen); - - /// - /// Gets a color which is linen. - /// - public static SplatColor Linen => KnownColors.FromKnownColor(KnownColor.Linen); - - /// - /// Gets a color which is magenta. - /// - public static SplatColor Magenta => KnownColors.FromKnownColor(KnownColor.Magenta); - - /// - /// Gets a color which is maroon. - /// - public static SplatColor Maroon => KnownColors.FromKnownColor(KnownColor.Maroon); - - /// - /// Gets a color which is medium aquamarine. - /// - public static SplatColor MediumAquamarine => KnownColors.FromKnownColor(KnownColor.MediumAquamarine); - - /// - /// Gets a color which is medium blue. - /// - public static SplatColor MediumBlue => KnownColors.FromKnownColor(KnownColor.MediumBlue); - - /// - /// Gets a color which is medium orchid. - /// - public static SplatColor MediumOrchid => KnownColors.FromKnownColor(KnownColor.MediumOrchid); - - /// - /// Gets a color which is medium purple. - /// - public static SplatColor MediumPurple => KnownColors.FromKnownColor(KnownColor.MediumPurple); - - /// - /// Gets a color which is medium sea green. - /// - public static SplatColor MediumSeaGreen => KnownColors.FromKnownColor(KnownColor.MediumSeaGreen); - - /// - /// Gets a color which is medium slate blue. - /// - public static SplatColor MediumSlateBlue => KnownColors.FromKnownColor(KnownColor.MediumSlateBlue); - - /// - /// Gets a color which is medium spring green. - /// - public static SplatColor MediumSpringGreen => KnownColors.FromKnownColor(KnownColor.MediumSpringGreen); - - /// - /// Gets a color which is medium turquoise. - /// - public static SplatColor MediumTurquoise => KnownColors.FromKnownColor(KnownColor.MediumTurquoise); - - /// - /// Gets a color which is medium violet red. - /// - public static SplatColor MediumVioletRed => KnownColors.FromKnownColor(KnownColor.MediumVioletRed); - - /// - /// Gets a color which is midnight blue. - /// - public static SplatColor MidnightBlue => KnownColors.FromKnownColor(KnownColor.MidnightBlue); - - /// - /// Gets a color which is mint cream. - /// - public static SplatColor MintCream => KnownColors.FromKnownColor(KnownColor.MintCream); - - /// - /// Gets a color which is misty rose. - /// - public static SplatColor MistyRose => KnownColors.FromKnownColor(KnownColor.MistyRose); - - /// - /// Gets a color which is moccasin. - /// - public static SplatColor Moccasin => KnownColors.FromKnownColor(KnownColor.Moccasin); - - /// - /// Gets a color which is navajo white. - /// - public static SplatColor NavajoWhite => KnownColors.FromKnownColor(KnownColor.NavajoWhite); - - /// - /// Gets a color which is navy. - /// - public static SplatColor Navy => KnownColors.FromKnownColor(KnownColor.Navy); - - /// - /// Gets a color hwich is old lace. - /// - public static SplatColor OldLace => KnownColors.FromKnownColor(KnownColor.OldLace); - - /// - /// Gets a color which is olive. - /// - public static SplatColor Olive => KnownColors.FromKnownColor(KnownColor.Olive); - - /// - /// Gets a color which is olive drab. - /// - public static SplatColor OliveDrab => KnownColors.FromKnownColor(KnownColor.OliveDrab); - - /// - /// Gets a color which is orange. - /// - public static SplatColor Orange => KnownColors.FromKnownColor(KnownColor.Orange); - - /// - /// Gets a color which is orange red. - /// - public static SplatColor OrangeRed => KnownColors.FromKnownColor(KnownColor.OrangeRed); - - /// - /// Gets a color which is orchid. - /// - public static SplatColor Orchid => KnownColors.FromKnownColor(KnownColor.Orchid); - - /// - /// Gets a color which is pale golden rod. - /// - public static SplatColor PaleGoldenrod => KnownColors.FromKnownColor(KnownColor.PaleGoldenrod); - - /// - /// Gets a color which is pale green. - /// - public static SplatColor PaleGreen => KnownColors.FromKnownColor(KnownColor.PaleGreen); - - /// - /// Gets a color which is pale turquoise. - /// - public static SplatColor PaleTurquoise => KnownColors.FromKnownColor(KnownColor.PaleTurquoise); - - /// - /// Gets a color which is pale violet red. - /// - public static SplatColor PaleVioletRed => KnownColors.FromKnownColor(KnownColor.PaleVioletRed); - - /// - /// Gets a color which is papaya whip. - /// - public static SplatColor PapayaWhip => KnownColors.FromKnownColor(KnownColor.PapayaWhip); - - /// - /// Gets a color which is peach puff. - /// - public static SplatColor PeachPuff => KnownColors.FromKnownColor(KnownColor.PeachPuff); - - /// - /// Gets a color which is peru. - /// - public static SplatColor Peru => KnownColors.FromKnownColor(KnownColor.Peru); - - /// - /// Gets a color which is pink. - /// - public static SplatColor Pink => KnownColors.FromKnownColor(KnownColor.Pink); - - /// - /// Gets a color which is plum. - /// - public static SplatColor Plum => KnownColors.FromKnownColor(KnownColor.Plum); - - /// - /// Gets a color which is powder blue. - /// - public static SplatColor PowderBlue => KnownColors.FromKnownColor(KnownColor.PowderBlue); - - /// - /// Gets a color which is purple. - /// - public static SplatColor Purple => KnownColors.FromKnownColor(KnownColor.Purple); - - /// - /// Gets a color which is red. - /// - public static SplatColor Red => KnownColors.FromKnownColor(KnownColor.Red); - - /// - /// Gets a color which is rosy brown. - /// - public static SplatColor RosyBrown => KnownColors.FromKnownColor(KnownColor.RosyBrown); - - /// - /// Gets a color which is royal blue. - /// - public static SplatColor RoyalBlue => KnownColors.FromKnownColor(KnownColor.RoyalBlue); - - /// - /// Gets a color which is saddle brown. - /// - public static SplatColor SaddleBrown => KnownColors.FromKnownColor(KnownColor.SaddleBrown); - - /// - /// Gets a color which is salmon. - /// - public static SplatColor Salmon => KnownColors.FromKnownColor(KnownColor.Salmon); - - /// - /// Gets a color which is sandy brown. - /// - public static SplatColor SandyBrown => KnownColors.FromKnownColor(KnownColor.SandyBrown); - - /// - /// Gets a color which is sea green. - /// - public static SplatColor SeaGreen => KnownColors.FromKnownColor(KnownColor.SeaGreen); - - /// - /// Gets a color which is sea shell. - /// - public static SplatColor SeaShell => KnownColors.FromKnownColor(KnownColor.SeaShell); - - /// - /// Gets a color which is sienna. - /// - public static SplatColor Sienna => KnownColors.FromKnownColor(KnownColor.Sienna); - - /// - /// Gets a color which is silver. - /// - public static SplatColor Silver => KnownColors.FromKnownColor(KnownColor.Silver); - - /// - /// Gets a color which is sky blue. - /// - public static SplatColor SkyBlue => KnownColors.FromKnownColor(KnownColor.SkyBlue); - - /// - /// Gets a color which is slate blue. - /// - public static SplatColor SlateBlue => KnownColors.FromKnownColor(KnownColor.SlateBlue); - - /// - /// Gets a color which is slate gray. - /// - public static SplatColor SlateGray => KnownColors.FromKnownColor(KnownColor.SlateGray); - - /// - /// Gets a color which is snow. - /// - public static SplatColor Snow => KnownColors.FromKnownColor(KnownColor.Snow); - - /// - /// Gets a color which is spring green. - /// - public static SplatColor SpringGreen => KnownColors.FromKnownColor(KnownColor.SpringGreen); - - /// - /// Gets a color which is steel blue. - /// - public static SplatColor SteelBlue => KnownColors.FromKnownColor(KnownColor.SteelBlue); - - /// - /// Gets a color which is tan. - /// - public static SplatColor Tan => KnownColors.FromKnownColor(KnownColor.Tan); - - /// - /// Gets a color which is teal. - /// - public static SplatColor Teal => KnownColors.FromKnownColor(KnownColor.Teal); - - /// - /// Gets a color which is thistle. - /// - public static SplatColor Thistle => KnownColors.FromKnownColor(KnownColor.Thistle); - - /// - /// Gets a color which is tomato. - /// - public static SplatColor Tomato => KnownColors.FromKnownColor(KnownColor.Tomato); - - /// - /// Gets a color which is turquoise. - /// - public static SplatColor Turquoise => KnownColors.FromKnownColor(KnownColor.Turquoise); - - /// - /// Gets a color which is violet. - /// - public static SplatColor Violet => KnownColors.FromKnownColor(KnownColor.Violet); - - /// - /// Gets a color which is wheat. - /// - public static SplatColor Wheat => KnownColors.FromKnownColor(KnownColor.Wheat); - - /// - /// Gets a color which is white. - /// - public static SplatColor White => KnownColors.FromKnownColor(KnownColor.White); - - /// - /// Gets a color which is white smoke. - /// - public static SplatColor WhiteSmoke => KnownColors.FromKnownColor(KnownColor.WhiteSmoke); - - /// - /// Gets a color which is yellow. - /// - public static SplatColor Yellow => KnownColors.FromKnownColor(KnownColor.Yellow); - - /// - /// Gets a color which is yellow green. - /// - public static SplatColor YellowGreen => KnownColors.FromKnownColor(KnownColor.YellowGreen); - } + /// Gets a color which is fully transparent. + /// + public static SplatColor Transparent => KnownColors.FromKnownColor(KnownColor.Transparent); + + /// + /// Gets a color which is alice blue. + /// + public static SplatColor AliceBlue => KnownColors.FromKnownColor(KnownColor.AliceBlue); + + /// + /// Gets a color which is antique white. + /// + public static SplatColor AntiqueWhite => KnownColors.FromKnownColor(KnownColor.AntiqueWhite); + + /// + /// Gets a color which is aqua. + /// + public static SplatColor Aqua => KnownColors.FromKnownColor(KnownColor.Aqua); + + /// + /// Gets a color which is aquamarine. + /// + public static SplatColor Aquamarine => KnownColors.FromKnownColor(KnownColor.Aquamarine); + + /// + /// Gets a color which is azure. + /// + public static SplatColor Azure => KnownColors.FromKnownColor(KnownColor.Azure); + + /// + /// Gets a color which is beige. + /// + public static SplatColor Beige => KnownColors.FromKnownColor(KnownColor.Beige); + + /// + /// Gets a color which is bisque. + /// + public static SplatColor Bisque => KnownColors.FromKnownColor(KnownColor.Bisque); + + /// + /// Gets a color which is black. + /// + public static SplatColor Black => KnownColors.FromKnownColor(KnownColor.Black); + + /// + /// Gets a color which is blanched almond. + /// + public static SplatColor BlanchedAlmond => KnownColors.FromKnownColor(KnownColor.BlanchedAlmond); + + /// + /// Gets a color which is blue. + /// + public static SplatColor Blue => KnownColors.FromKnownColor(KnownColor.Blue); + + /// + /// Gets a color which is blue violet. + /// + public static SplatColor BlueViolet => KnownColors.FromKnownColor(KnownColor.BlueViolet); + + /// + /// Gets a color which is brown. + /// + public static SplatColor Brown => KnownColors.FromKnownColor(KnownColor.Brown); + + /// + /// Gets a color which is burly wood. + /// + public static SplatColor BurlyWood => KnownColors.FromKnownColor(KnownColor.BurlyWood); + + /// + /// Gets a color which is cadet blue. + /// + public static SplatColor CadetBlue => KnownColors.FromKnownColor(KnownColor.CadetBlue); + + /// + /// Gets a color which is churtreuse. + /// + public static SplatColor Chartreuse => KnownColors.FromKnownColor(KnownColor.Chartreuse); + + /// + /// Gets a color which is chocolate. + /// + public static SplatColor Chocolate => KnownColors.FromKnownColor(KnownColor.Chocolate); + + /// + /// Gets a color which is coral. + /// + public static SplatColor Coral => KnownColors.FromKnownColor(KnownColor.Coral); + + /// + /// Gets a color which is cornflower blue. + /// + public static SplatColor CornflowerBlue => KnownColors.FromKnownColor(KnownColor.CornflowerBlue); + + /// + /// Gets a color which is cornsilk. + /// + public static SplatColor Cornsilk => KnownColors.FromKnownColor(KnownColor.Cornsilk); + + /// + /// Gets a color which is crimson. + /// + public static SplatColor Crimson => KnownColors.FromKnownColor(KnownColor.Crimson); + + /// + /// Gets a color which is cyan. + /// + public static SplatColor Cyan => KnownColors.FromKnownColor(KnownColor.Cyan); + + /// + /// Gets a color which is dark blue. + /// + public static SplatColor DarkBlue => KnownColors.FromKnownColor(KnownColor.DarkBlue); + + /// + /// Gets a color which is dark cyan. + /// + public static SplatColor DarkCyan => KnownColors.FromKnownColor(KnownColor.DarkCyan); + + /// + /// Gets a color which is dark goldenrod. + /// + public static SplatColor DarkGoldenrod => KnownColors.FromKnownColor(KnownColor.DarkGoldenrod); + + /// + /// Gets a color which is dark gray. + /// + public static SplatColor DarkGray => KnownColors.FromKnownColor(KnownColor.DarkGray); + + /// + /// Gets a color which is dark green. + /// + public static SplatColor DarkGreen => KnownColors.FromKnownColor(KnownColor.DarkGreen); + + /// + /// Gets a color which is dark khaki. + /// + public static SplatColor DarkKhaki => KnownColors.FromKnownColor(KnownColor.DarkKhaki); + + /// + /// Gets a color which is dark magenta. + /// + public static SplatColor DarkMagenta => KnownColors.FromKnownColor(KnownColor.DarkMagenta); + + /// + /// Gets a color which is dark olive green. + /// + public static SplatColor DarkOliveGreen => KnownColors.FromKnownColor(KnownColor.DarkOliveGreen); + + /// + /// Gets a color which is dark orange. + /// + public static SplatColor DarkOrange => KnownColors.FromKnownColor(KnownColor.DarkOrange); + + /// + /// Gets a color which is dark orchid. + /// + public static SplatColor DarkOrchid => KnownColors.FromKnownColor(KnownColor.DarkOrchid); + + /// + /// Gets a color which is dark red. + /// + public static SplatColor DarkRed => KnownColors.FromKnownColor(KnownColor.DarkRed); + + /// + /// Gets a color which is dark salmon. + /// + public static SplatColor DarkSalmon => KnownColors.FromKnownColor(KnownColor.DarkSalmon); + + /// + /// Gets a color which is dark sea green. + /// + public static SplatColor DarkSeaGreen => KnownColors.FromKnownColor(KnownColor.DarkSeaGreen); + + /// + /// Gets a color which is dark slate blue. + /// + public static SplatColor DarkSlateBlue => KnownColors.FromKnownColor(KnownColor.DarkSlateBlue); + + /// + /// Gets a color which is dark slate gray. + /// + public static SplatColor DarkSlateGray => KnownColors.FromKnownColor(KnownColor.DarkSlateGray); + + /// + /// Gets a color which is dark torquoise. + /// + public static SplatColor DarkTurquoise => KnownColors.FromKnownColor(KnownColor.DarkTurquoise); + + /// + /// Gets a color which is dark violet. + /// + public static SplatColor DarkViolet => KnownColors.FromKnownColor(KnownColor.DarkViolet); + + /// + /// Gets a color which is deep pink. + /// + public static SplatColor DeepPink => KnownColors.FromKnownColor(KnownColor.DeepPink); + + /// + /// Gets a color which is deep sky blue. + /// + public static SplatColor DeepSkyBlue => KnownColors.FromKnownColor(KnownColor.DeepSkyBlue); + + /// + /// Gets a color which is dim gray. + /// + public static SplatColor DimGray => KnownColors.FromKnownColor(KnownColor.DimGray); + + /// + /// Gets a color which is dodger blue. + /// + public static SplatColor DodgerBlue => KnownColors.FromKnownColor(KnownColor.DodgerBlue); + + /// + /// Gets a color which is fire brick. + /// + public static SplatColor Firebrick => KnownColors.FromKnownColor(KnownColor.Firebrick); + + /// + /// Gets a color which is floral white. + /// + public static SplatColor FloralWhite => KnownColors.FromKnownColor(KnownColor.FloralWhite); + + /// + /// Gets a color which is forest green. + /// + public static SplatColor ForestGreen => KnownColors.FromKnownColor(KnownColor.ForestGreen); + + /// + /// Gets a color which is fuchsia. + /// + public static SplatColor Fuchsia => KnownColors.FromKnownColor(KnownColor.Fuchsia); + + /// + /// Gets a color which is gainsboro. + /// + public static SplatColor Gainsboro => KnownColors.FromKnownColor(KnownColor.Gainsboro); + + /// + /// Gets a color which is ghost white. + /// + public static SplatColor GhostWhite => KnownColors.FromKnownColor(KnownColor.GhostWhite); + + /// + /// Gets a color which is gold. + /// + public static SplatColor Gold => KnownColors.FromKnownColor(KnownColor.Gold); + + /// + /// Gets a color which is golden rod. + /// + public static SplatColor Goldenrod => KnownColors.FromKnownColor(KnownColor.Goldenrod); + + /// + /// Gets a color which is gray. + /// + public static SplatColor Gray => KnownColors.FromKnownColor(KnownColor.Gray); + + /// + /// Gets a color which is green. + /// + public static SplatColor Green => KnownColors.FromKnownColor(KnownColor.Green); + + /// + /// Gets a color which is green yellow. + /// + public static SplatColor GreenYellow => KnownColors.FromKnownColor(KnownColor.GreenYellow); + + /// + /// Gets a color which is honeydew. + /// + public static SplatColor Honeydew => KnownColors.FromKnownColor(KnownColor.Honeydew); + + /// + /// Gets a color which is hot pink. + /// + public static SplatColor HotPink => KnownColors.FromKnownColor(KnownColor.HotPink); + + /// + /// Gets a color which is indian red. + /// + public static SplatColor IndianRed => KnownColors.FromKnownColor(KnownColor.IndianRed); + + /// + /// Gets a color which is indigo. + /// + public static SplatColor Indigo => KnownColors.FromKnownColor(KnownColor.Indigo); + + /// + /// Gets a color which is ivory. + /// + public static SplatColor Ivory => KnownColors.FromKnownColor(KnownColor.Ivory); + + /// + /// Gets a color which is khaki. + /// + public static SplatColor Khaki => KnownColors.FromKnownColor(KnownColor.Khaki); + + /// + /// Gets a color which is lavender. + /// + public static SplatColor Lavender => KnownColors.FromKnownColor(KnownColor.Lavender); + + /// + /// Gets a color which is lavender blush. + /// + public static SplatColor LavenderBlush => KnownColors.FromKnownColor(KnownColor.LavenderBlush); + + /// + /// Gets a color which is lawn green. + /// + public static SplatColor LawnGreen => KnownColors.FromKnownColor(KnownColor.LawnGreen); + + /// + /// Gets a color which is lemon chiffon. + /// + public static SplatColor LemonChiffon => KnownColors.FromKnownColor(KnownColor.LemonChiffon); + + /// + /// Gets a color which is light blue. + /// + public static SplatColor LightBlue => KnownColors.FromKnownColor(KnownColor.LightBlue); + + /// + /// Gets a color which is light coral. + /// + public static SplatColor LightCoral => KnownColors.FromKnownColor(KnownColor.LightCoral); + + /// + /// Gets a color which is light cyan. + /// + public static SplatColor LightCyan => KnownColors.FromKnownColor(KnownColor.LightCyan); + + /// + /// Gets a color which is light golden rod yellow. + /// + public static SplatColor LightGoldenrodYellow => KnownColors.FromKnownColor(KnownColor.LightGoldenrodYellow); + + /// + /// Gets a value which is light green. + /// + public static SplatColor LightGreen => KnownColors.FromKnownColor(KnownColor.LightGreen); + + /// + /// Gets a color which is light gray. + /// + public static SplatColor LightGray => KnownColors.FromKnownColor(KnownColor.LightGray); + + /// + /// Gets a color which is light pink. + /// + public static SplatColor LightPink => KnownColors.FromKnownColor(KnownColor.LightPink); + + /// + /// Gets a color which is light salmon. + /// + public static SplatColor LightSalmon => KnownColors.FromKnownColor(KnownColor.LightSalmon); + + /// + /// Gets a color which is light sea green. + /// + public static SplatColor LightSeaGreen => KnownColors.FromKnownColor(KnownColor.LightSeaGreen); + + /// + /// Gets a color which is light sky blue. + /// + public static SplatColor LightSkyBlue => KnownColors.FromKnownColor(KnownColor.LightSkyBlue); + + /// + /// Gets a color which is light slate gray. + /// + public static SplatColor LightSlateGray => KnownColors.FromKnownColor(KnownColor.LightSlateGray); + + /// + /// Gets a color which is light steel blue. + /// + public static SplatColor LightSteelBlue => KnownColors.FromKnownColor(KnownColor.LightSteelBlue); + + /// + /// Gets a color which is light yellow. + /// + public static SplatColor LightYellow => KnownColors.FromKnownColor(KnownColor.LightYellow); + + /// + /// Gets a color which is lime. + /// + public static SplatColor Lime => KnownColors.FromKnownColor(KnownColor.Lime); + + /// + /// Gets a color which is lime green. + /// + public static SplatColor LimeGreen => KnownColors.FromKnownColor(KnownColor.LimeGreen); + + /// + /// Gets a color which is linen. + /// + public static SplatColor Linen => KnownColors.FromKnownColor(KnownColor.Linen); + + /// + /// Gets a color which is magenta. + /// + public static SplatColor Magenta => KnownColors.FromKnownColor(KnownColor.Magenta); + + /// + /// Gets a color which is maroon. + /// + public static SplatColor Maroon => KnownColors.FromKnownColor(KnownColor.Maroon); + + /// + /// Gets a color which is medium aquamarine. + /// + public static SplatColor MediumAquamarine => KnownColors.FromKnownColor(KnownColor.MediumAquamarine); + + /// + /// Gets a color which is medium blue. + /// + public static SplatColor MediumBlue => KnownColors.FromKnownColor(KnownColor.MediumBlue); + + /// + /// Gets a color which is medium orchid. + /// + public static SplatColor MediumOrchid => KnownColors.FromKnownColor(KnownColor.MediumOrchid); + + /// + /// Gets a color which is medium purple. + /// + public static SplatColor MediumPurple => KnownColors.FromKnownColor(KnownColor.MediumPurple); + + /// + /// Gets a color which is medium sea green. + /// + public static SplatColor MediumSeaGreen => KnownColors.FromKnownColor(KnownColor.MediumSeaGreen); + + /// + /// Gets a color which is medium slate blue. + /// + public static SplatColor MediumSlateBlue => KnownColors.FromKnownColor(KnownColor.MediumSlateBlue); + + /// + /// Gets a color which is medium spring green. + /// + public static SplatColor MediumSpringGreen => KnownColors.FromKnownColor(KnownColor.MediumSpringGreen); + + /// + /// Gets a color which is medium turquoise. + /// + public static SplatColor MediumTurquoise => KnownColors.FromKnownColor(KnownColor.MediumTurquoise); + + /// + /// Gets a color which is medium violet red. + /// + public static SplatColor MediumVioletRed => KnownColors.FromKnownColor(KnownColor.MediumVioletRed); + + /// + /// Gets a color which is midnight blue. + /// + public static SplatColor MidnightBlue => KnownColors.FromKnownColor(KnownColor.MidnightBlue); + + /// + /// Gets a color which is mint cream. + /// + public static SplatColor MintCream => KnownColors.FromKnownColor(KnownColor.MintCream); + + /// + /// Gets a color which is misty rose. + /// + public static SplatColor MistyRose => KnownColors.FromKnownColor(KnownColor.MistyRose); + + /// + /// Gets a color which is moccasin. + /// + public static SplatColor Moccasin => KnownColors.FromKnownColor(KnownColor.Moccasin); + + /// + /// Gets a color which is navajo white. + /// + public static SplatColor NavajoWhite => KnownColors.FromKnownColor(KnownColor.NavajoWhite); + + /// + /// Gets a color which is navy. + /// + public static SplatColor Navy => KnownColors.FromKnownColor(KnownColor.Navy); + + /// + /// Gets a color hwich is old lace. + /// + public static SplatColor OldLace => KnownColors.FromKnownColor(KnownColor.OldLace); + + /// + /// Gets a color which is olive. + /// + public static SplatColor Olive => KnownColors.FromKnownColor(KnownColor.Olive); + + /// + /// Gets a color which is olive drab. + /// + public static SplatColor OliveDrab => KnownColors.FromKnownColor(KnownColor.OliveDrab); + + /// + /// Gets a color which is orange. + /// + public static SplatColor Orange => KnownColors.FromKnownColor(KnownColor.Orange); + + /// + /// Gets a color which is orange red. + /// + public static SplatColor OrangeRed => KnownColors.FromKnownColor(KnownColor.OrangeRed); + + /// + /// Gets a color which is orchid. + /// + public static SplatColor Orchid => KnownColors.FromKnownColor(KnownColor.Orchid); + + /// + /// Gets a color which is pale golden rod. + /// + public static SplatColor PaleGoldenrod => KnownColors.FromKnownColor(KnownColor.PaleGoldenrod); + + /// + /// Gets a color which is pale green. + /// + public static SplatColor PaleGreen => KnownColors.FromKnownColor(KnownColor.PaleGreen); + + /// + /// Gets a color which is pale turquoise. + /// + public static SplatColor PaleTurquoise => KnownColors.FromKnownColor(KnownColor.PaleTurquoise); + + /// + /// Gets a color which is pale violet red. + /// + public static SplatColor PaleVioletRed => KnownColors.FromKnownColor(KnownColor.PaleVioletRed); + + /// + /// Gets a color which is papaya whip. + /// + public static SplatColor PapayaWhip => KnownColors.FromKnownColor(KnownColor.PapayaWhip); + + /// + /// Gets a color which is peach puff. + /// + public static SplatColor PeachPuff => KnownColors.FromKnownColor(KnownColor.PeachPuff); + + /// + /// Gets a color which is peru. + /// + public static SplatColor Peru => KnownColors.FromKnownColor(KnownColor.Peru); + + /// + /// Gets a color which is pink. + /// + public static SplatColor Pink => KnownColors.FromKnownColor(KnownColor.Pink); + + /// + /// Gets a color which is plum. + /// + public static SplatColor Plum => KnownColors.FromKnownColor(KnownColor.Plum); + + /// + /// Gets a color which is powder blue. + /// + public static SplatColor PowderBlue => KnownColors.FromKnownColor(KnownColor.PowderBlue); + + /// + /// Gets a color which is purple. + /// + public static SplatColor Purple => KnownColors.FromKnownColor(KnownColor.Purple); + + /// + /// Gets a color which is red. + /// + public static SplatColor Red => KnownColors.FromKnownColor(KnownColor.Red); + + /// + /// Gets a color which is rosy brown. + /// + public static SplatColor RosyBrown => KnownColors.FromKnownColor(KnownColor.RosyBrown); + + /// + /// Gets a color which is royal blue. + /// + public static SplatColor RoyalBlue => KnownColors.FromKnownColor(KnownColor.RoyalBlue); + + /// + /// Gets a color which is saddle brown. + /// + public static SplatColor SaddleBrown => KnownColors.FromKnownColor(KnownColor.SaddleBrown); + + /// + /// Gets a color which is salmon. + /// + public static SplatColor Salmon => KnownColors.FromKnownColor(KnownColor.Salmon); + + /// + /// Gets a color which is sandy brown. + /// + public static SplatColor SandyBrown => KnownColors.FromKnownColor(KnownColor.SandyBrown); + + /// + /// Gets a color which is sea green. + /// + public static SplatColor SeaGreen => KnownColors.FromKnownColor(KnownColor.SeaGreen); + + /// + /// Gets a color which is sea shell. + /// + public static SplatColor SeaShell => KnownColors.FromKnownColor(KnownColor.SeaShell); + + /// + /// Gets a color which is sienna. + /// + public static SplatColor Sienna => KnownColors.FromKnownColor(KnownColor.Sienna); + + /// + /// Gets a color which is silver. + /// + public static SplatColor Silver => KnownColors.FromKnownColor(KnownColor.Silver); + + /// + /// Gets a color which is sky blue. + /// + public static SplatColor SkyBlue => KnownColors.FromKnownColor(KnownColor.SkyBlue); + + /// + /// Gets a color which is slate blue. + /// + public static SplatColor SlateBlue => KnownColors.FromKnownColor(KnownColor.SlateBlue); + + /// + /// Gets a color which is slate gray. + /// + public static SplatColor SlateGray => KnownColors.FromKnownColor(KnownColor.SlateGray); + + /// + /// Gets a color which is snow. + /// + public static SplatColor Snow => KnownColors.FromKnownColor(KnownColor.Snow); + + /// + /// Gets a color which is spring green. + /// + public static SplatColor SpringGreen => KnownColors.FromKnownColor(KnownColor.SpringGreen); + + /// + /// Gets a color which is steel blue. + /// + public static SplatColor SteelBlue => KnownColors.FromKnownColor(KnownColor.SteelBlue); + + /// + /// Gets a color which is tan. + /// + public static SplatColor Tan => KnownColors.FromKnownColor(KnownColor.Tan); + + /// + /// Gets a color which is teal. + /// + public static SplatColor Teal => KnownColors.FromKnownColor(KnownColor.Teal); + + /// + /// Gets a color which is thistle. + /// + public static SplatColor Thistle => KnownColors.FromKnownColor(KnownColor.Thistle); + + /// + /// Gets a color which is tomato. + /// + public static SplatColor Tomato => KnownColors.FromKnownColor(KnownColor.Tomato); + + /// + /// Gets a color which is turquoise. + /// + public static SplatColor Turquoise => KnownColors.FromKnownColor(KnownColor.Turquoise); + + /// + /// Gets a color which is violet. + /// + public static SplatColor Violet => KnownColors.FromKnownColor(KnownColor.Violet); + + /// + /// Gets a color which is wheat. + /// + public static SplatColor Wheat => KnownColors.FromKnownColor(KnownColor.Wheat); + + /// + /// Gets a color which is white. + /// + public static SplatColor White => KnownColors.FromKnownColor(KnownColor.White); + + /// + /// Gets a color which is white smoke. + /// + public static SplatColor WhiteSmoke => KnownColors.FromKnownColor(KnownColor.WhiteSmoke); + + /// + /// Gets a color which is yellow. + /// + public static SplatColor Yellow => KnownColors.FromKnownColor(KnownColor.Yellow); + + /// + /// Gets a color which is yellow green. + /// + public static SplatColor YellowGreen => KnownColors.FromKnownColor(KnownColor.YellowGreen); } diff --git a/src/Splat.Drawing/Colors/SplatColor.cs b/src/Splat.Drawing/Colors/SplatColor.cs index c3739089a..ee02347dd 100644 --- a/src/Splat.Drawing/Colors/SplatColor.cs +++ b/src/Splat.Drawing/Colors/SplatColor.cs @@ -4,478 +4,476 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.Serialization; -namespace Splat +namespace Splat; + +/// +/// A platform independent color structure. +/// +[DataContract] +public partial struct SplatColor : IEquatable { + // Private transparency (A) and R,G,B fields. + private uint _value; + + private short _state; + private short _knownColor; + + // #if ONLY_1_1 + // Mono bug #324144 is holding this change + // MS 1.1 requires this member to be present for serialization (not so in 2.0) + // however it's bad to keep a string (reference) in a struct + private string _name; + + internal SplatColor(uint value, short state, short knownColor, string name) + { + _value = value; + _state = state; + _knownColor = knownColor; + _name = name; + } + + // The specs also indicate that all three of these properties are true + // if created with FromKnownColor or FromNamedColor, false otherwise (FromARGB). + // Per Microsoft and ECMA specs these varibles are set by which constructor is used, not by their values. + [Flags] + internal enum ColorType : short + { + Empty = 0, + Known = 1, + ARGB = 2, + Named = 4, + System = 8, + } + /// - /// A platform independent color structure. + /// Gets a full empty which is fully transparent. /// - [DataContract] - public partial struct SplatColor : IEquatable - { - // Private transparency (A) and R,G,B fields. - private uint _value; + public static SplatColor Empty { get; } - private short _state; - private short _knownColor; + /// + /// Gets a value indicating whether the current color is transparent black. Eg where R,G,B,A == 0. + /// + public bool IsEmpty => _state == (short)ColorType.Empty; - // #if ONLY_1_1 - // Mono bug #324144 is holding this change - // MS 1.1 requires this member to be present for serialization (not so in 2.0) - // however it's bad to keep a string (reference) in a struct - private string _name; + /// + /// Gets the alpha component of the color. + /// + public byte A => (byte)(Value >> 24); - internal SplatColor(uint value, short state, short knownColor, string name) - { - _value = value; - _state = state; - _knownColor = knownColor; - _name = name; - } + /// + /// Gets the red component of the color. + /// + public byte R => (byte)(Value >> 16); - // The specs also indicate that all three of these properties are true - // if created with FromKnownColor or FromNamedColor, false otherwise (FromARGB). - // Per Microsoft and ECMA specs these varibles are set by which constructor is used, not by their values. - [Flags] - internal enum ColorType : short - { - Empty = 0, - Known = 1, - ARGB = 2, - Named = 4, - System = 8 - } + /// + /// Gets the green component of the color. + /// + public byte G => (byte)(Value >> 8); + + /// + /// Gets the blue component of the color. + /// + public byte B => (byte)Value; - /// - /// Gets a full empty which is fully transparent. - /// - public static SplatColor Empty { get; } - - /// - /// Gets a value indicating whether the current color is transparent black. Eg where R,G,B,A == 0. - /// - public bool IsEmpty => _state == (short)ColorType.Empty; - - /// - /// Gets the alpha component of the color. - /// - public byte A => (byte)(Value >> 24); - - /// - /// Gets the red component of the color. - /// - public byte R => (byte)(Value >> 16); - - /// - /// Gets the green component of the color. - /// - public byte G => (byte)(Value >> 8); - - /// - /// Gets the blue component of the color. - /// - public byte B => (byte)Value; - - /// - /// Gets the name of the color if one is known. Otherwise will be the hex value. - /// - public string Name + /// + /// Gets the name of the color if one is known. Otherwise will be the hex value. + /// + public string Name + { + get { - get - { #if NET_2_0_ONCE_MONO_BUG_324144_IS_FIXED - if (IsNamedColor) - return KnownColors.GetName (knownColor); - else - return String.Format ("{0:x}", ToArgb ()); + if (IsNamedColor) + return KnownColors.GetName (knownColor); + else + return String.Format ("{0:x}", ToArgb ()); #else - // name is required for serialization under 1.x, but not under 2.0 - if (_name is null) + // name is required for serialization under 1.x, but not under 2.0 + if (_name is null) + { + // Can happen with stuff deserialized from MS + if (IsNamedColor) + { + _name = KnownColors.GetName(_knownColor); + } + else { - // Can happen with stuff deserialized from MS - if (IsNamedColor) - { - _name = KnownColors.GetName(_knownColor); - } - else - { - _name = $"{ToArgb():x}"; - } + _name = $"{ToArgb():x}"; } + } - return _name; + return _name; #endif - } } + } - /// - /// Gets a value indicating whether the color is part of the group. - /// - public bool IsKnownColor => (_state & ((short)ColorType.Known)) != 0; + /// + /// Gets a value indicating whether the color is part of the group. + /// + public bool IsKnownColor => (_state & ((short)ColorType.Known)) != 0; - /// - /// Gets a value indicating whether the color is part of the group. - /// - public bool IsSystemColor => (_state & ((short)ColorType.System)) != 0; + /// + /// Gets a value indicating whether the color is part of the group. + /// + public bool IsSystemColor => (_state & ((short)ColorType.System)) != 0; - /// - /// Gets a value indicating whether the color is par tof the or groups. - /// - public bool IsNamedColor => (_state & (short)(ColorType.Known | ColorType.Named)) != 0; + /// + /// Gets a value indicating whether the color is par tof the or groups. + /// + public bool IsNamedColor => (_state & (short)(ColorType.Known | ColorType.Named)) != 0; #if TARGET_JVM - /// - /// Gets the java native object of the color. - /// - internal java.awt.SplatColor NativeObject => return new java.awt.SplatColor (R, G, B, A); + /// + /// Gets the java native object of the color. + /// + internal java.awt.SplatColor NativeObject => return new java.awt.SplatColor (R, G, B, A); #endif - /// - /// Gets or sets the value of the color. - /// - [DataMember] - internal uint Value + /// + /// Gets or sets the value of the color. + /// + [DataMember] + internal uint Value + { + get { - get + // Optimization for known colors that were deserialized + // from an MS serialized stream. + if (_value == 0 && IsKnownColor) { - // Optimization for known colors that were deserialized - // from an MS serialized stream. - if (_value == 0 && IsKnownColor) - { - _value = KnownColors.FromKnownColor((KnownColor)_knownColor).ToArgb() & 0xFFFFFFFF; - } - - return _value; + _value = KnownColors.FromKnownColor((KnownColor)_knownColor).ToArgb() & 0xFFFFFFFF; } - set => _value = value; + return _value; } - /// - /// Compares two SplatColor references and determines if they are equivalent based on their A,R,G,B values. - /// - /// The first SplatColor to compare. - /// The second SplatColor to compare. - /// If they are equivalent to each other. - public static bool operator ==(SplatColor left, SplatColor right) => - left.Equals(right); - - /// - /// Compares two SplatColor references and determines if they are not equivalent based on their A,R,G,B values. - /// - /// The first SplatColor to compare. - /// The second SplatColor to compare. - /// If they are not equivalent to each other. - public static bool operator !=(SplatColor left, SplatColor right) => - !left.Equals(right); - - /// - /// Creates a SplatColor from the RGB values. - /// The alpha will be set to 255 for full alpha. - /// - /// The red channel of the color. - /// The green channel of the color. - /// The blue channel of the color. - /// A splat color from the specified channels. - public static SplatColor FromArgb(int red, int green, int blue) - { - return FromArgb(255, red, green, blue); - } + set => _value = value; + } - /// - /// Creates a SplatColor from the RGB values. - /// - /// The alpha channel of the color. - /// The red channel of the color. - /// The green channel of the color. - /// The blue channel of the color. - /// A splat color from the specified channels. - public static SplatColor FromArgb(int alpha, int red, int green, int blue) - { - CheckARGBValues(alpha, red, green, blue); - var newColor = new SplatColor - { - _state = (short)ColorType.ARGB, - Value = ((uint)alpha << 24) + ((uint)red << 16) + ((uint)green << 8) + (uint)blue - }; + /// + /// Compares two SplatColor references and determines if they are equivalent based on their A,R,G,B values. + /// + /// The first SplatColor to compare. + /// The second SplatColor to compare. + /// If they are equivalent to each other. + public static bool operator ==(SplatColor left, SplatColor right) => + left.Equals(right); - return CheckIfIsKnownColor(newColor); - } + /// + /// Compares two SplatColor references and determines if they are not equivalent based on their A,R,G,B values. + /// + /// The first SplatColor to compare. + /// The second SplatColor to compare. + /// If they are not equivalent to each other. + public static bool operator !=(SplatColor left, SplatColor right) => + !left.Equals(right); - /// - /// Creates a new from another , replacing its alpha with one specified. - /// - /// The new alpha component to set for the new . - /// The base color to use for the RGB values. - /// The new . - public static SplatColor FromArgb(int alpha, SplatColor baseColor) => - FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B); - - /// - /// Creates a new from the specified int based ARGB value. - /// - /// The int containing the ARGB values. - /// The new . - public static SplatColor FromArgb(uint argb) => - FromArgb((int)((argb >> 24) & 0x0FF), (int)((argb >> 16) & 0x0FF), (int)((argb >> 8) & 0x0FF), (int)(argb & 0x0FF)); - - /// - /// Gets a SplatColor from a value. - /// - /// The color to generate. - /// The generated SplatValue. - public static SplatColor FromKnownColor(KnownColor color) + /// + /// Creates a SplatColor from the RGB values. + /// The alpha will be set to 255 for full alpha. + /// + /// The red channel of the color. + /// The green channel of the color. + /// The blue channel of the color. + /// A splat color from the specified channels. + public static SplatColor FromArgb(int red, int green, int blue) + { + return FromArgb(255, red, green, blue); + } + + /// + /// Creates a SplatColor from the RGB values. + /// + /// The alpha channel of the color. + /// The red channel of the color. + /// The green channel of the color. + /// The blue channel of the color. + /// A splat color from the specified channels. + public static SplatColor FromArgb(int alpha, int red, int green, int blue) + { + CheckARGBValues(alpha, red, green, blue); + var newColor = new SplatColor { - short n = (short)color; - SplatColor c; - if ((n <= 0) || (n >= KnownColors.ArgbValues.Length)) - { - // This is what it returns! - c = SplatColor.Empty; - c._state |= (short)ColorType.Named; - } - else - { - c = SplatColor.Empty; - c._state = (short)(ColorType.ARGB | ColorType.Known | ColorType.Named); - if ((n < 27) || (n > 169)) - { - c._state |= (short)ColorType.System; - } + _state = (short)ColorType.ARGB, + Value = ((uint)alpha << 24) + ((uint)red << 16) + ((uint)green << 8) + (uint)blue, + }; - c.Value = KnownColors.ArgbValues[n]; - } + return CheckIfIsKnownColor(newColor); + } - c._knownColor = n; - return c; - } + /// + /// Creates a new from another , replacing its alpha with one specified. + /// + /// The new alpha component to set for the new . + /// The base color to use for the RGB values. + /// The new . + public static SplatColor FromArgb(int alpha, SplatColor baseColor) => + FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B); + + /// + /// Creates a new from the specified int based ARGB value. + /// + /// The int containing the ARGB values. + /// The new . + public static SplatColor FromArgb(uint argb) => + FromArgb((int)((argb >> 24) & 0x0FF), (int)((argb >> 16) & 0x0FF), (int)((argb >> 8) & 0x0FF), (int)(argb & 0x0FF)); - /// - /// Gets a SplatColor from a name. - /// - /// The name of the color to generate. - /// The generated SplatValue. - public static SplatColor FromName(string name) + /// + /// Gets a SplatColor from a value. + /// + /// The color to generate. + /// The generated SplatValue. + public static SplatColor FromKnownColor(KnownColor color) + { + var n = (short)color; + SplatColor c; + if ((n <= 0) || (n >= KnownColors.ArgbValues.Length)) + { + // This is what it returns! + c = SplatColor.Empty; + c._state |= (short)ColorType.Named; + } + else { - try + c = SplatColor.Empty; + c._state = (short)(ColorType.ARGB | ColorType.Known | ColorType.Named); + if ((n < 27) || (n > 169)) { - KnownColor kc = (KnownColor)Enum.Parse(typeof(KnownColor), name, true); - return FromKnownColor(kc); + c._state |= (short)ColorType.System; } - catch (Exception ex) - { - LogHost.Default.Debug(ex, "Unable to parse the known colour name."); - // This is what it returns! - var d = SplatColor.Empty; - d._name = name; - d._state |= (short)ColorType.Named; - return d; - } + c.Value = KnownColors.ArgbValues[n]; } - /// - /// Gets the brightness of the color. - /// - /// The brightness of the value between 0 and 1. - public float GetBrightness() + c._knownColor = n; + return c; + } + + /// + /// Gets a SplatColor from a name. + /// + /// The name of the color to generate. + /// The generated SplatValue. + public static SplatColor FromName(string name) + { + try { - byte minval = Math.Min(R, Math.Min(G, B)); - byte maxval = Math.Max(R, Math.Max(G, B)); + KnownColor kc = (KnownColor)Enum.Parse(typeof(KnownColor), name, true); + return FromKnownColor(kc); + } + catch (Exception ex) + { + LogHost.Default.Debug(ex, "Unable to parse the known colour name."); - return (float)(maxval + minval) / 510; + // This is what it returns! + var d = SplatColor.Empty; + d._name = name; + d._state |= (short)ColorType.Named; + return d; } + } - /// - /// Gets the saturation of the color. - /// - /// The saturation of the value between 0 and 1. - public float GetSaturation() - { - byte minval = Math.Min(R, Math.Min(G, B)); - byte maxval = Math.Max(R, Math.Max(G, B)); + /// + /// Gets the brightness of the color. + /// + /// The brightness of the value between 0 and 1. + public float GetBrightness() + { + var minval = Math.Min(R, Math.Min(G, B)); + var maxval = Math.Max(R, Math.Max(G, B)); - if (maxval == minval) - { - return 0.0f; - } + return (float)(maxval + minval) / 510; + } - int sum = maxval + minval; - if (sum > 255) - { - sum = 510 - sum; - } + /// + /// Gets the saturation of the color. + /// + /// The saturation of the value between 0 and 1. + public float GetSaturation() + { + var minval = Math.Min(R, Math.Min(G, B)); + var maxval = Math.Max(R, Math.Max(G, B)); - return (float)(maxval - minval) / sum; + if (maxval == minval) + { + return 0.0f; } - /// - /// Gets the integer value of the color. - /// - /// The integer value. - public uint ToArgb() => Value; - - /// - /// Gets the hue of the color. - /// - /// The hue component of the color. - public float GetHue() + var sum = maxval + minval; + if (sum > 255) { - int r = R; - int g = G; - int b = B; - byte minval = (byte)Math.Min(r, Math.Min(g, b)); - byte maxval = (byte)Math.Max(r, Math.Max(g, b)); - - if (maxval == minval) - { - return 0.0f; - } + sum = 510 - sum; + } - float diff = maxval - minval; - float rnorm = (maxval - r) / diff; - float gnorm = (maxval - g) / diff; - float bnorm = (maxval - b) / diff; + return (float)(maxval - minval) / sum; + } - float hue = 0.0f; - if (r == maxval) - { - hue = 60.0f * (6.0f + bnorm - gnorm); - } + /// + /// Gets the integer value of the color. + /// + /// The integer value. + public uint ToArgb() => Value; - if (g == maxval) - { - hue = 60.0f * (2.0f + rnorm - bnorm); - } + /// + /// Gets the hue of the color. + /// + /// The hue component of the color. + public float GetHue() + { + int r = R; + int g = G; + int b = B; + var minval = (byte)Math.Min(r, Math.Min(g, b)); + var maxval = (byte)Math.Max(r, Math.Max(g, b)); - if (b == maxval) - { - hue = 60.0f * (4.0f + gnorm - rnorm); - } + if (maxval == minval) + { + return 0.0f; + } - if (hue > 360.0f) - { - hue -= 360.0f; - } + float diff = maxval - minval; + var rnorm = (maxval - r) / diff; + var gnorm = (maxval - g) / diff; + var bnorm = (maxval - b) / diff; - return hue; + var hue = 0.0f; + if (r == maxval) + { + hue = 60.0f * (6.0f + bnorm - gnorm); } - /// Gets the of the current value (if one is available). - /// Returns the KnownColor enum value for this color, 0 if is not known. - public KnownColor ToKnownColor() => (KnownColor)_knownColor; + if (g == maxval) + { + hue = 60.0f * (2.0f + rnorm - bnorm); + } - /// - public override bool Equals(object? obj) + if (b == maxval) { - if (obj is SplatColor splatColor) - { - return Equals(splatColor); - } + hue = 60.0f * (4.0f + gnorm - rnorm); + } - return false; + if (hue > 360.0f) + { + hue -= 360.0f; } - /// - public bool Equals(SplatColor other) => - A == other.A && R == other.R && G == other.G && B == other.B; + return hue; + } - /// - public override int GetHashCode() - { - int hc = (int)(Value ^ (Value >> 32) ^ _state ^ (_knownColor >> 16)); - if (IsNamedColor) - { - hc ^= StringComparer.OrdinalIgnoreCase.GetHashCode(Name); - } + /// Gets the of the current value (if one is available). + /// Returns the KnownColor enum value for this color, 0 if is not known. + public KnownColor ToKnownColor() => (KnownColor)_knownColor; - return hc; + /// + public override bool Equals(object? obj) + { + if (obj is SplatColor splatColor) + { + return Equals(splatColor); } - /// - public override string ToString() - { - if (IsEmpty) - { - return "SplatColor [Empty]"; - } + return false; + } - // Use the property here, not the field. - if (IsNamedColor) - { - return "SplatColor [" + Name + "]"; - } + /// + public bool Equals(SplatColor other) => + A == other.A && R == other.R && G == other.G && B == other.B; - return $"SplatColor [A={A}, R={R}, G={G}, B={B}]"; + /// + public override int GetHashCode() + { + var hc = (int)(Value ^ (Value >> 32) ^ _state ^ (_knownColor >> 16)); + if (IsNamedColor) + { + hc ^= StringComparer.OrdinalIgnoreCase.GetHashCode(Name); } -#if TARGET_JVM - internal static SplatColor FromArgbNamed (int alpha, int red, int green, int blue, string name, KnownColor knownColor) - { - SplatColor color = FromArgb (alpha, red, green, blue); - color.state = (short) (ColorType.Known|ColorType.Named); - color.name = KnownColors.GetName (knownColor); - color.knownColor = (short) knownColor; - return color; + return hc; } - internal static SplatColor FromArgbSystem (int alpha, int red, int green, int blue, string name, KnownColor knownColor) + /// + public override string ToString() { - SplatColor color = FromArgbNamed (alpha, red, green, blue, name, knownColor); - color.state |= (short) ColorType.System; - return color; + if (IsEmpty) + { + return "SplatColor [Empty]"; + } + + // Use the property here, not the field. + if (IsNamedColor) + { + return "SplatColor [" + Name + "]"; + } + + return $"SplatColor [A={A}, R={R}, G={G}, B={B}]"; } + +#if TARGET_JVM +internal static SplatColor FromArgbNamed (int alpha, int red, int green, int blue, string name, KnownColor knownColor) +{ + SplatColor color = FromArgb (alpha, red, green, blue); + color.state = (short) (ColorType.Known|ColorType.Named); + color.name = KnownColors.GetName (knownColor); + color.knownColor = (short) knownColor; + return color; +} + +internal static SplatColor FromArgbSystem (int alpha, int red, int green, int blue, string name, KnownColor knownColor) +{ + SplatColor color = FromArgbNamed (alpha, red, green, blue, name, knownColor); + color.state |= (short) ColorType.System; + return color; +} #endif - private static void CheckRGBValues(int red, int green, int blue) + private static void CheckRGBValues(int red, int green, int blue) + { + if ((red > 255) || (red < 0)) { - if ((red > 255) || (red < 0)) - { - throw CreateColorArgumentException(red, "red"); - } + throw CreateColorArgumentException(red, "red"); + } - if ((green > 255) || (green < 0)) - { - throw CreateColorArgumentException(green, "green"); - } + if ((green > 255) || (green < 0)) + { + throw CreateColorArgumentException(green, "green"); + } - if ((blue > 255) || (blue < 0)) - { - throw CreateColorArgumentException(blue, "blue"); - } + if ((blue > 255) || (blue < 0)) + { + throw CreateColorArgumentException(blue, "blue"); } + } - private static ArgumentException CreateColorArgumentException(int value, string color) => - new($"'{value}' is not a valid value for '{color}'. '{color}' should be greater or equal to 0 and less than or equal to 255."); + private static ArgumentException CreateColorArgumentException(int value, string color) => + new($"'{value}' is not a valid value for '{color}'. '{color}' should be greater or equal to 0 and less than or equal to 255."); - private static void CheckARGBValues(int alpha, int red, int green, int blue) + private static void CheckARGBValues(int alpha, int red, int green, int blue) + { + if ((alpha > 255) || (alpha < 0)) { - if ((alpha > 255) || (alpha < 0)) - { - throw CreateColorArgumentException(alpha, "alpha"); - } - - CheckRGBValues(red, green, blue); + throw CreateColorArgumentException(alpha, "alpha"); } - private static SplatColor CheckIfIsKnownColor(SplatColor splatColor) + CheckRGBValues(red, green, blue); + } + + private static SplatColor CheckIfIsKnownColor(SplatColor splatColor) + { + try { - try - { - var index = Array.IndexOf(KnownColors.ArgbValues, splatColor.Value); - if (index >= 0) - { - var knownColorLookup = (KnownColor)index; - return FromKnownColor(knownColorLookup); - } - } - catch + var index = Array.IndexOf(KnownColors.ArgbValues, splatColor.Value); + if (index >= 0) { + var knownColorLookup = (KnownColor)index; + return FromKnownColor(knownColorLookup); } - - return splatColor; } + catch + { + } + + return splatColor; } } diff --git a/src/Splat.Drawing/DefaultPlatformModeDetector.cs b/src/Splat.Drawing/DefaultPlatformModeDetector.cs index 92199765d..bf697e10e 100644 --- a/src/Splat.Drawing/DefaultPlatformModeDetector.cs +++ b/src/Splat.Drawing/DefaultPlatformModeDetector.cs @@ -11,88 +11,88 @@ #if NETFX_CORE using System.Threading; using System.Threading.Tasks; + using Windows.ApplicationModel; #endif -namespace Splat +namespace Splat; + +/// +/// Detects if we are in design mode or unit test mode based on the current platform. +/// +public class DefaultPlatformModeDetector : IPlatformModeDetector { - /// - /// Detects if we are in design mode or unit test mode based on the current platform. - /// - public class DefaultPlatformModeDetector : IPlatformModeDetector - { #if !NETFX_CORE - private const string XamlDesignPropertiesType = "System.ComponentModel.DesignerProperties, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"; - private const string XamlControlBorderType = "System.Windows.Controls.Border, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"; - private const string XamlDesignPropertiesDesignModeMethodName = "GetIsInDesignMode"; - private const string WpfDesignerPropertiesType = "System.ComponentModel.DesignerProperties, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; - private const string WpfDesignerPropertiesDesignModeMethod = "GetIsInDesignMode"; - private const string WpfDependencyPropertyType = "System.Windows.DependencyObject, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; - private const string WinFormsDesignerPropertiesType = "Windows.ApplicationModel.DesignMode, Windows, ContentType=WindowsRuntime"; - private const string WinFormsDesignerPropertiesDesignModeMethod = "DesignModeEnabled"; + private const string XamlDesignPropertiesType = "System.ComponentModel.DesignerProperties, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"; + private const string XamlControlBorderType = "System.Windows.Controls.Border, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"; + private const string XamlDesignPropertiesDesignModeMethodName = "GetIsInDesignMode"; + private const string WpfDesignerPropertiesType = "System.ComponentModel.DesignerProperties, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; + private const string WpfDesignerPropertiesDesignModeMethod = "GetIsInDesignMode"; + private const string WpfDependencyPropertyType = "System.Windows.DependencyObject, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; + private const string WinFormsDesignerPropertiesType = "Windows.ApplicationModel.DesignMode, Windows, ContentType=WindowsRuntime"; + private const string WinFormsDesignerPropertiesDesignModeMethod = "DesignModeEnabled"; - private static bool? _cachedInDesignModeResult; + private static bool? _cachedInDesignModeResult; #endif - /// - public bool? InDesignMode() - { + /// + public bool? InDesignMode() + { #if NETFX_CORE - return DesignMode.DesignModeEnabled; + return DesignMode.DesignModeEnabled; #else - if (_cachedInDesignModeResult.HasValue) - { - return _cachedInDesignModeResult.Value; - } + if (_cachedInDesignModeResult.HasValue) + { + return _cachedInDesignModeResult.Value; + } - // Check Silverlight / WP8 Design Mode - var type = Type.GetType(XamlDesignPropertiesType, false); - if (type is not null) - { - var mInfo = type.GetMethod(XamlDesignPropertiesDesignModeMethodName); - var dependencyObject = Type.GetType(XamlControlBorderType, false); + // Check Silverlight / WP8 Design Mode + var type = Type.GetType(XamlDesignPropertiesType, false); + if (type is not null) + { + var mInfo = type.GetMethod(XamlDesignPropertiesDesignModeMethodName); + var dependencyObject = Type.GetType(XamlControlBorderType, false); - if (mInfo is not null && dependencyObject is not null) - { - _cachedInDesignModeResult = (bool)(mInfo.Invoke(null, new[] { Activator.CreateInstance(dependencyObject) }) ?? false); - } - } - else if ((type = Type.GetType(WpfDesignerPropertiesType, false)) is not null) + if (mInfo is not null && dependencyObject is not null) { - // loaded the assembly, could be .net - var mInfo = type.GetMethod(WpfDesignerPropertiesDesignModeMethod); - var dependencyObject = Type.GetType(WpfDependencyPropertyType, false); - if (mInfo is not null && dependencyObject is not null) - { - _cachedInDesignModeResult = (bool)(mInfo.Invoke(null, new[] { Activator.CreateInstance(dependencyObject) }) ?? false); - } + _cachedInDesignModeResult = (bool)(mInfo.Invoke(null, new[] { Activator.CreateInstance(dependencyObject) }) ?? false); } - else if ((type = Type.GetType(WinFormsDesignerPropertiesType, false)) is not null) + } + else if ((type = Type.GetType(WpfDesignerPropertiesType, false)) is not null) + { + // loaded the assembly, could be .net + var mInfo = type.GetMethod(WpfDesignerPropertiesDesignModeMethod); + var dependencyObject = Type.GetType(WpfDependencyPropertyType, false); + if (mInfo is not null && dependencyObject is not null) { - // check WinRT next - _cachedInDesignModeResult = (bool)(type.GetProperty(WinFormsDesignerPropertiesDesignModeMethod)?.GetMethod?.Invoke(null, null) ?? false); + _cachedInDesignModeResult = (bool)(mInfo.Invoke(null, new[] { Activator.CreateInstance(dependencyObject) }) ?? false); } - else + } + else if ((type = Type.GetType(WinFormsDesignerPropertiesType, false)) is not null) + { + // check WinRT next + _cachedInDesignModeResult = (bool)(type.GetProperty(WinFormsDesignerPropertiesDesignModeMethod)?.GetMethod?.Invoke(null, null) ?? false); + } + else + { + var designEnvironments = new[] { "BLEND.EXE", "XDESPROC.EXE" }; + + var entry = Assembly.GetEntryAssembly(); + if (entry is not null) { - var designEnvironments = new[] { "BLEND.EXE", "XDESPROC.EXE" }; + var exeName = new FileInfo(entry.Location).Name; - var entry = Assembly.GetEntryAssembly(); - if (entry is not null) + if (designEnvironments.Any(x => + x.IndexOf(exeName, StringComparison.InvariantCultureIgnoreCase) != -1)) { - var exeName = new FileInfo(entry.Location).Name; - - if (designEnvironments.Any(x => - x.IndexOf(exeName, StringComparison.InvariantCultureIgnoreCase) != -1)) - { - _cachedInDesignModeResult = true; - } + _cachedInDesignModeResult = true; } } + } - _cachedInDesignModeResult = false; + _cachedInDesignModeResult = false; - return _cachedInDesignModeResult; + return _cachedInDesignModeResult; #endif - } } } diff --git a/src/Splat.Drawing/IPlatformModeDetector.cs b/src/Splat.Drawing/IPlatformModeDetector.cs index 522e66a42..1927961bb 100644 --- a/src/Splat.Drawing/IPlatformModeDetector.cs +++ b/src/Splat.Drawing/IPlatformModeDetector.cs @@ -3,17 +3,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// Detects properties about the current platform. +/// +public interface IPlatformModeDetector { /// - /// Detects properties about the current platform. + /// Gets a value indicating whether the current library or application is running in a GUI design mode tool. /// - public interface IPlatformModeDetector - { - /// - /// Gets a value indicating whether the current library or application is running in a GUI design mode tool. - /// - /// If we are currently running in design mode. - bool? InDesignMode(); - } + /// If we are currently running in design mode. + bool? InDesignMode(); } diff --git a/src/Splat.Drawing/PlatformModeDetector.cs b/src/Splat.Drawing/PlatformModeDetector.cs index 7105594a4..2755b569f 100644 --- a/src/Splat.Drawing/PlatformModeDetector.cs +++ b/src/Splat.Drawing/PlatformModeDetector.cs @@ -3,59 +3,58 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// Detects various properties about a platform. +/// +public static class PlatformModeDetector { + private static bool? _cachedInDesignModeResult; + /// - /// Detects various properties about a platform. + /// Initializes static members of the class. /// - public static class PlatformModeDetector + static PlatformModeDetector() { - private static bool? _cachedInDesignModeResult; + Current = new DefaultPlatformModeDetector(); + } - /// - /// Initializes static members of the class. - /// - static PlatformModeDetector() - { - Current = new DefaultPlatformModeDetector(); - } + /// + /// Gets or sets the current mode detector set. + /// + private static IPlatformModeDetector Current { get; set; } - /// - /// Gets or sets the current mode detector set. - /// - private static IPlatformModeDetector Current { get; set; } + /// + /// Overrides the mode detector with one of your own provided ones. + /// + /// The mode detector to use. + public static void OverrideModeDetector(IPlatformModeDetector modeDetector) + { + Current = modeDetector; + _cachedInDesignModeResult = null; + } - /// - /// Overrides the mode detector with one of your own provided ones. - /// - /// The mode detector to use. - public static void OverrideModeDetector(IPlatformModeDetector modeDetector) + /// + /// Gets a value indicating whether we are currently running from within a GUI design editor. + /// + /// If we are currently running from design mode. + public static bool InDesignMode() + { + if (_cachedInDesignModeResult.HasValue) { - Current = modeDetector; - _cachedInDesignModeResult = null; + return _cachedInDesignModeResult.Value; } - /// - /// Gets a value indicating whether we are currently running from within a GUI design editor. - /// - /// If we are currently running from design mode. - public static bool InDesignMode() + if (Current is not null) { + _cachedInDesignModeResult = Current.InDesignMode(); if (_cachedInDesignModeResult.HasValue) { return _cachedInDesignModeResult.Value; } - - if (Current is not null) - { - _cachedInDesignModeResult = Current.InDesignMode(); - if (_cachedInDesignModeResult.HasValue) - { - return _cachedInDesignModeResult.Value; - } - } - - return _cachedInDesignModeResult.GetValueOrDefault(); } + + return _cachedInDesignModeResult.GetValueOrDefault(); } } diff --git a/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs b/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs index b75699b19..c32e3644b 100644 --- a/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs +++ b/src/Splat.Drawing/Platforms/Android/Bitmaps/AndroidBitmap.cs @@ -7,53 +7,53 @@ using System.IO; using System.Threading; using System.Threading.Tasks; + using Android.Graphics; -namespace Splat +namespace Splat; + +/// +/// Wraps a android native bitmap into the splat . +/// +internal sealed class AndroidBitmap : IBitmap { + private Bitmap? _inner; + /// - /// Wraps a android native bitmap into the splat . + /// Initializes a new instance of the class. /// - internal sealed class AndroidBitmap : IBitmap + /// The bitmap we are wrapping. + public AndroidBitmap(Bitmap inner) { - private Bitmap? _inner; - - /// - /// Initializes a new instance of the class. - /// - /// The bitmap we are wrapping. - public AndroidBitmap(Bitmap inner) - { - _inner = inner; - } + _inner = inner; + } - /// - public float Width => _inner?.Width ?? 0; + /// + public float Width => _inner?.Width ?? 0; - /// - public float Height => _inner?.Height ?? 0; + /// + public float Height => _inner?.Height ?? 0; - /// - /// Gets the internal bitmap we are wrapping. - /// - internal Bitmap Inner => _inner ?? throw new InvalidOperationException("Attempt to access a disposed Bitmap"); + /// + /// Gets the internal bitmap we are wrapping. + /// + internal Bitmap Inner => _inner ?? throw new InvalidOperationException("Attempt to access a disposed Bitmap"); - /// - public Task Save(CompressedBitmapFormat format, float quality, Stream target) + /// + public Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + if (_inner is null) { - if (_inner is null) - { - return Task.CompletedTask; - } - - var fmt = format == CompressedBitmapFormat.Jpeg ? Bitmap.CompressFormat.Jpeg : Bitmap.CompressFormat.Png; - return Task.Run(() => _inner.Compress(fmt, (int)(quality * 100), target)); + return Task.CompletedTask; } - /// - public void Dispose() - { - Interlocked.Exchange(ref _inner, null)?.Dispose(); - } + var fmt = format == CompressedBitmapFormat.Jpeg ? Bitmap.CompressFormat.Jpeg : Bitmap.CompressFormat.Png; + return Task.Run(() => _inner.Compress(fmt, (int)(quality * 100), target)); + } + + /// + public void Dispose() + { + Interlocked.Exchange(ref _inner, null)?.Dispose(); } } diff --git a/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs index 27dbb2d4c..0027fae02 100644 --- a/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs @@ -9,63 +9,62 @@ using Android.Graphics; using Android.Graphics.Drawables; -namespace Splat +namespace Splat; + +/// +/// Extension methods to assist with dealing with Bitmaps. +/// +public static class BitmapMixins { /// - /// Extension methods to assist with dealing with Bitmaps. + /// Converts to a native type. /// - public static class BitmapMixins + /// The bitmap to convert. + /// A bitmap. + public static Drawable ToNative(this IBitmap value) { - /// - /// Converts to a native type. - /// - /// The bitmap to convert. - /// A bitmap. - public static Drawable ToNative(this IBitmap value) + if (value is null) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - if (value is AndroidBitmap androidBitmap) - { - return new BitmapDrawable(Application.Context.Resources, androidBitmap.Inner); - } - - return ((DrawableBitmap)value).Inner; + throw new System.ArgumentNullException(nameof(value)); } - /// - /// Converts a to a splat . - /// - /// The native bitmap to convert from. - /// Whether to copy the android bitmap or not. - /// A bitmap. - public static IBitmap FromNative(this Bitmap value, bool copy = false) + if (value is AndroidBitmap androidBitmap) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } + return new BitmapDrawable(Application.Context.Resources, androidBitmap.Inner); + } - if (copy) - { - var copiedBitmap = value.Copy(value.GetConfig(), true) ?? throw new InvalidOperationException("The bitmap does not have a valid reference."); - return new AndroidBitmap(copiedBitmap); - } + return ((DrawableBitmap)value).Inner; + } - return new AndroidBitmap(value); + /// + /// Converts a to a splat . + /// + /// The native bitmap to convert from. + /// Whether to copy the android bitmap or not. + /// A bitmap. + public static IBitmap FromNative(this Bitmap value, bool copy = false) + { + if (value is null) + { + throw new System.ArgumentNullException(nameof(value)); } - /// - /// Converts a to a splat . - /// - /// The native bitmap to convert from. - /// A bitmap. - public static IBitmap FromNative(this Drawable value) + if (copy) { - return new DrawableBitmap(value); + var copiedBitmap = value.Copy(value.GetConfig(), true) ?? throw new InvalidOperationException("The bitmap does not have a valid reference."); + return new AndroidBitmap(copiedBitmap); } + + return new AndroidBitmap(value); + } + + /// + /// Converts a to a splat . + /// + /// The native bitmap to convert from. + /// A bitmap. + public static IBitmap FromNative(this Drawable value) + { + return new DrawableBitmap(value); } } diff --git a/src/Splat.Drawing/Platforms/Android/Bitmaps/DrawableBitmap.cs b/src/Splat.Drawing/Platforms/Android/Bitmaps/DrawableBitmap.cs index 96d28a073..b68d4e7e9 100644 --- a/src/Splat.Drawing/Platforms/Android/Bitmaps/DrawableBitmap.cs +++ b/src/Splat.Drawing/Platforms/Android/Bitmaps/DrawableBitmap.cs @@ -7,46 +7,46 @@ using System.IO; using System.Threading; using System.Threading.Tasks; + using Android.Graphics.Drawables; -namespace Splat +namespace Splat; + +internal sealed class DrawableBitmap : IBitmap { - internal sealed class DrawableBitmap : IBitmap - { - private Drawable? _inner; + private Drawable? _inner; - /// - /// Initializes a new instance of the class. - /// - /// The drawable bitmap to wrap. - public DrawableBitmap(Drawable inner) - { - _inner = inner; - } + /// + /// Initializes a new instance of the class. + /// + /// The drawable bitmap to wrap. + public DrawableBitmap(Drawable inner) + { + _inner = inner; + } - /// - public float Width => Inner.IntrinsicWidth; + /// + public float Width => Inner.IntrinsicWidth; - /// - public float Height => Inner.IntrinsicHeight; + /// + public float Height => Inner.IntrinsicHeight; - /// - /// Gets the internal Drawable we are wrapping. - /// - internal Drawable Inner => _inner ?? throw new InvalidOperationException("Attempting to retrieve a disposed bitmap"); + /// + /// Gets the internal Drawable we are wrapping. + /// + internal Drawable Inner => _inner ?? throw new InvalidOperationException("Attempting to retrieve a disposed bitmap"); - public Task Save(CompressedBitmapFormat format, float quality, Stream target) - { - throw new NotSupportedException("You can't save resources"); - } + public Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + throw new NotSupportedException("You can't save resources"); + } - public void Dispose() + public void Dispose() + { + var disp = Interlocked.Exchange(ref _inner, null); + if (disp is not null) { - var disp = Interlocked.Exchange(ref _inner, null); - if (disp is not null) - { - disp.Dispose(); - } + disp.Dispose(); } } } diff --git a/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs index 7252fe7a1..5ff3fcfcc 100644 --- a/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs @@ -10,249 +10,249 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; + using Android.App; using Android.Graphics; -namespace Splat +namespace Splat; + +/// +/// A android based platform bitmap loader which will load our bitmaps for us. +/// +public class PlatformBitmapLoader : IBitmapLoader, IEnableLogger { + private readonly Dictionary _drawableList; + /// - /// A android based platform bitmap loader which will load our bitmaps for us. + /// Initializes a new instance of the class. /// - public class PlatformBitmapLoader : IBitmapLoader, IEnableLogger + public PlatformBitmapLoader() { - private readonly Dictionary _drawableList; + _drawableList = GetDrawableList(); + } - /// - /// Initializes a new instance of the class. - /// - public PlatformBitmapLoader() + /// + public async Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) + { + if (sourceStream is null) { - _drawableList = GetDrawableList(); + throw new ArgumentNullException(nameof(sourceStream)); } - /// - public async Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) + // this is a rough check to do with the termination check for #479 + if (sourceStream.Length < 2) { - if (sourceStream is null) - { - throw new ArgumentNullException(nameof(sourceStream)); - } - - // this is a rough check to do with the termination check for #479 - if (sourceStream.Length < 2) - { - throw new ArgumentException("The source stream is not a valid image file.", nameof(sourceStream)); - } - - if (!HasCorrectStreamEnd(sourceStream)) - { - AttemptStreamByteCorrection(sourceStream); - } - - sourceStream.Position = 0; - Bitmap? bitmap = null; - - if (desiredWidth is null || desiredHeight is null) - { - bitmap = await Task.Run(() => BitmapFactory.DecodeStream(sourceStream)).ConfigureAwait(false); - } - else - { - var opts = new BitmapFactory.Options() - { - OutWidth = (int)desiredWidth.Value, - OutHeight = (int)desiredHeight.Value, - }; + throw new ArgumentException("The source stream is not a valid image file.", nameof(sourceStream)); + } - var noPadding = new Rect(0, 0, 0, 0); - bitmap = await Task.Run(() => BitmapFactory.DecodeStream(sourceStream, noPadding, opts)).ConfigureAwait(true); - } + if (!HasCorrectStreamEnd(sourceStream)) + { + AttemptStreamByteCorrection(sourceStream); + } - if (bitmap is null) - { - throw new IOException("Failed to load bitmap from source stream"); - } + sourceStream.Position = 0; + Bitmap? bitmap = null; - return bitmap.FromNative(); + if (desiredWidth is null || desiredHeight is null) + { + bitmap = await Task.Run(() => BitmapFactory.DecodeStream(sourceStream)).ConfigureAwait(false); } - - /// - public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + else { - if (_drawableList is null) + var opts = new BitmapFactory.Options() { - throw new InvalidOperationException("No resources found in any of the drawable folders."); - } + OutWidth = (int)desiredWidth.Value, + OutHeight = (int)desiredHeight.Value, + }; - var res = Application.Context.Resources; - var theme = Application.Context.Theme; + var noPadding = new Rect(0, 0, 0, 0); + bitmap = await Task.Run(() => BitmapFactory.DecodeStream(sourceStream, noPadding, opts)).ConfigureAwait(true); + } - if (res is null) - { - throw new InvalidOperationException("No resources found in the application."); - } + if (bitmap is null) + { + throw new IOException("Failed to load bitmap from source stream"); + } - var id = default(int); - if (int.TryParse(source, out id)) - { - return Task.Run(() => GetFromDrawable(res.GetDrawable(id, theme))); - } + return bitmap.FromNative(); + } - if (_drawableList.ContainsKey(source)) - { - return Task.Run(() => GetFromDrawable(res.GetDrawable(_drawableList[source], theme))); - } + /// + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + { + if (_drawableList is null) + { + throw new InvalidOperationException("No resources found in any of the drawable folders."); + } - // 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); - if (_drawableList.ContainsKey(key)) - { - return Task.Run(() => GetFromDrawable(res.GetDrawable(_drawableList[key], theme))); - } + var res = Application.Context.Resources; + var theme = Application.Context.Theme; - throw new ArgumentException("Either pass in an integer ID cast to a string, or the name of a drawable resource"); + if (res is null) + { + throw new InvalidOperationException("No resources found in the application."); } - /// - public IBitmap? Create(float width, float height) + var id = default(int); + if (int.TryParse(source, out id)) { - var config = Bitmap.Config.Argb8888 ?? throw new InvalidOperationException("The ARGB8888 bitmap format is unavailable"); - - return Bitmap.CreateBitmap((int)width, (int)height, config)?.FromNative(); + return Task.Run(() => GetFromDrawable(res.GetDrawable(id, theme))); } - internal static Dictionary GetDrawableList(IFullLogger? log) + if (_drawableList.ContainsKey(source)) { - var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + return Task.Run(() => GetFromDrawable(res.GetDrawable(_drawableList[source], theme))); + } - return GetDrawableList(log, assemblies); + // 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); + if (_drawableList.ContainsKey(key)) + { + return Task.Run(() => GetFromDrawable(res.GetDrawable(_drawableList[key], theme))); } - private static Type[] GetTypesFromAssembly( - Assembly assembly, - IFullLogger? log) + throw new ArgumentException("Either pass in an integer ID cast to a string, or the name of a drawable resource"); + } + + /// + public IBitmap? Create(float width, float height) + { + var config = Bitmap.Config.Argb8888 ?? throw new InvalidOperationException("The ARGB8888 bitmap format is unavailable"); + + return Bitmap.CreateBitmap((int)width, (int)height, config)?.FromNative(); + } + + internal static Dictionary GetDrawableList(IFullLogger? log) + { + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + return GetDrawableList(log, assemblies); + } + + private static Type[] GetTypesFromAssembly( + Assembly assembly, + IFullLogger? log) + { + try { - try - { - return assembly.GetTypes(); - } - catch (ReflectionTypeLoadException e) + return assembly.GetTypes(); + } + catch (ReflectionTypeLoadException e) + { + // The array returned by the Types property of this exception contains a Type + // object for each type that was loaded and null for each type that could not + // be loaded, while the LoaderExceptions property contains an exception for + // each type that could not be loaded. + if (log is not null) { - // The array returned by the Types property of this exception contains a Type - // object for each type that was loaded and null for each type that could not - // be loaded, while the LoaderExceptions property contains an exception for - // each type that could not be loaded. - if (log is not null) - { - log.Warn(e, "Exception while detecting drawing types."); + log.Warn(e, "Exception while detecting drawing types."); - foreach (var loaderException in e.LoaderExceptions) + foreach (var loaderException in e.LoaderExceptions) + { + if (loaderException is null) { - if (loaderException is null) - { - continue; - } - - log.Warn(loaderException, "Inner Exception for detecting drawing types."); + continue; } - } - // null check here because mono doesn't appear to follow the MSDN documentation - // as of July 2019. - return e.Types is not null - ? e.Types.Where(x => x is not null).Select(x => x!).ToArray() - : Array.Empty(); + log.Warn(loaderException, "Inner Exception for detecting drawing types."); + } } + + // null check here because mono doesn't appear to follow the MSDN documentation + // as of July 2019. + return e.Types is not null + ? e.Types.Where(x => x is not null).Select(x => x!).ToArray() + : Array.Empty(); } + } - private static Dictionary GetDrawableList( - IFullLogger? log, - Assembly[] assemblies) + private static Dictionary GetDrawableList( + IFullLogger? log, + Assembly[] assemblies) + { + // VS2019 onward + var drawableTypes = assemblies + .AsParallel() + .SelectMany(a => GetTypesFromAssembly(a, log)) + .Where(x => x.Name.Equals("Resource", StringComparison.Ordinal) && x.GetNestedType("Drawable") is not null) + .Select(x => x.GetNestedType("Drawable")) + .Where(x => x != null) + .Select(x => x!) + .ToArray(); + + if (log?.IsDebugEnabled == true) { - // VS2019 onward - var drawableTypes = assemblies - .AsParallel() - .SelectMany(a => GetTypesFromAssembly(a, log)) - .Where(x => x.Name.Equals("Resource", StringComparison.Ordinal) && x.GetNestedType("Drawable") is not null) - .Select(x => x.GetNestedType("Drawable")) - .Where(x => x != null) - .Select(x => x!) - .ToArray(); - - if (log?.IsDebugEnabled == true) - { - var output = new StringBuilder(); - output.Append("DrawableList. Got ").Append(drawableTypes.Length).AppendLine(" types."); + var output = new StringBuilder(); + output.Append("DrawableList. Got ").Append(drawableTypes.Length).AppendLine(" types."); - foreach (var drawableType in drawableTypes) - { - output.Append("DrawableList Type: ").AppendLine(drawableType.Name); - } - - log.Debug(output.ToString()); + foreach (var drawableType in drawableTypes) + { + output.Append("DrawableList Type: ").AppendLine(drawableType.Name); } - var result = drawableTypes - .AsParallel() - .SelectMany(x => x.GetFields()) - .Where(x => x.FieldType == typeof(int) && x.IsLiteral) - .ToDictionary(k => k.Name, v => ((int?)v.GetRawConstantValue()) ?? 0); + log.Debug(output.ToString()); + } - if (log?.IsDebugEnabled == true) - { - var output = new StringBuilder(); - output.Append("DrawableList. Got ").Append(result.Count).AppendLine(" items."); + var result = drawableTypes + .AsParallel() + .SelectMany(x => x.GetFields()) + .Where(x => x.FieldType == typeof(int) && x.IsLiteral) + .ToDictionary(k => k.Name, v => ((int?)v.GetRawConstantValue()) ?? 0); - foreach (var keyValuePair in result) - { - output.Append("DrawableList Item: ").AppendLine(keyValuePair.Key); - } + if (log?.IsDebugEnabled == true) + { + var output = new StringBuilder(); + output.Append("DrawableList. Got ").Append(result.Count).AppendLine(" items."); - log.Debug(output.ToString()); + foreach (var keyValuePair in result) + { + output.Append("DrawableList Item: ").AppendLine(keyValuePair.Key); } - return result; + log.Debug(output.ToString()); } - private static IBitmap? GetFromDrawable(Android.Graphics.Drawables.Drawable? drawable) - { - return drawable is null ? null : new DrawableBitmap(drawable); - } + return result; + } - /// - /// Checks to make sure the last 2 bytes are as expected. - /// issue #479 xamarin android can throw an objectdisposedexception on stream - /// suggestion is it relates to https://forums.xamarin.com/discussion/16500/bitmap-decode-byte-array-skia-decoder-returns-false - /// and truncated jpeg\png files. - /// - /// Input image source stream. - /// Whether the termination is correct. - private static bool HasCorrectStreamEnd(Stream sourceStream) - { - // 0-based and go back 2. - sourceStream.Position = sourceStream.Length - 3; - return sourceStream.ReadByte() == 0xFF - && sourceStream.ReadByte() == 0xD9; - } + private static IBitmap? GetFromDrawable(Android.Graphics.Drawables.Drawable? drawable) + { + return drawable is null ? null : new DrawableBitmap(drawable); + } - private static Dictionary GetDrawableList() + /// + /// Checks to make sure the last 2 bytes are as expected. + /// issue #479 xamarin android can throw an objectdisposedexception on stream + /// suggestion is it relates to https://forums.xamarin.com/discussion/16500/bitmap-decode-byte-array-skia-decoder-returns-false + /// and truncated jpeg\png files. + /// + /// Input image source stream. + /// Whether the termination is correct. + private static bool HasCorrectStreamEnd(Stream sourceStream) + { + // 0-based and go back 2. + sourceStream.Position = sourceStream.Length - 3; + return sourceStream.ReadByte() == 0xFF + && sourceStream.ReadByte() == 0xD9; + } + + private static Dictionary GetDrawableList() + { + return GetDrawableList(Locator.Current.GetService()?.GetLogger(typeof(PlatformBitmapLoader))); + } + + private void AttemptStreamByteCorrection(Stream sourceStream) + { + if (!sourceStream.CanWrite) { - return GetDrawableList(Locator.Current.GetService()?.GetLogger(typeof(PlatformBitmapLoader))); + this.Log().Warn("Stream missing terminating bytes but is read only."); } - - private void AttemptStreamByteCorrection(Stream sourceStream) + else { - if (!sourceStream.CanWrite) - { - this.Log().Warn("Stream missing terminating bytes but is read only."); - } - else - { - this.Log().Warn("Carrying out source stream byte correction."); - sourceStream.Position = sourceStream.Length; - sourceStream.Write(new byte[] { 0xFF, 0xD9 }); - } + this.Log().Warn("Carrying out source stream byte correction."); + sourceStream.Position = sourceStream.Length; + sourceStream.Write(new byte[] { 0xFF, 0xD9 }); } } } diff --git a/src/Splat.Drawing/Platforms/Android/Colors/ColorExtensions.cs b/src/Splat.Drawing/Platforms/Android/Colors/ColorExtensions.cs index 62acbe06f..5b6e04af2 100644 --- a/src/Splat.Drawing/Platforms/Android/Colors/ColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/Android/Colors/ColorExtensions.cs @@ -5,31 +5,30 @@ using Android.Graphics; -namespace Splat +namespace Splat; + +/// +/// Provides extension methods for interacting with colors, to and from the android colors. +/// +public static class ColorExtensions { /// - /// Provides extension methods for interacting with colors, to and from the android colors. + /// Converts a to a android native color. /// - public static class ColorExtensions + /// The System.Drawing.Color to convert. + /// A native android color. + public static Color ToNative(this System.Drawing.Color other) { - /// - /// Converts a to a android native color. - /// - /// The System.Drawing.Color to convert. - /// A native android color. - public static Color ToNative(this System.Drawing.Color other) - { - return new(other.R, other.G, other.B, other.A); - } + return new(other.R, other.G, other.B, other.A); + } - /// - /// Converts from a android native color to a . - /// - /// The android native color to convert. - /// A System.Drawing.Color. - public static System.Drawing.Color FromNative(this Color other) - { - return System.Drawing.Color.FromArgb(other.A, other.R, other.G, other.B); - } + /// + /// Converts from a android native color to a . + /// + /// The android native color to convert. + /// A System.Drawing.Color. + public static System.Drawing.Color FromNative(this Color other) + { + return System.Drawing.Color.FromArgb(other.A, other.R, other.G, other.B); } } diff --git a/src/Splat.Drawing/Platforms/Android/Colors/SplatColorExtensions.cs b/src/Splat.Drawing/Platforms/Android/Colors/SplatColorExtensions.cs index 30ea49347..46c0f5aba 100644 --- a/src/Splat.Drawing/Platforms/Android/Colors/SplatColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/Android/Colors/SplatColorExtensions.cs @@ -5,31 +5,30 @@ using Android.Graphics; -namespace Splat +namespace Splat; + +/// +/// Extension methods associated with the struct. +/// +public static class SplatColorExtensions { /// - /// Extension methods associated with the struct. + /// Converts a into the android native . /// - public static class SplatColorExtensions + /// The color to convert. + /// The generated. + public static Color ToNative(this SplatColor value) { - /// - /// Converts a into the android native . - /// - /// The color to convert. - /// The generated. - public static Color ToNative(this SplatColor value) - { - return new(value.R, value.G, value.B, value.A); - } + return new(value.R, value.G, value.B, value.A); + } - /// - /// Converts a into the android native . - /// - /// The color to convert. - /// The generated. - public static SplatColor FromNative(this Color value) - { - return SplatColor.FromArgb(value.A, value.R, value.G, value.B); - } + /// + /// Converts a into the android native . + /// + /// The color to convert. + /// The generated. + public static SplatColor FromNative(this Color value) + { + return SplatColor.FromArgb(value.A, value.R, value.G, value.B); } } diff --git a/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs b/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs index 818746066..7248dd0cf 100644 --- a/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs +++ b/src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs @@ -5,61 +5,60 @@ using Android.Graphics; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing point's and a native point classes. +/// +public static class PointExtensions { /// - /// A set of extension methods which will convert between System.Drawing point's and a native point classes. + /// Convert a to the android native . /// - public static class PointExtensions + /// The value to convert. + /// A of the value. + public static Point ToNative(this System.Drawing.Point value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Point ToNative(this System.Drawing.Point value) - { - return new(value.X, value.Y); - } + return new(value.X, value.Y); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static PointF ToNative(this System.Drawing.PointF value) - { - return new(value.X, value.Y); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static PointF ToNative(this System.Drawing.PointF value) + { + return new(value.X, value.Y); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.Point FromNative(this Point value) + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.Point FromNative(this Point value) + { + if (value is null) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - return new System.Drawing.Point(value.X, value.Y); + throw new System.ArgumentNullException(nameof(value)); } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.PointF FromNative(this PointF value) - { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } + return new System.Drawing.Point(value.X, value.Y); + } - return new System.Drawing.PointF(value.X, value.Y); + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.PointF FromNative(this PointF value) + { + if (value is null) + { + throw new System.ArgumentNullException(nameof(value)); } + + return new System.Drawing.PointF(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 d0b5f48e0..74ec2725a 100644 --- a/src/Splat.Drawing/Platforms/Android/Maths/RectExtensions.cs +++ b/src/Splat.Drawing/Platforms/Android/Maths/RectExtensions.cs @@ -5,61 +5,60 @@ using Android.Graphics; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing rectangle's and a native rectangle classes. +/// +public static class RectExtensions { /// - /// A set of extension methods which will convert between System.Drawing rectangle's and a native rectangle classes. + /// Convert a to the android native . /// - public static class RectExtensions + /// The value to convert. + /// A of the value. + public static Rect ToNative(this System.Drawing.Rectangle value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Rect ToNative(this System.Drawing.Rectangle value) - { - return new(value.X, value.Y, value.X + value.Width, value.Y + value.Height); - } + return new(value.X, value.Y, value.X + value.Width, value.Y + value.Height); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static RectF ToNative(this System.Drawing.RectangleF value) - { - return new(value.X, value.Y, value.X + value.Width, value.Y + value.Height); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static RectF ToNative(this System.Drawing.RectangleF value) + { + return new(value.X, value.Y, value.X + value.Width, value.Y + value.Height); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.Rectangle FromNative(this Rect value) + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.Rectangle FromNative(this Rect value) + { + if (value is null) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - return new System.Drawing.Rectangle(value.Left, value.Top, value.Width(), value.Height()); + throw new System.ArgumentNullException(nameof(value)); } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.RectangleF FromNative(this RectF value) - { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } + return new System.Drawing.Rectangle(value.Left, value.Top, value.Width(), value.Height()); + } - return new System.Drawing.RectangleF(value.Left, value.Top, value.Width(), value.Height()); + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.RectangleF FromNative(this RectF value) + { + if (value is null) + { + throw new System.ArgumentNullException(nameof(value)); } + + return new System.Drawing.RectangleF(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 05588ad55..ddcf3a356 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/BitmapMixins.cs @@ -9,47 +9,46 @@ using UIImage = AppKit.NSImage; #endif -namespace Splat +namespace Splat; + +/// +/// Extension methods to assist with dealing with Bitmaps. +/// +public static class BitmapMixins { /// - /// Extension methods to assist with dealing with Bitmaps. + /// Converts to a native type. /// - public static class BitmapMixins + /// The bitmap to convert. + /// A bitmap. + public static UIImage ToNative(this IBitmap value) { - /// - /// Converts to a native type. - /// - /// The bitmap to convert. - /// A bitmap. - public static UIImage ToNative(this IBitmap value) + if (value is null) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - return ((CocoaBitmap)value).Inner; + throw new System.ArgumentNullException(nameof(value)); } - /// - /// Converts a to a splat . - /// - /// 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) - { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } + return ((CocoaBitmap)value).Inner; + } - if (copy) - { - return new CocoaBitmap((UIImage)value.Copy()); - } + /// + /// Converts a to a splat . + /// + /// 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) + { + if (value is null) + { + throw new System.ArgumentNullException(nameof(value)); + } - return new CocoaBitmap(value); + if (copy) + { + return new CocoaBitmap((UIImage)value.Copy()); } + + return new CocoaBitmap(value); } } diff --git a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs index d68111251..fa21176e3 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/CocoaBitmap.cs @@ -12,82 +12,83 @@ using UIKit; #else using AppKit; + using CoreGraphics; + using Foundation; using UIImage = AppKit.NSImage; #endif -namespace Splat +namespace Splat; + +/// +/// Wraps a cocoa native bitmap into the splat . +/// +internal sealed class CocoaBitmap : IBitmap { + private UIImage? _inner; + /// - /// Wraps a cocoa native bitmap into the splat . + /// Initializes a new instance of the class. /// - internal sealed class CocoaBitmap : IBitmap + /// The native image we are wrapping. + public CocoaBitmap(UIImage inner) { - private UIImage? _inner; - - /// - /// Initializes a new instance of the class. - /// - /// The native image we are wrapping. - public CocoaBitmap(UIImage inner) - { - _inner = inner; - } + _inner = inner; + } - /// - public float Width => (float)(_inner?.Size.Width ?? 0); + /// + public float Width => (float)(_inner?.Size.Width ?? 0); - /// - public float Height => (float)(_inner?.Size.Height ?? 0); + /// + public float Height => (float)(_inner?.Size.Height ?? 0); - /// - /// Gets the native image. - /// - internal UIImage Inner => _inner ?? throw new InvalidOperationException("Inner bitmap is no longer valid"); + /// + /// Gets the native image. + /// + internal UIImage Inner => _inner ?? throw new InvalidOperationException("Inner bitmap is no longer valid"); - /// - public Task Save(CompressedBitmapFormat format, float quality, Stream target) + /// + public Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + if (_inner is null) { - if (_inner is null) - { - return Task.CompletedTask; - } + return Task.CompletedTask; + } - return Task.Run(() => - { + return Task.Run(() => + { #if UIKIT - var data = format == CompressedBitmapFormat.Jpeg ? _inner.AsJPEG((float)quality) : _inner.AsPNG(); - data.AsStream().CopyTo(target); + var data = format == CompressedBitmapFormat.Jpeg ? _inner.AsJPEG((float)quality) : _inner.AsPNG(); + data.AsStream().CopyTo(target); #else - var rect = CGRect.Empty; + var rect = CGRect.Empty; - var cgImage = _inner.AsCGImage(ref rect, null, null); - var imageRep = new NSBitmapImageRep(cgImage); + var cgImage = _inner.AsCGImage(ref rect, null, null); + var imageRep = new NSBitmapImageRep(cgImage); - var props = format == CompressedBitmapFormat.Png ? - new NSDictionary() : - new NSDictionary(new NSNumber(quality), new NSString("NSImageCompressionFactor")); + var props = format == CompressedBitmapFormat.Png ? + new NSDictionary() : + new NSDictionary(new NSNumber(quality), new NSString("NSImageCompressionFactor")); - var type = format == CompressedBitmapFormat.Png ? NSBitmapImageFileType.Png : NSBitmapImageFileType.Jpeg; + var type = format == CompressedBitmapFormat.Png ? NSBitmapImageFileType.Png : NSBitmapImageFileType.Jpeg; - var outData = imageRep.RepresentationUsingTypeProperties(type, props); - outData.AsStream().CopyTo(target); + var outData = imageRep.RepresentationUsingTypeProperties(type, props); + outData.AsStream().CopyTo(target); #endif - }); - } + }); + } - /// - public void Dispose() + /// + public void Dispose() + { + var disp = Interlocked.Exchange(ref _inner, null); + if (disp is not null) { - var disp = Interlocked.Exchange(ref _inner, null); - if (disp is not null) - { - disp.Dispose(); - } + disp.Dispose(); } } } diff --git a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs index badc8825c..21ac487b6 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs @@ -4,12 +4,12 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; #if UIKIT using Foundation; + using UIKit; #else using Foundation; @@ -18,45 +18,22 @@ using UIImage = AppKit.NSImage; #endif -namespace Splat +namespace Splat; + +/// +/// A which will load Cocoa based bitmaps. +/// +public class PlatformBitmapLoader : IBitmapLoader { - /// - /// A which will load Cocoa based bitmaps. - /// - public class PlatformBitmapLoader : IBitmapLoader + /// + public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) { - /// - public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) - { - var data = NSData.FromStream(sourceStream); + var data = NSData.FromStream(sourceStream); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); #if UIKIT - NSRunLoop.InvokeInBackground(() => - { - try - { - if (data is null) - { - throw new InvalidOperationException("Failed to load stream"); - } - - var bitmap = UIImage.LoadFromData(data); - if (bitmap is null) - { - throw new InvalidOperationException("Failed to load image"); - } - - tcs.TrySetResult(new CocoaBitmap(bitmap)); - } - catch (Exception ex) - { - LogHost.Default.Debug(ex, "Unable to parse bitmap from byte stream."); - tcs.TrySetException(ex); - } - }); -#else - + NSRunLoop.InvokeInBackground(() => + { try { if (data is null) @@ -64,69 +41,91 @@ public class PlatformBitmapLoader : IBitmapLoader throw new InvalidOperationException("Failed to load stream"); } - tcs.TrySetResult(new CocoaBitmap(new UIImage(data))); + var bitmap = UIImage.LoadFromData(data); + if (bitmap is null) + { + throw new InvalidOperationException("Failed to load image"); + } + + tcs.TrySetResult(new CocoaBitmap(bitmap)); } catch (Exception ex) { LogHost.Default.Debug(ex, "Unable to parse bitmap from byte stream."); tcs.TrySetException(ex); } -#endif + }); +#else - return tcs.Task; - } + try + { + if (data is null) + { + throw new InvalidOperationException("Failed to load stream"); + } - /// - public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + tcs.TrySetResult(new CocoaBitmap(new UIImage(data))); + } + catch (Exception ex) { - var tcs = new TaskCompletionSource(); + LogHost.Default.Debug(ex, "Unable to parse bitmap from byte stream."); + tcs.TrySetException(ex); + } +#endif + + return tcs.Task; + } + + /// + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + { + var tcs = new TaskCompletionSource(); #if UIKIT - NSRunLoop.InvokeInBackground(() => + NSRunLoop.InvokeInBackground(() => + { + try { - try + var bitmap = UIImage.FromBundle(source); + if (bitmap is null) { - var bitmap = UIImage.FromBundle(source); - if (bitmap is null) - { - throw new InvalidOperationException("Failed to load image from resource: " + source); - } - - tcs.TrySetResult(new CocoaBitmap(bitmap)); + throw new InvalidOperationException("Failed to load image from resource: " + source); } - catch (Exception ex) - { - LogHost.Default.Debug(ex, "Unable to parse bitmap from resource."); - tcs.TrySetException(ex); - } - }); + + tcs.TrySetResult(new CocoaBitmap(bitmap)); + } + catch (Exception ex) + { + LogHost.Default.Debug(ex, "Unable to parse bitmap from resource."); + tcs.TrySetException(ex); + } + }); #else - NSRunLoop.Main.BeginInvokeOnMainThread(() => + NSRunLoop.Main.BeginInvokeOnMainThread(() => + { + try { - try + var bitmap = UIImage.ImageNamed(source); + if (bitmap is null) { - var bitmap = UIImage.ImageNamed(source); - if (bitmap is null) - { - throw new InvalidOperationException("Failed to load image from resource: " + source); - } - - tcs.TrySetResult(new CocoaBitmap(bitmap)); + throw new InvalidOperationException("Failed to load image from resource: " + source); } - catch (Exception ex) - { - LogHost.Default.Debug(ex, "Unable to parse bitmap from resource."); - tcs.TrySetException(ex); - } - }); + + tcs.TrySetResult(new CocoaBitmap(bitmap)); + } + catch (Exception ex) + { + LogHost.Default.Debug(ex, "Unable to parse bitmap from resource."); + tcs.TrySetException(ex); + } + }); #endif - return tcs.Task; - } + return tcs.Task; + } - /// - public IBitmap Create(float width, float height) - { - throw new NotImplementedException(); - } + /// + public IBitmap Create(float width, float height) + { + throw new NotImplementedException(); } } diff --git a/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs b/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs index cfa8e3be0..7b54f221a 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Colors/SplatColorExtensions.cs @@ -11,61 +11,60 @@ using AppKit; #endif -namespace Splat +namespace Splat; + +/// +/// Extension methods associated with the struct. +/// +public static class SplatColorExtensions { +#if UIKIT /// - /// Extension methods associated with the struct. + /// Converts a into the cocoa native . /// - public static class SplatColorExtensions - { -#if UIKIT - /// - /// Converts a into the cocoa native . - /// - /// The color to convert. - /// The generated value. - public static UIColor ToNative(this SplatColor value) => - new(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f); + /// The color to convert. + /// The generated value. + public static UIColor ToNative(this SplatColor value) => + new(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f); - /// - /// Converts a into the cocoa native . - /// - /// The color to convert. - /// The generated. - public static SplatColor FromNative(this UIColor value) + /// + /// Converts a into the cocoa native . + /// + /// The color to convert. + /// The generated. + public static SplatColor FromNative(this UIColor value) + { + if (value is null) { - if (value is null) - { - throw new ArgumentNullException(nameof(value)); - } - - 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)); + throw new ArgumentNullException(nameof(value)); } + + 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)); + } #else - /// - /// Converts a into the cocoa native . - /// - /// The color to convert. - /// The generated. - public static NSColor ToNative(this SplatColor value) => - NSColor.FromSrgb(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f); + /// + /// Converts a into the cocoa native . + /// + /// The color to convert. + /// The generated. + public static NSColor ToNative(this SplatColor value) => + NSColor.FromSrgb(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f); - /// - /// Converts a into the cocoa native . - /// - /// The color to convert. - /// The generated. - public static SplatColor FromNative(this NSColor value) + /// + /// Converts a into the cocoa native . + /// + /// The color to convert. + /// The generated. + public static SplatColor FromNative(this NSColor value) + { + if (value is null) { - if (value is null) - { - throw new ArgumentNullException(nameof(value)); - } - - 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)); + throw new 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)); } +#endif } diff --git a/src/Splat.Drawing/Platforms/ReflectionStubs.cs b/src/Splat.Drawing/Platforms/ReflectionStubs.cs index 8ad66877b..1a4ec989b 100644 --- a/src/Splat.Drawing/Platforms/ReflectionStubs.cs +++ b/src/Splat.Drawing/Platforms/ReflectionStubs.cs @@ -8,95 +8,94 @@ using System.Linq; using System.Reflection; -namespace Splat +namespace Splat; + +internal static class ReflectionStubs { - internal static class ReflectionStubs + public static FieldInfo? GetField(this Type value, string name, BindingFlags flags = default) { - public static FieldInfo? GetField(this Type value, string name, BindingFlags flags = default) + var ti = value.GetTypeInfo(); + var ret = ti.GetDeclaredField(name); + if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) { - var ti = value.GetTypeInfo(); - var ret = ti.GetDeclaredField(name); - if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) - { - return ret; - } - - return ti.BaseType.GetField(name, flags); + return ret; } - public static MethodInfo? GetMethod(this Type value, string name, BindingFlags flags = default) - { - var ti = value.GetTypeInfo(); - var ret = ti.GetDeclaredMethod(name); - if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) - { - return ret; - } - - return ti.BaseType.GetMethod(name, flags); - } + return ti.BaseType.GetField(name, flags); + } - public static PropertyInfo? GetProperty(this Type value, string name, BindingFlags flags = default) + public static MethodInfo? GetMethod(this Type value, string name, BindingFlags flags = default) + { + var ti = value.GetTypeInfo(); + var ret = ti.GetDeclaredMethod(name); + if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) { - var ti = value.GetTypeInfo(); - var ret = ti.GetDeclaredProperty(name); - if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) - { - return ret; - } - - return ti.BaseType.GetProperty(name, flags); + return ret; } - public static EventInfo? GetEvent(this Type value, string name, BindingFlags flags = default) - { - var ti = value.GetTypeInfo(); - var ret = ti.GetDeclaredEvent(name); - if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) - { - return ret; - } - - return ti.BaseType.GetEvent(name, flags); - } + return ti.BaseType.GetMethod(name, flags); + } - public static IEnumerable GetProperties(this Type value) + public static PropertyInfo? GetProperty(this Type value, string name, BindingFlags flags = default) + { + var ti = value.GetTypeInfo(); + var ret = ti.GetDeclaredProperty(name); + if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) { - return value.GetTypeInfo().DeclaredProperties; + return ret; } - public static IEnumerable GetFields(this Type value) + return ti.BaseType.GetProperty(name, flags); + } + + public static EventInfo? GetEvent(this Type value, string name, BindingFlags flags = default) + { + var ti = value.GetTypeInfo(); + var ret = ti.GetDeclaredEvent(name); + if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) { - return value.GetTypeInfo().DeclaredFields; + return ret; } - public static MethodInfo? GetMethod(this Type value, string methodName, Type[] paramTypes, BindingFlags flags = default) - { - var ti = value.GetTypeInfo(); - var ret = ti.GetDeclaredMethods(methodName) - .FirstOrDefault(x => paramTypes.Zip(x.GetParameters().Select(y => y.ParameterType), (l, r) => l == r).All(y => y)); + return ti.BaseType.GetEvent(name, flags); + } - if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) - { - return ret; - } + public static IEnumerable GetProperties(this Type value) + { + return value.GetTypeInfo().DeclaredProperties; + } - return ti.BaseType.GetMethod(methodName, paramTypes, flags); - } + public static IEnumerable GetFields(this Type value) + { + return value.GetTypeInfo().DeclaredFields; + } - public static IEnumerable GetMethods(this Type value) - { - return value.GetTypeInfo().DeclaredMethods; - } + public static MethodInfo? GetMethod(this Type value, string methodName, Type[] paramTypes, BindingFlags flags = default) + { + var ti = value.GetTypeInfo(); + var ret = ti.GetDeclaredMethods(methodName) + .FirstOrDefault(x => paramTypes.Zip(x.GetParameters().Select(y => y.ParameterType), (l, r) => l == r).All(y => y)); - public static IEnumerable GetCustomAttributes(this Type value, Type attributeType, bool inherit) + if (ret is not null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType is null) { - return value.GetTypeInfo().GetCustomAttributes(attributeType, inherit); + return ret; } - public static bool IsAssignableFrom(this Type value, Type anotherType) - { - return value.GetTypeInfo().IsAssignableFrom(anotherType.GetTypeInfo()); - } + return ti.BaseType.GetMethod(methodName, paramTypes, flags); + } + + public static IEnumerable GetMethods(this Type value) + { + return value.GetTypeInfo().DeclaredMethods; + } + + public static IEnumerable GetCustomAttributes(this Type value, Type attributeType, bool inherit) + { + return value.GetTypeInfo().GetCustomAttributes(attributeType, inherit); + } + + public static bool IsAssignableFrom(this Type value, Type anotherType) + { + return value.GetTypeInfo().IsAssignableFrom(anotherType.GetTypeInfo()); } } diff --git a/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs b/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs index 3afebf81b..d948344ab 100644 --- a/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs +++ b/src/Splat.Drawing/Platforms/ServiceLocationDrawingInitialization.cs @@ -5,31 +5,30 @@ using System; -namespace Splat +namespace Splat; + +/// +/// Provides service location for the Splat.Drawing packages. +/// +public static class ServiceLocationDrawingInitialization { /// - /// Provides service location for the Splat.Drawing packages. + /// Registers the platform bitmap loader for the current platform. /// - public static class ServiceLocationDrawingInitialization + /// The resolver to register against. + public static void RegisterPlatformBitmapLoader(this IMutableDependencyResolver resolver) { - /// - /// Registers the platform bitmap loader for the current platform. - /// - /// The resolver to register against. - public static void RegisterPlatformBitmapLoader(this IMutableDependencyResolver resolver) + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + throw new ArgumentNullException(nameof(resolver)); + } #if !IS_SHARED_NET - // not supported in netstandard or NET6 library - if (!resolver.HasRegistration(typeof(IBitmapLoader))) - { - resolver.RegisterLazySingleton(() => new PlatformBitmapLoader(), typeof(IBitmapLoader)); - } -#endif + // not supported in netstandard or NET6 library + if (!resolver.HasRegistration(typeof(IBitmapLoader))) + { + resolver.RegisterLazySingleton(() => new PlatformBitmapLoader(), typeof(IBitmapLoader)); } +#endif } } diff --git a/src/Splat.Drawing/Platforms/Tizen/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/Tizen/Bitmaps/BitmapMixins.cs index 1de1c88dd..4c2b14253 100644 --- a/src/Splat.Drawing/Platforms/Tizen/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/Tizen/Bitmaps/BitmapMixins.cs @@ -3,40 +3,37 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; - using Tizen.Multimedia.Util; -namespace Splat +namespace Splat; + +/// +/// Extension methods to assist with dealing with Bitmaps. +/// +public static class BitmapMixins { /// - /// Extension methods to assist with dealing with Bitmaps. + /// Converts to a . /// - public static class BitmapMixins + /// The bitmap to convert. + /// A bitmap. + public static IBitmap FromNative(this BitmapFrame value) { - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static IBitmap FromNative(this BitmapFrame value) - { - return new TizenBitmap(value); - } + return new TizenBitmap(value); + } - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static BitmapFrame ToNative(this IBitmap value) + /// + /// Converts to a . + /// + /// The bitmap to convert. + /// A bitmap. + public static BitmapFrame ToNative(this IBitmap value) + { + if (value is null) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - return ((TizenBitmap)value).Inner ?? throw new InvalidOperationException("Bitmap has been disposed"); + throw new System.ArgumentNullException(nameof(value)); } + + return (value as TizenBitmap)?.Inner ?? throw new InvalidOperationException("Bitmap has been disposed"); } } diff --git a/src/Splat.Drawing/Platforms/Tizen/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/Tizen/Bitmaps/PlatformBitmapLoader.cs index e16143010..257d03a48 100644 --- a/src/Splat.Drawing/Platforms/Tizen/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/Tizen/Bitmaps/PlatformBitmapLoader.cs @@ -3,44 +3,40 @@ // 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.IO; -using System.Threading.Tasks; +namespace Splat; -namespace Splat +/// +/// A which will load Tizen based bitmaps. +/// +public class PlatformBitmapLoader : IBitmapLoader { /// - /// A which will load Tizen based bitmaps. + /// A image the size of 100x100 pixels. + /// This is used due to the fact Tizen does not have a empty image object. /// - public class PlatformBitmapLoader : IBitmapLoader - { - /// - /// A image the size of 100x100 pixels. - /// This is used due to the fact Tizen does not have a empty image object. - /// - private static readonly byte[] _emptyImage = new byte[] - { - 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 100, 0, 0, 0, 100, 8, 2, 0, 0, 0, 255, 128, 2, 3, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 4, - 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, 195, 0, 0, 14, 195, 1, 199, 111, 168, 100, 0, 0, 0, 52, 73, 68, 65, 84, 120, 94, 237, 193, 1, 13, 0, 0, 0, - 194, 160, 247, 79, 109, 14, 55, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 27, 53, 117, 148, 0, 1, 4, 253, 190, 98, 0, 0, 0, - 0, 73, 69, 78, 68, 174, 66, 96, 130 - }; + private static readonly byte[] _emptyImage = new byte[] + { + 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 100, 0, 0, 0, 100, 8, 2, 0, 0, 0, 255, 128, 2, 3, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 4, + 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, 195, 0, 0, 14, 195, 1, 199, 111, 168, 100, 0, 0, 0, 52, 73, 68, 65, 84, 120, 94, 237, 193, 1, 13, 0, 0, 0, + 194, 160, 247, 79, 109, 14, 55, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 27, 53, 117, 148, 0, 1, 4, 253, 190, 98, 0, 0, 0, + 0, 73, 69, 78, 68, 174, 66, 96, 130, + }; - /// - public IBitmap Create(float width, float height) - { - return new TizenBitmap(_emptyImage); - } + /// + public IBitmap Create(float width, float height) + { + return new TizenBitmap(_emptyImage); + } - /// - public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) - { - return Task.Run(() => new TizenBitmap(((MemoryStream)sourceStream).ToArray())); - } + /// + public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) + { + return Task.Run(() => new TizenBitmap(((MemoryStream)sourceStream).ToArray())); + } - /// - public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) - { - return Task.Run(() => new TizenBitmap(source)); - } + /// + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + { + return Task.Run(() => new TizenBitmap(source)); } } diff --git a/src/Splat.Drawing/Platforms/Tizen/Bitmaps/TizenBitmap.cs b/src/Splat.Drawing/Platforms/Tizen/Bitmaps/TizenBitmap.cs index 8cd9c8729..bfd3252df 100644 --- a/src/Splat.Drawing/Platforms/Tizen/Bitmaps/TizenBitmap.cs +++ b/src/Splat.Drawing/Platforms/Tizen/Bitmaps/TizenBitmap.cs @@ -3,133 +3,129 @@ // 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.IO; -using System.Linq; -using System.Threading.Tasks; using Tizen.Multimedia.Util; -namespace Splat +namespace Splat; + +/// +/// Wraps a tizen native bitmap into the splat . +/// +internal sealed class TizenBitmap : IBitmap { + private static readonly ImageDecoder[] _decoderList = new ImageDecoder[] + { + new JpegDecoder(), + new PngDecoder(), + new BmpDecoder(), + new GifDecoder(), + }; + /// - /// Wraps a tizen native bitmap into the splat . + /// Initializes a new instance of the class. /// - internal sealed class TizenBitmap : IBitmap + /// The image in bytes we are wrapping. Will generate a native platform bitmap for us. + public TizenBitmap(byte[] image) { - private static readonly ImageDecoder[] _decoderList = new ImageDecoder[] - { - new JpegDecoder(), - new PngDecoder(), - new BmpDecoder(), - new GifDecoder(), - }; - - /// - /// Initializes a new instance of the class. - /// - /// The image in bytes we are wrapping. Will generate a native platform bitmap for us. - public TizenBitmap(byte[] image) - { - Inner = GetBitmapFrame(image); - } + Inner = GetBitmapFrame(image); + } - /// - /// Initializes a new instance of the class. - /// - /// The name of the image resource to load. - public TizenBitmap(string imageResourceName) - { - Inner = GetBitmapFrame(File.ReadAllBytes(imageResourceName)); - } + /// + /// Initializes a new instance of the class. + /// + /// The name of the image resource to load. + public TizenBitmap(string imageResourceName) + { + Inner = GetBitmapFrame(File.ReadAllBytes(imageResourceName)); + } - public TizenBitmap(BitmapFrame image) - { - Inner = image; - } + public TizenBitmap(BitmapFrame image) + { + Inner = image; + } - /// - public float Width => Inner?.Size.Width ?? 0; + /// + public float Width => Inner?.Size.Width ?? 0; - /// - public float Height => Inner?.Size.Height ?? 0; + /// + public float Height => Inner?.Size.Height ?? 0; - /// - /// Gets the native bitmap. - /// - internal BitmapFrame? Inner { get; private set; } + /// + /// Gets the native bitmap. + /// + internal BitmapFrame? Inner { get; private set; } - /// - public Task Save(CompressedBitmapFormat format, float quality, Stream target) + /// + public Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + if (Inner is null) { - if (Inner is null) - { - return Task.CompletedTask; - } + return Task.CompletedTask; + } - ImageEncoder? encoder = null; - try + ImageEncoder? encoder = null; + try + { + var qualityPercent = (int)(100 * quality); + switch (format) { - int qualityPercent = (int)(100 * quality); - switch (format) - { - case CompressedBitmapFormat.Jpeg: - encoder = new JpegEncoder(); - ((JpegEncoder)encoder).Quality = qualityPercent; - break; - case CompressedBitmapFormat.Png: - encoder = new PngEncoder(); - if (qualityPercent == 100) - { - ((PngEncoder)encoder).Compression = PngCompression.None; - } - else if (qualityPercent < 10) - { - ((PngEncoder)encoder).Compression = PngCompression.Level1; - } - else - { - ((PngEncoder)encoder).Compression = (PngCompression)(qualityPercent / 10); - } - - break; - } - - if (encoder is null) - { - return Task.CompletedTask; - } - - encoder.SetResolution(new Tizen.Multimedia.Size((int)Width, (int)Height)); - return encoder.EncodeAsync(Inner.Buffer, target); + case CompressedBitmapFormat.Jpeg: + encoder = new JpegEncoder(); + ((JpegEncoder)encoder).Quality = qualityPercent; + break; + case CompressedBitmapFormat.Png: + encoder = new PngEncoder(); + if (qualityPercent == 100) + { + ((PngEncoder)encoder).Compression = PngCompression.None; + } + else if (qualityPercent < 10) + { + ((PngEncoder)encoder).Compression = PngCompression.Level1; + } + else + { + ((PngEncoder)encoder).Compression = (PngCompression)(qualityPercent / 10); + } + + break; } - finally + + if (encoder is null) { - encoder?.Dispose(); + return Task.CompletedTask; } - } - /// - public void Dispose() + encoder.SetResolution(new Tizen.Multimedia.Size((int)Width, (int)Height)); + return encoder.EncodeAsync(Inner.Buffer, target); + } + finally { - Inner = null; + encoder?.Dispose(); } + } - private static BitmapFrame? GetBitmapFrame(byte[] imageBuffer) - { - BitmapFrame? result = null; + /// + public void Dispose() + { + Inner = null; + } + + private static BitmapFrame? GetBitmapFrame(byte[] imageBuffer) + { + BitmapFrame? result = null; - foreach (var decoder in _decoderList) + foreach (var decoder in _decoderList) + { + try + { + result = decoder.DecodeAsync(imageBuffer).Result.First(); + break; + } + catch (Tizen.Multimedia.FileFormatException) { - try - { - result = decoder.DecodeAsync(imageBuffer).Result.First(); - break; - } - catch (Tizen.Multimedia.FileFormatException) - { - } } - - return result; } + + return result; } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs index dae01bd14..79c547f89 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs @@ -3,59 +3,55 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Threading.Tasks; + using Windows.Storage; using Windows.UI.Xaml.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// A bitmap that wraps a . +/// +internal sealed class BitmapImageBitmap : IBitmap { - /// - /// A bitmap that wraps a . - /// - internal sealed class BitmapImageBitmap : IBitmap - { - private BitmapImage? _inner; + private BitmapImage? _inner; - public BitmapImageBitmap(BitmapImage bitmap) - { - _inner = bitmap; - } + public BitmapImageBitmap(BitmapImage bitmap) + { + _inner = bitmap; + } - /// - public float Width => Inner?.PixelWidth ?? 0; + /// + public float Width => Inner?.PixelWidth ?? 0; - /// - public float Height => Inner?.PixelHeight ?? 0; + /// + public float Height => Inner?.PixelHeight ?? 0; - /// - /// Gets the platform . - /// - public BitmapSource? Inner => _inner; + /// + /// Gets the platform . + /// + public BitmapSource? Inner => _inner; - /// - [SuppressMessage("Globalization", "CA1307: Use IFormatProvider", Justification = "string.Replace does not have a IFormatProvider on all .NET platforms")] - public async Task Save(CompressedBitmapFormat format, float quality, Stream target) + /// + public async Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + if (_inner is null) { - if (_inner is null) - { - return; - } + return; + } - string installedFolderImageSourceUri = _inner.UriSource.OriginalString.Replace("ms-appx:/", string.Empty); - var wb = new WriteableBitmap(_inner.PixelWidth, _inner.PixelHeight); - var file = await StorageFile.GetFileFromPathAsync(_inner.UriSource.OriginalString); - await wb.SetSourceAsync(await file.OpenReadAsync()); + var installedFolderImageSourceUri = _inner.UriSource.OriginalString.Replace("ms-appx:/", string.Empty); + var wb = new WriteableBitmap(_inner.PixelWidth, _inner.PixelHeight); + var file = await StorageFile.GetFileFromPathAsync(_inner.UriSource.OriginalString); + await wb.SetSourceAsync(await file.OpenReadAsync()); - await new WriteableBitmapImageBitmap(wb).Save(format, quality, target).ConfigureAwait(false); - } + await new WriteableBitmapImageBitmap(wb).Save(format, quality, target).ConfigureAwait(false); + } - /// - public void Dispose() - { - _inner = null; - } + /// + public void Dispose() + { + _inner = null; } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs index 5c47631c1..b1fb72301 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs @@ -3,60 +3,57 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; - using Windows.UI.Xaml.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// Extension methods to assist with dealing with Bitmaps. +/// +public static class BitmapMixins { /// - /// Extension methods to assist with dealing with Bitmaps. + /// Converts to a . + /// + /// The bitmap to convert. + /// A bitmap. + public static IBitmap FromNative(this BitmapImage value) + { + return new BitmapImageBitmap(value); + } + + /// + /// Converts to a . /// - public static class BitmapMixins + /// The bitmap to convert. + /// A bitmap. + public static IBitmap FromNative(this WriteableBitmap value) { - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static IBitmap FromNative(this BitmapImage value) + return new WriteableBitmapImageBitmap(value); + } + + /// + /// Converts to a . + /// + /// The bitmap to convert. + /// A bitmap. + public static BitmapSource ToNative(this IBitmap value) + { + if (value is null) { - return new BitmapImageBitmap(value); + throw new System.ArgumentNullException(nameof(value)); } - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static IBitmap FromNative(this WriteableBitmap value) + if (value is WriteableBitmapImageBitmap wbib) { - return new WriteableBitmapImageBitmap(value); + return wbib.Inner ?? throw new InvalidOperationException("The bitmap has been disposed"); } - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static BitmapSource ToNative(this IBitmap value) + if (value is BitmapImageBitmap bitmapImage) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - if (value is WriteableBitmapImageBitmap wbib) - { - return wbib.Inner ?? throw new InvalidOperationException("The bitmap has been disposed"); - } - - if (value is BitmapImageBitmap bitmapImage) - { - return bitmapImage.Inner ?? throw new InvalidOperationException("The bitmap has been disposed"); - } - - throw new InvalidOperationException("The bitmap type is unsupported"); + return bitmapImage.Inner ?? throw new InvalidOperationException("The bitmap has been disposed"); } + + throw new InvalidOperationException("The bitmap type is unsupported"); } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs index 7d5e47d4a..d62eadedb 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs @@ -3,42 +3,39 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Threading.Tasks; using Windows.UI.Core; -namespace Splat +namespace Splat; + +internal static class DispatcherMixin { - internal static class DispatcherMixin + public static async Task RunTaskAsync(this CoreDispatcher dispatcher, Func> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) { - public static async Task RunTaskAsync(this CoreDispatcher dispatcher, Func> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) + var taskCompletionSource = new TaskCompletionSource(); + await dispatcher.RunAsync(priority, async () => { - var taskCompletionSource = new TaskCompletionSource(); - await dispatcher.RunAsync(priority, async () => + try + { + taskCompletionSource.SetResult(await func().ConfigureAwait(false)); + } + catch (Exception ex) { - try - { - taskCompletionSource.SetResult(await func().ConfigureAwait(false)); - } - catch (Exception ex) - { - taskCompletionSource.SetException(ex); - } - }); - return await taskCompletionSource.Task.ConfigureAwait(false); - } + taskCompletionSource.SetException(ex); + } + }); + return await taskCompletionSource.Task.ConfigureAwait(false); + } - // There is no TaskCompletionSource so we use a bool that we throw away. - public static Task RunTaskAsync(this CoreDispatcher dispatcher, Func func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) - { - return RunTaskAsync( - dispatcher, - async () => - { - await func().ConfigureAwait(false); - return false; - }, - priority); - } + // There is no TaskCompletionSource so we use a bool that we throw away. + public static Task RunTaskAsync(this CoreDispatcher dispatcher, Func func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) + { + return RunTaskAsync( + dispatcher, + async () => + { + await func().ConfigureAwait(false); + return false; + }, + priority); } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs index 2b1ca7faf..85e5ed5f2 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs @@ -3,93 +3,90 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.IO; using System.Runtime.InteropServices.WindowsRuntime; -using System.Threading.Tasks; + using Windows.ApplicationModel.Core; using Windows.Graphics.Imaging; using Windows.Storage; using Windows.UI.Core; using Windows.UI.Xaml.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// A XAML based platform bitmap loader which will load our bitmaps for us. +/// +public class PlatformBitmapLoader : IBitmapLoader { - /// - /// A XAML based platform bitmap loader which will load our bitmaps for us. - /// - public class PlatformBitmapLoader : IBitmapLoader + /// + public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) { - /// - public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) + return GetDispatcher().RunTaskAsync(async () => { - return GetDispatcher().RunTaskAsync(async () => + using (var randomAccessStream = sourceStream.AsRandomAccessStream()) { - using (var randomAccessStream = sourceStream.AsRandomAccessStream()) - { - randomAccessStream.Seek(0); - var decoder = await BitmapDecoder.CreateAsync(randomAccessStream); + randomAccessStream.Seek(0); + var decoder = await BitmapDecoder.CreateAsync(randomAccessStream); - int targetWidth = (int)(desiredWidth ?? decoder.OrientedPixelWidth); - int targetHeight = (int)(desiredHeight ?? decoder.OrientedPixelHeight); + var targetWidth = (int)(desiredWidth ?? decoder.OrientedPixelWidth); + var targetHeight = (int)(desiredHeight ?? decoder.OrientedPixelHeight); - var transform = new BitmapTransform - { - ScaledWidth = (uint)targetWidth, - ScaledHeight = (uint)targetHeight, - InterpolationMode = BitmapInterpolationMode.Fant - }; + var transform = new BitmapTransform + { + ScaledWidth = (uint)targetWidth, + ScaledHeight = (uint)targetHeight, + InterpolationMode = BitmapInterpolationMode.Fant, + }; - if (decoder.OrientedPixelHeight != decoder.PixelHeight) - { - // if Exif orientation indicates 90 or 270 degrees rotation we swap width and height for the transformation. - transform.ScaledWidth = (uint)targetHeight; - transform.ScaledHeight = (uint)targetWidth; - } + if (decoder.OrientedPixelHeight != decoder.PixelHeight) + { + // if Exif orientation indicates 90 or 270 degrees rotation we swap width and height for the transformation. + transform.ScaledWidth = (uint)targetHeight; + transform.ScaledHeight = (uint)targetWidth; + } - var pixelData = await decoder.GetPixelDataAsync(decoder.BitmapPixelFormat, BitmapAlphaMode.Premultiplied, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb); - var pixels = pixelData.DetachPixelData(); + var pixelData = await decoder.GetPixelDataAsync(decoder.BitmapPixelFormat, BitmapAlphaMode.Premultiplied, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb); + var pixels = pixelData.DetachPixelData(); - var bmp = new WriteableBitmap(targetWidth, targetHeight); - using (var bmpStream = bmp.PixelBuffer.AsStream()) - { - bmpStream.Seek(0, SeekOrigin.Begin); - await bmpStream.WriteAsync(pixels, 0, (int)bmpStream.Length); - return (IBitmap?)new WriteableBitmapImageBitmap(bmp); - } + var bmp = new WriteableBitmap(targetWidth, targetHeight); + using (var bmpStream = bmp.PixelBuffer.AsStream()) + { + bmpStream.Seek(0, SeekOrigin.Begin); + await bmpStream.WriteAsync(pixels, 0, (int)bmpStream.Length); + return (IBitmap?)new WriteableBitmapImageBitmap(bmp); } - }); - } + } + }); + } - /// - public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + /// + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + { + return GetDispatcher().RunTaskAsync(async () => { - return GetDispatcher().RunTaskAsync(async () => + var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(source)); + using (var stream = await file.OpenAsync(FileAccessMode.Read)) { - var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(source)); - using (var stream = await file.OpenAsync(FileAccessMode.Read)) - { - return await Load(stream.AsStreamForRead(), desiredWidth, desiredHeight).ConfigureAwait(false); - } - }); - } + return await Load(stream.AsStreamForRead(), desiredWidth, desiredHeight).ConfigureAwait(false); + } + }); + } - /// - public IBitmap Create(float width, float height) + /// + public IBitmap Create(float width, float height) + { + var disp = GetDispatcher().RunTaskAsync(async () => { - var disp = GetDispatcher().RunTaskAsync(async () => - { - return await Task.FromResult(new WriteableBitmapImageBitmap(new WriteableBitmap((int)width, (int)height))).ConfigureAwait(false); - }); + return await Task.FromResult(new WriteableBitmapImageBitmap(new WriteableBitmap((int)width, (int)height))).ConfigureAwait(false); + }); - return disp.GetAwaiter().GetResult(); - } + return disp.GetAwaiter().GetResult(); + } - private static CoreDispatcher GetDispatcher() - { - CoreWindow currentThreadWindow = CoreWindow.GetForCurrentThread(); + private static CoreDispatcher GetDispatcher() + { + CoreWindow currentThreadWindow = CoreWindow.GetForCurrentThread(); - return currentThreadWindow is null ? CoreApplication.MainView.CoreWindow.Dispatcher : currentThreadWindow.Dispatcher; - } + return currentThreadWindow is null ? CoreApplication.MainView.CoreWindow.Dispatcher : currentThreadWindow.Dispatcher; } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs index 614bc5964..e155468b4 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs @@ -3,66 +3,61 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.IO; using System.Runtime.InteropServices.WindowsRuntime; -using System.Threading.Tasks; + using Windows.Foundation; using Windows.Graphics.Imaging; using Windows.Storage.Streams; using Windows.UI.Xaml.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// A bitmap that wraps a . +/// +internal sealed class WriteableBitmapImageBitmap : IBitmap { - /// - /// A bitmap that wraps a . - /// - internal sealed class WriteableBitmapImageBitmap : IBitmap + public WriteableBitmapImageBitmap(WriteableBitmap bitmap) { - public WriteableBitmapImageBitmap(WriteableBitmap bitmap) - { - Inner = bitmap; - } + Inner = bitmap; + } - /// - public float Width => Inner?.PixelWidth ?? 0; + /// + public float Width => Inner?.PixelWidth ?? 0; - /// - public float Height => Inner?.PixelHeight ?? 0; + /// + public float Height => Inner?.PixelHeight ?? 0; - /// - /// Gets the platform . - /// - public WriteableBitmap? Inner { get; private set; } + /// + /// Gets the platform . + /// + public WriteableBitmap? Inner { get; private set; } - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Local variable will be disposed.")] - public async Task Save(CompressedBitmapFormat format, float quality, Stream target) + /// + public async Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + if (Inner is null) { - if (Inner is null) - { - return; - } + return; + } - // NB: Due to WinRT's brain-dead design, we're copying this image - // like three times. Let Dreams Soar. - using var rwTarget = new InMemoryRandomAccessStream(); - var fmt = format == CompressedBitmapFormat.Jpeg ? BitmapEncoder.JpegEncoderId : BitmapEncoder.PngEncoderId; - var encoder = await BitmapEncoder.CreateAsync(fmt, rwTarget, new[] { new KeyValuePair("ImageQuality", new BitmapTypedValue(quality, PropertyType.Single)) }); + // NB: Due to WinRT's brain-dead design, we're copying this image + // like three times. Let Dreams Soar. + using var rwTarget = new InMemoryRandomAccessStream(); + var fmt = format == CompressedBitmapFormat.Jpeg ? BitmapEncoder.JpegEncoderId : BitmapEncoder.PngEncoderId; + var encoder = await BitmapEncoder.CreateAsync(fmt, rwTarget, new[] { new KeyValuePair("ImageQuality", new BitmapTypedValue(quality, PropertyType.Single)) }); - var pixels = new byte[Inner.PixelBuffer.Length]; - await Inner.PixelBuffer.AsStream().ReadAsync(pixels, 0, (int)Inner.PixelBuffer.Length).ConfigureAwait(true); + var pixels = new byte[Inner.PixelBuffer.Length]; + await Inner.PixelBuffer.AsStream().ReadAsync(pixels, 0, (int)Inner.PixelBuffer.Length).ConfigureAwait(true); - encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, (uint)Inner.PixelWidth, (uint)Inner.PixelHeight, 96, 96, pixels); - await encoder.FlushAsync(); - await rwTarget.AsStream().CopyToAsync(target).ConfigureAwait(false); - } + encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, (uint)Inner.PixelWidth, (uint)Inner.PixelHeight, 96, 96, pixels); + await encoder.FlushAsync(); + await rwTarget.AsStream().CopyToAsync(target).ConfigureAwait(false); + } - /// - public void Dispose() - { - Inner = null; - } + /// + public void Dispose() + { + Inner = null; } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs b/src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs index 5326e9354..da214bef7 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs @@ -6,41 +6,40 @@ using Windows.UI; using Windows.UI.Xaml.Media; -namespace Splat.Platforms.WinRT.Colors +namespace Splat.Platforms.WinRT.Colors; + +/// +/// Provides extension methods for interacting with colors, to and from the XAML colors. +/// +public static class ColorExtensions { /// - /// Provides extension methods for interacting with colors, to and from the XAML colors. + /// Converts a to a XAML native color. /// - public static class ColorExtensions + /// The System.Drawing.Color to convert. + /// A native XAML color. + public static Color ToNative(this System.Drawing.Color value) { - /// - /// Converts a to a XAML native color. - /// - /// The System.Drawing.Color to convert. - /// A native XAML color. - public static Color ToNative(this System.Drawing.Color value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } + return Color.FromArgb(value.A, value.R, value.G, value.B); + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value) - { - return new(value.ToNative()); - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value) + { + return new(value.ToNative()); + } - /// - /// Converts a XAML color into the XAML . - /// - /// The color to convert. - /// The generated. - public static System.Drawing.Color FromNative(this Color value) - { - return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B); - } + /// + /// Converts a XAML color into the XAML . + /// + /// The color to convert. + /// The generated. + public static System.Drawing.Color FromNative(this Color value) + { + return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B); } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs b/src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs index d679e073f..ab1f963a6 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs @@ -6,41 +6,40 @@ using Windows.UI; using Windows.UI.Xaml.Media; -namespace Splat.Platforms.WinRT.Colors +namespace Splat.Platforms.WinRT.Colors; + +/// +/// Extension methods associated with the struct. +/// +public static class SplatColorExtensions { /// - /// Extension methods associated with the struct. + /// Converts a into the XAML color. /// - public static class SplatColorExtensions + /// The color to convert. + /// The XAML color generated. + public static Color ToNative(this SplatColor value) { - /// - /// Converts a into the XAML color. - /// - /// The color to convert. - /// The XAML color generated. - public static Color ToNative(this SplatColor value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } + return Color.FromArgb(value.A, value.R, value.G, value.B); + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this SplatColor value) - { - return new(value.ToNative()); - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static SolidColorBrush ToNativeBrush(this SplatColor value) + { + return new(value.ToNative()); + } - /// - /// Converts a XAML color into the XAML . - /// - /// The color to convert. - /// The generated. - public static SplatColor FromNative(this Color value) - { - return SplatColor.FromArgb(value.A, value.R, value.G, value.B); - } + /// + /// Converts a XAML color into the XAML . + /// + /// The color to convert. + /// The generated. + public static SplatColor FromNative(this Color value) + { + return SplatColor.FromArgb(value.A, value.R, value.G, value.B); } } diff --git a/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapMixins.cs index 828262589..1abca78cc 100644 --- a/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapMixins.cs @@ -6,36 +6,35 @@ using System; using System.Windows.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// Extension methods to assist with dealing with Bitmaps. +/// +public static class BitmapMixins { /// - /// Extension methods to assist with dealing with Bitmaps. + /// Converts to a native type. /// - public static class BitmapMixins + /// The bitmap to convert. + /// A bitmap. + public static IBitmap FromNative(this BitmapSource value) { - /// - /// Converts to a native type. - /// - /// The bitmap to convert. - /// A bitmap. - public static IBitmap FromNative(this BitmapSource value) - { - return new BitmapSourceBitmap(value); - } + return new BitmapSourceBitmap(value); + } - /// - /// Converts a to a splat . - /// - /// The native bitmap to convert from. - /// A bitmap. - public static BitmapSource ToNative(this IBitmap value) + /// + /// Converts a to a splat . + /// + /// The native bitmap to convert from. + /// A bitmap. + public static BitmapSource ToNative(this IBitmap value) + { + if (value is null) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - return ((BitmapSourceBitmap)value).Inner ?? throw new InvalidOperationException("There is not a valid bitmap"); + throw new System.ArgumentNullException(nameof(value)); } + + return ((BitmapSourceBitmap)value).Inner ?? throw new InvalidOperationException("There is not a valid bitmap"); } } diff --git a/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapSourceBitmap.cs b/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapSourceBitmap.cs index 4522ffd1b..00455cde3 100644 --- a/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapSourceBitmap.cs +++ b/src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapSourceBitmap.cs @@ -7,56 +7,55 @@ using System.Threading.Tasks; using System.Windows.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// A bitmap that wraps a . +/// +internal sealed class BitmapSourceBitmap : IBitmap { /// - /// A bitmap that wraps a . + /// Initializes a new instance of the class. /// - internal sealed class BitmapSourceBitmap : IBitmap + /// The platform native bitmap we are wrapping. + public BitmapSourceBitmap(BitmapSource bitmap) { - /// - /// Initializes a new instance of the class. - /// - /// The platform native bitmap we are wrapping. - public BitmapSourceBitmap(BitmapSource bitmap) - { - Inner = bitmap; - } + Inner = bitmap; + } - /// - public float Width => (float)(Inner?.Width ?? 0f); + /// + public float Width => (float)(Inner?.Width ?? 0f); - /// - public float Height => (float)(Inner?.Height ?? 0f); + /// + public float Height => (float)(Inner?.Height ?? 0f); - /// - /// Gets the platform . - /// - public BitmapSource? Inner { get; private set; } + /// + /// Gets the platform . + /// + public BitmapSource? Inner { get; private set; } - /// - public Task Save(CompressedBitmapFormat format, float quality, Stream target) + /// + public Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + if (Inner is null) { - if (Inner is null) - { - return Task.CompletedTask; - } - - return Task.Run(() => - { - var encoder = format == CompressedBitmapFormat.Jpeg ? - new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } : - (BitmapEncoder)new PngBitmapEncoder(); - - encoder.Frames.Add(BitmapFrame.Create(Inner)); - encoder.Save(target); - }); + return Task.CompletedTask; } - /// - public void Dispose() + return Task.Run(() => { - Inner = null; - } + var encoder = format == CompressedBitmapFormat.Jpeg ? + new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } : + (BitmapEncoder)new PngBitmapEncoder(); + + encoder.Frames.Add(BitmapFrame.Create(Inner)); + encoder.Save(target); + }); + } + + /// + public void Dispose() + { + Inner = null; } } diff --git a/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs index 5070cf3c4..542035d0b 100644 --- a/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs @@ -9,81 +9,80 @@ using System.Windows.Media; using System.Windows.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// A XAML based platform bitmap loader which will load our bitmaps for us. +/// +public class PlatformBitmapLoader : IBitmapLoader { - /// - /// A XAML based platform bitmap loader which will load our bitmaps for us. - /// - public class PlatformBitmapLoader : IBitmapLoader + /// + public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) { - /// - public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) + return Task.Run(() => { - return Task.Run(() => - { - var ret = new BitmapImage(); + var ret = new BitmapImage(); - WithInit(ret, source => + WithInit(ret, source => + { + if (desiredWidth is not null) { - if (desiredWidth is not null) - { - source.DecodePixelWidth = (int)desiredWidth; - } + source.DecodePixelWidth = (int)desiredWidth; + } - if (desiredHeight is not null) - { - source.DecodePixelHeight = (int)desiredHeight; - } - - source.StreamSource = sourceStream; - source.CacheOption = BitmapCacheOption.OnLoad; - }); + if (desiredHeight is not null) + { + source.DecodePixelHeight = (int)desiredHeight; + } - return new BitmapSourceBitmap(ret); + source.StreamSource = sourceStream; + source.CacheOption = BitmapCacheOption.OnLoad; }); - } - /// - public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + return new BitmapSourceBitmap(ret); + }); + } + + /// + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + { + return Task.Run(() => { - return Task.Run(() => + var ret = new BitmapImage(); + WithInit(ret, x => { - var ret = new BitmapImage(); - WithInit(ret, x => + if (desiredWidth is not null) { - if (desiredWidth is not null) - { - x.DecodePixelWidth = (int)desiredWidth; - } + x.DecodePixelWidth = (int)desiredWidth; + } - if (desiredHeight is not null) - { - x.DecodePixelHeight = (int)desiredHeight; - } - - x.UriSource = new Uri(source, UriKind.RelativeOrAbsolute); - }); + if (desiredHeight is not null) + { + x.DecodePixelHeight = (int)desiredHeight; + } - return new BitmapSourceBitmap(ret); + x.UriSource = new Uri(source, UriKind.RelativeOrAbsolute); }); - } - /// - public IBitmap Create(float width, float height) - { - return new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32, null)); - } + return new BitmapSourceBitmap(ret); + }); + } - private static void WithInit(BitmapImage source, Action block) - { - source.BeginInit(); - block(source); - source.EndInit(); + /// + public IBitmap Create(float width, float height) + { + return new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32, null)); + } - if (source.CanFreeze) - { - source.Freeze(); - } + private static void WithInit(BitmapImage source, Action block) + { + source.BeginInit(); + block(source); + source.EndInit(); + + if (source.CanFreeze) + { + source.Freeze(); } } } diff --git a/src/Splat.Drawing/Platforms/net4/Colors/ColorExtensions.cs b/src/Splat.Drawing/Platforms/net4/Colors/ColorExtensions.cs index cbb6ba1f1..b069f6358 100644 --- a/src/Splat.Drawing/Platforms/net4/Colors/ColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/net4/Colors/ColorExtensions.cs @@ -5,43 +5,42 @@ using System.Windows.Media; -namespace Splat +namespace Splat; + +/// +/// Provides extension methods for interacting with colors, to and from the XAML colors. +/// +public static class ColorExtensions { /// - /// Provides extension methods for interacting with colors, to and from the XAML colors. + /// Converts a to a XAML native color. /// - public static class ColorExtensions + /// The System.Drawing.Color to convert. + /// A native XAML color. + public static Color ToNative(this System.Drawing.Color value) { - /// - /// Converts a to a XAML native color. - /// - /// The System.Drawing.Color to convert. - /// A native XAML color. - public static Color ToNative(this System.Drawing.Color value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } + return Color.FromArgb(value.A, value.R, value.G, value.B); + } - /// - /// Converts a into the cocoa native . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value) - { - var ret = new SolidColorBrush(value.ToNative()); - ret.Freeze(); - return ret; - } + /// + /// Converts a into the cocoa native . + /// + /// The color to convert. + /// The generated. + public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value) + { + var ret = new SolidColorBrush(value.ToNative()); + ret.Freeze(); + return ret; + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static System.Drawing.Color FromNative(this Color value) - { - return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B); - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static System.Drawing.Color FromNative(this Color value) + { + return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B); } } diff --git a/src/Splat.Drawing/Platforms/net4/Colors/SplatColorExtensions.cs b/src/Splat.Drawing/Platforms/net4/Colors/SplatColorExtensions.cs index 0043854e9..b2d93c664 100644 --- a/src/Splat.Drawing/Platforms/net4/Colors/SplatColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/net4/Colors/SplatColorExtensions.cs @@ -5,43 +5,42 @@ using System.Windows.Media; -namespace Splat +namespace Splat; + +/// +/// Extension methods associated with the struct. +/// +public static class SplatColorExtensions { /// - /// Extension methods associated with the struct. + /// Converts a into the XAML . /// - public static class SplatColorExtensions + /// The color to convert. + /// The generated. + public static Color ToNative(this SplatColor value) { - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static Color ToNative(this SplatColor value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } + return Color.FromArgb(value.A, value.R, value.G, value.B); + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this SplatColor value) - { - var ret = new SolidColorBrush(value.ToNative()); - ret.Freeze(); - return ret; - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static SolidColorBrush ToNativeBrush(this SplatColor value) + { + var ret = new SolidColorBrush(value.ToNative()); + ret.Freeze(); + return ret; + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SplatColor FromNative(this Color value) - { - return SplatColor.FromArgb(value.A, value.R, value.G, value.B); - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static SplatColor FromNative(this Color value) + { + return SplatColor.FromArgb(value.A, value.R, value.G, value.B); } } diff --git a/src/Splat.Drawing/Platforms/net4/Maths/PointExtensions.cs b/src/Splat.Drawing/Platforms/net4/Maths/PointExtensions.cs index a993fea3b..e13a6d3af 100644 --- a/src/Splat.Drawing/Platforms/net4/Maths/PointExtensions.cs +++ b/src/Splat.Drawing/Platforms/net4/Maths/PointExtensions.cs @@ -5,41 +5,40 @@ using System.Windows; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing point's and a native point classes. +/// +public static class PointExtensions { /// - /// A set of extension methods which will convert between System.Drawing point's and a native point classes. + /// Convert a to the android native . /// - public static class PointExtensions + /// The value to convert. + /// A of the value. + public static Point ToNative(this System.Drawing.Point value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Point ToNative(this System.Drawing.Point value) - { - return new(value.X, value.Y); - } + return new(value.X, value.Y); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Point ToNative(this System.Drawing.PointF value) - { - return new(value.X, value.Y); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static Point ToNative(this System.Drawing.PointF value) + { + return new(value.X, value.Y); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.PointF FromNative(this Point value) - { - return new((float)value.X, (float)value.Y); - } + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.PointF FromNative(this Point value) + { + return new((float)value.X, (float)value.Y); } } diff --git a/src/Splat.Drawing/Platforms/net4/Maths/RectExtensions.cs b/src/Splat.Drawing/Platforms/net4/Maths/RectExtensions.cs index 59a8618fa..74498ae21 100644 --- a/src/Splat.Drawing/Platforms/net4/Maths/RectExtensions.cs +++ b/src/Splat.Drawing/Platforms/net4/Maths/RectExtensions.cs @@ -5,41 +5,40 @@ using System.Windows; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing rectangle's and a native rectangle classes. +/// +public static class RectExtensions { /// - /// A set of extension methods which will convert between System.Drawing rectangle's and a native rectangle classes. + /// Convert a to the android native . /// - public static class RectExtensions + /// The value to convert. + /// A of the value. + public static Rect ToNative(this System.Drawing.Rectangle value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Rect ToNative(this System.Drawing.Rectangle value) - { - return new(value.X, value.Y, value.Width, value.Height); - } + return new(value.X, value.Y, value.Width, value.Height); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Rect ToNative(this System.Drawing.RectangleF value) - { - return new(value.X, value.Y, value.Width, value.Height); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static Rect ToNative(this System.Drawing.RectangleF value) + { + return new(value.X, value.Y, value.Width, value.Height); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.RectangleF FromNative(this Rect value) - { - return new((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height); - } + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.RectangleF FromNative(this Rect value) + { + return new((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height); } } diff --git a/src/Splat.Drawing/Platforms/net4/Maths/SizeExtensions.cs b/src/Splat.Drawing/Platforms/net4/Maths/SizeExtensions.cs index 985aaa171..4bf3881ac 100644 --- a/src/Splat.Drawing/Platforms/net4/Maths/SizeExtensions.cs +++ b/src/Splat.Drawing/Platforms/net4/Maths/SizeExtensions.cs @@ -5,41 +5,40 @@ using System.Windows; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing size's and a native size classes. +/// +public static class SizeExtensions { /// - /// A set of extension methods which will convert between System.Drawing size's and a native size classes. + /// Convert a to the android native . /// - public static class SizeExtensions + /// The value to convert. + /// A of the value. + public static Size ToNative(this System.Drawing.Size value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Size ToNative(this System.Drawing.Size value) - { - return new(value.Width, value.Height); - } + return new(value.Width, value.Height); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Size ToNative(this System.Drawing.SizeF value) - { - return new(value.Width, value.Height); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static Size ToNative(this System.Drawing.SizeF value) + { + return new(value.Width, value.Height); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.SizeF FromNative(this Size value) - { - return new((float)value.Width, (float)value.Height); - } + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.SizeF FromNative(this Size value) + { + return new((float)value.Width, (float)value.Height); } } diff --git a/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs index 88d77115d..8c2c4cb8c 100644 --- a/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs +++ b/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapMixins.cs @@ -6,36 +6,35 @@ using System; using System.Windows.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// Extension methods to assist with dealing with Bitmaps. +/// +public static class BitmapMixins { /// - /// Extension methods to assist with dealing with Bitmaps. + /// Converts to a native type. /// - public static class BitmapMixins + /// The bitmap to convert. + /// A bitmap. + public static IBitmap FromNative(this BitmapSource value) { - /// - /// Converts to a native type. - /// - /// The bitmap to convert. - /// A bitmap. - public static IBitmap FromNative(this BitmapSource value) - { - return new BitmapSourceBitmap(value); - } + return new BitmapSourceBitmap(value); + } - /// - /// Converts a to a splat . - /// - /// The native bitmap to convert from. - /// A bitmap. - public static BitmapSource ToNative(this IBitmap value) + /// + /// Converts a to a splat . + /// + /// The native bitmap to convert from. + /// A bitmap. + public static BitmapSource ToNative(this IBitmap value) + { + if (value is null) { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - return ((BitmapSourceBitmap)value).Inner ?? throw new InvalidOperationException("The bitmap is not longer valid"); + throw new System.ArgumentNullException(nameof(value)); } + + return ((BitmapSourceBitmap)value).Inner ?? throw new InvalidOperationException("The bitmap is not longer valid"); } } diff --git a/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapSourceBitmap.cs b/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapSourceBitmap.cs index 4c0efc423..0a609f0ee 100644 --- a/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapSourceBitmap.cs +++ b/src/Splat.Drawing/Platforms/net6/Bitmaps/BitmapSourceBitmap.cs @@ -8,56 +8,55 @@ using System.Threading.Tasks; using System.Windows.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// A bitmap that wraps a . +/// +internal sealed class BitmapSourceBitmap : IBitmap { /// - /// A bitmap that wraps a . + /// Initializes a new instance of the class. /// - internal sealed class BitmapSourceBitmap : IBitmap + /// The platform native bitmap we are wrapping. + public BitmapSourceBitmap(BitmapSource bitmap) { - /// - /// Initializes a new instance of the class. - /// - /// The platform native bitmap we are wrapping. - public BitmapSourceBitmap(BitmapSource bitmap) - { - Inner = bitmap; - } + Inner = bitmap; + } - /// - public float Width => (float)(Inner?.Width ?? 0); + /// + public float Width => (float)(Inner?.Width ?? 0); - /// - public float Height => (float)(Inner?.Height ?? 0); + /// + public float Height => (float)(Inner?.Height ?? 0); - /// - /// Gets the platform . - /// - public BitmapSource? Inner { get; private set; } + /// + /// Gets the platform . + /// + public BitmapSource? Inner { get; private set; } - /// - public Task Save(CompressedBitmapFormat format, float quality, Stream target) + /// + public Task Save(CompressedBitmapFormat format, float quality, Stream target) + { + if (target is null) { - if (target is null) - { - throw new ArgumentNullException(nameof(target)); - } - - return Task.Run(() => - { - var encoder = format == CompressedBitmapFormat.Jpeg ? - new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } : - (BitmapEncoder)new PngBitmapEncoder(); - - encoder.Frames.Add(BitmapFrame.Create(Inner)); - encoder.Save(target); - }); + throw new ArgumentNullException(nameof(target)); } - /// - public void Dispose() + return Task.Run(() => { - Inner = null; - } + var encoder = format == CompressedBitmapFormat.Jpeg ? + new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } : + (BitmapEncoder)new PngBitmapEncoder(); + + encoder.Frames.Add(BitmapFrame.Create(Inner)); + encoder.Save(target); + }); + } + + /// + public void Dispose() + { + Inner = null; } } diff --git a/src/Splat.Drawing/Platforms/net6/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/net6/Bitmaps/PlatformBitmapLoader.cs index 00372b59e..d7bec2e54 100644 --- a/src/Splat.Drawing/Platforms/net6/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/net6/Bitmaps/PlatformBitmapLoader.cs @@ -9,88 +9,87 @@ using System.Windows.Media; using System.Windows.Media.Imaging; -namespace Splat +namespace Splat; + +/// +/// A XAML based platform bitmap loader which will load our bitmaps for us. +/// +public class PlatformBitmapLoader : IBitmapLoader { - /// - /// A XAML based platform bitmap loader which will load our bitmaps for us. - /// - public class PlatformBitmapLoader : IBitmapLoader + /// + public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) { - /// - public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) + return Task.Run(() => { - return Task.Run(() => - { - var ret = new BitmapImage(); + var ret = new BitmapImage(); - WithInit(ret, source => + WithInit(ret, source => + { + if (desiredWidth is not null) { - if (desiredWidth is not null) - { - source.DecodePixelWidth = (int)desiredWidth; - } + source.DecodePixelWidth = (int)desiredWidth; + } - if (desiredHeight is not null) - { - source.DecodePixelHeight = (int)desiredHeight; - } - - source.StreamSource = sourceStream; - source.CacheOption = BitmapCacheOption.OnLoad; - }); + if (desiredHeight is not null) + { + source.DecodePixelHeight = (int)desiredHeight; + } - return new BitmapSourceBitmap(ret); + source.StreamSource = sourceStream; + source.CacheOption = BitmapCacheOption.OnLoad; }); - } - /// - public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + return new BitmapSourceBitmap(ret); + }); + } + + /// + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) + { + return Task.Run(() => { - return Task.Run(() => + var ret = new BitmapImage(); + WithInit(ret, x => { - var ret = new BitmapImage(); - WithInit(ret, x => + if (desiredWidth is not null) { - if (desiredWidth is not null) - { - x.DecodePixelWidth = (int)desiredWidth; - } + x.DecodePixelWidth = (int)desiredWidth; + } - if (desiredHeight is not null) - { - x.DecodePixelHeight = (int)desiredHeight; - } - - x.UriSource = new Uri(source, UriKind.RelativeOrAbsolute); - }); + if (desiredHeight is not null) + { + x.DecodePixelHeight = (int)desiredHeight; + } - return new BitmapSourceBitmap(ret); + x.UriSource = new Uri(source, UriKind.RelativeOrAbsolute); }); - } - /// - public IBitmap Create(float width, float height) - { - /* - * Taken from MSDN: - * - * The preferred values for pixelFormat are Bgr32 and Pbgra32. - * These formats are natively supported and do not require a format conversion. - * Other pixelFormat values require a format conversion for each frame update, which reduces performance. - */ - return new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32, null)); - } + return new BitmapSourceBitmap(ret); + }); + } - private static void WithInit(BitmapImage source, Action block) - { - source.BeginInit(); - block(source); - source.EndInit(); + /// + public IBitmap Create(float width, float height) + { + /* + * Taken from MSDN: + * + * The preferred values for pixelFormat are Bgr32 and Pbgra32. + * These formats are natively supported and do not require a format conversion. + * Other pixelFormat values require a format conversion for each frame update, which reduces performance. + */ + return new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32, null)); + } - if (source.CanFreeze) - { - source.Freeze(); - } + private static void WithInit(BitmapImage source, Action block) + { + source.BeginInit(); + block(source); + source.EndInit(); + + if (source.CanFreeze) + { + source.Freeze(); } } } diff --git a/src/Splat.Drawing/Platforms/net6/Colors/ColorExtensions.cs b/src/Splat.Drawing/Platforms/net6/Colors/ColorExtensions.cs index cbb6ba1f1..b069f6358 100644 --- a/src/Splat.Drawing/Platforms/net6/Colors/ColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/net6/Colors/ColorExtensions.cs @@ -5,43 +5,42 @@ using System.Windows.Media; -namespace Splat +namespace Splat; + +/// +/// Provides extension methods for interacting with colors, to and from the XAML colors. +/// +public static class ColorExtensions { /// - /// Provides extension methods for interacting with colors, to and from the XAML colors. + /// Converts a to a XAML native color. /// - public static class ColorExtensions + /// The System.Drawing.Color to convert. + /// A native XAML color. + public static Color ToNative(this System.Drawing.Color value) { - /// - /// Converts a to a XAML native color. - /// - /// The System.Drawing.Color to convert. - /// A native XAML color. - public static Color ToNative(this System.Drawing.Color value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } + return Color.FromArgb(value.A, value.R, value.G, value.B); + } - /// - /// Converts a into the cocoa native . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value) - { - var ret = new SolidColorBrush(value.ToNative()); - ret.Freeze(); - return ret; - } + /// + /// Converts a into the cocoa native . + /// + /// The color to convert. + /// The generated. + public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value) + { + var ret = new SolidColorBrush(value.ToNative()); + ret.Freeze(); + return ret; + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static System.Drawing.Color FromNative(this Color value) - { - return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B); - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static System.Drawing.Color FromNative(this Color value) + { + return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B); } } diff --git a/src/Splat.Drawing/Platforms/net6/Colors/SplatColorExtensions.cs b/src/Splat.Drawing/Platforms/net6/Colors/SplatColorExtensions.cs index 0043854e9..b2d93c664 100644 --- a/src/Splat.Drawing/Platforms/net6/Colors/SplatColorExtensions.cs +++ b/src/Splat.Drawing/Platforms/net6/Colors/SplatColorExtensions.cs @@ -5,43 +5,42 @@ using System.Windows.Media; -namespace Splat +namespace Splat; + +/// +/// Extension methods associated with the struct. +/// +public static class SplatColorExtensions { /// - /// Extension methods associated with the struct. + /// Converts a into the XAML . /// - public static class SplatColorExtensions + /// The color to convert. + /// The generated. + public static Color ToNative(this SplatColor value) { - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static Color ToNative(this SplatColor value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } + return Color.FromArgb(value.A, value.R, value.G, value.B); + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this SplatColor value) - { - var ret = new SolidColorBrush(value.ToNative()); - ret.Freeze(); - return ret; - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static SolidColorBrush ToNativeBrush(this SplatColor value) + { + var ret = new SolidColorBrush(value.ToNative()); + ret.Freeze(); + return ret; + } - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SplatColor FromNative(this Color value) - { - return SplatColor.FromArgb(value.A, value.R, value.G, value.B); - } + /// + /// Converts a into the XAML . + /// + /// The color to convert. + /// The generated. + public static SplatColor FromNative(this Color value) + { + return SplatColor.FromArgb(value.A, value.R, value.G, value.B); } } diff --git a/src/Splat.Drawing/Platforms/net6/Maths/PointExtensions.cs b/src/Splat.Drawing/Platforms/net6/Maths/PointExtensions.cs index 4691adeac..b84cc50d2 100644 --- a/src/Splat.Drawing/Platforms/net6/Maths/PointExtensions.cs +++ b/src/Splat.Drawing/Platforms/net6/Maths/PointExtensions.cs @@ -5,41 +5,40 @@ using System.Windows; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing point's and a native point classes. +/// +public static class PointExtensions { /// - /// A set of extension methods which will convert between System.Drawing point's and a native point classes. + /// Convert a to the android native . /// - public static class PointExtensions + /// The value to convert. + /// A of the value. + public static Point ToNative(this System.Drawing.Point value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Point ToNative(this System.Drawing.Point value) - { - return new Point(value.X, value.Y); - } + return new Point(value.X, value.Y); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Point ToNative(this System.Drawing.PointF value) - { - return new Point(value.X, value.Y); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static Point ToNative(this System.Drawing.PointF value) + { + return new Point(value.X, value.Y); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.PointF FromNative(this Point value) - { - return new((float)value.X, (float)value.Y); - } + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.PointF FromNative(this Point value) + { + return new((float)value.X, (float)value.Y); } } diff --git a/src/Splat.Drawing/Platforms/net6/Maths/RectExtensions.cs b/src/Splat.Drawing/Platforms/net6/Maths/RectExtensions.cs index d4d03058e..dab9adeb5 100644 --- a/src/Splat.Drawing/Platforms/net6/Maths/RectExtensions.cs +++ b/src/Splat.Drawing/Platforms/net6/Maths/RectExtensions.cs @@ -5,41 +5,40 @@ using System.Windows; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing rectangle's and a native rectangle classes. +/// +public static class RectExtensions { /// - /// A set of extension methods which will convert between System.Drawing rectangle's and a native rectangle classes. + /// Convert a to the android native . /// - public static class RectExtensions + /// The value to convert. + /// A of the value. + public static Rect ToNative(this System.Drawing.Rectangle value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Rect ToNative(this System.Drawing.Rectangle value) - { - return new Rect(value.X, value.Y, value.Width, value.Height); - } + return new Rect(value.X, value.Y, value.Width, value.Height); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Rect ToNative(this System.Drawing.RectangleF value) - { - return new Rect(value.X, value.Y, value.Width, value.Height); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static Rect ToNative(this System.Drawing.RectangleF value) + { + return new Rect(value.X, value.Y, value.Width, value.Height); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.RectangleF FromNative(this Rect value) - { - return new((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height); - } + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.RectangleF FromNative(this Rect value) + { + return new((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height); } } diff --git a/src/Splat.Drawing/Platforms/net6/Maths/SizeExtensions.cs b/src/Splat.Drawing/Platforms/net6/Maths/SizeExtensions.cs index 41534d9e5..fbd6d59c2 100644 --- a/src/Splat.Drawing/Platforms/net6/Maths/SizeExtensions.cs +++ b/src/Splat.Drawing/Platforms/net6/Maths/SizeExtensions.cs @@ -5,41 +5,40 @@ using System.Windows; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods which will convert between System.Drawing size's and a native size classes. +/// +public static class SizeExtensions { /// - /// A set of extension methods which will convert between System.Drawing size's and a native size classes. + /// Convert a to the android native . /// - public static class SizeExtensions + /// The value to convert. + /// A of the value. + public static Size ToNative(this System.Drawing.Size value) { - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Size ToNative(this System.Drawing.Size value) - { - return new Size(value.Width, value.Height); - } + return new Size(value.Width, value.Height); + } - /// - /// Convert a to the android native . - /// - /// The value to convert. - /// A of the value. - public static Size ToNative(this System.Drawing.SizeF value) - { - return new Size(value.Width, value.Height); - } + /// + /// Convert a to the android native . + /// + /// The value to convert. + /// A of the value. + public static Size ToNative(this System.Drawing.SizeF value) + { + return new Size(value.Width, value.Height); + } - /// - /// Converts a to a . - /// - /// The value to convert. - /// A of the value. - public static System.Drawing.SizeF FromNative(this Size value) - { - return new((float)value.Width, (float)value.Height); - } + /// + /// Converts a to a . + /// + /// The value to convert. + /// A of the value. + public static System.Drawing.SizeF FromNative(this Size value) + { + return new((float)value.Width, (float)value.Height); } } diff --git a/src/Splat.Drawing/Splat.Drawing.csproj b/src/Splat.Drawing/Splat.Drawing.csproj index 22bf3ba97..7a68ffeb9 100644 --- a/src/Splat.Drawing/Splat.Drawing.csproj +++ b/src/Splat.Drawing/Splat.Drawing.csproj @@ -17,6 +17,10 @@ true + + + + diff --git a/src/Splat.DryIoc.Tests/DependencyResolverTests.cs b/src/Splat.DryIoc.Tests/DependencyResolverTests.cs index b61830188..1f9dc4712 100644 --- a/src/Splat.DryIoc.Tests/DependencyResolverTests.cs +++ b/src/Splat.DryIoc.Tests/DependencyResolverTests.cs @@ -11,315 +11,314 @@ using Splat.Common.Test; using Xunit; -namespace Splat.DryIoc.Tests +namespace Splat.DryIoc.Tests; + +/// +/// Tests to show the works correctly. +/// +public class DependencyResolverTests { /// - /// Tests to show the works correctly. + /// Shoulds the resolve nulls. /// - public class DependencyResolverTests + [Fact] //// (Skip = "Further investigation required")] + public void Can_Register_And_Resolve_Null_Types() { - /// - /// Shoulds the resolve nulls. - /// - [Fact] //// (Skip = "Further investigation required")] - public void Can_Register_And_Resolve_Null_Types() - { - var builder = new Container(); - builder.UseDryIocDependencyResolver(); + var builder = new Container(); + builder.UseDryIocDependencyResolver(); - var foo = 5; - Assert.Throws(() => Locator.CurrentMutable.Register(() => foo, null)); + var foo = 5; + Assert.Throws(() => Locator.CurrentMutable.Register(() => foo, null)); - // Tests skipped as functionality removed. + // Tests skipped as functionality removed. #if SKIP_TEST - var bar = 4; - var contract = "foo"; - Locator.CurrentMutable.Register(() => bar, null, contract); - - Assert.True(Locator.CurrentMutable.HasRegistration(null)); - var value = Locator.Current.GetService(null); - Assert.Equal(foo, value); - - Assert.True(Locator.CurrentMutable.HasRegistration(null, contract)); - value = Locator.Current.GetService(null, contract); - Assert.Equal(bar, value); - - var values = Locator.Current.GetServices(null); - Assert.Equal(foo, (int)values.First()); - Assert.Equal(1, values.Count()); - - Locator.CurrentMutable.UnregisterCurrent(null); - var valuesNC = Locator.Current.GetServices(null); - Assert.Equal(0, valuesNC.Count()); - var valuesC = Locator.Current.GetServices(null, contract); - Assert.Equal(1, valuesC.Count()); - - Locator.CurrentMutable.UnregisterAll(null); - valuesNC = Locator.Current.GetServices(null); - Assert.Equal(0, valuesNC.Count()); - - Locator.CurrentMutable.UnregisterAll(null, contract); - valuesC = Locator.Current.GetServices(null, contract); - Assert.Equal(0, valuesC.Count()); + var bar = 4; + var contract = "foo"; + Locator.CurrentMutable.Register(() => bar, null, contract); + + Assert.True(Locator.CurrentMutable.HasRegistration(null)); + var value = Locator.Current.GetService(null); + Assert.Equal(foo, value); + + Assert.True(Locator.CurrentMutable.HasRegistration(null, contract)); + value = Locator.Current.GetService(null, contract); + Assert.Equal(bar, value); + + var values = Locator.Current.GetServices(null); + Assert.Equal(foo, (int)values.First()); + Assert.Equal(1, values.Count()); + + Locator.CurrentMutable.UnregisterCurrent(null); + var valuesNC = Locator.Current.GetServices(null); + Assert.Equal(0, valuesNC.Count()); + var valuesC = Locator.Current.GetServices(null, contract); + Assert.Equal(1, valuesC.Count()); + + Locator.CurrentMutable.UnregisterAll(null); + valuesNC = Locator.Current.GetServices(null); + Assert.Equal(0, valuesNC.Count()); + + Locator.CurrentMutable.UnregisterAll(null, contract); + valuesC = Locator.Current.GetServices(null, contract); + Assert.Equal(0, valuesC.Count()); #endif - } + } - /// - /// Should resolve the views. - /// - [Fact] - public void DryIocDependencyResolver_Should_Register_But_Not_Create_Views() - { - var container = new Container(); - container.UseDryIocDependencyResolver(); - - Splat.Locator.CurrentMutable.Register(() => new ViewThatShouldNotLoad(), typeof(IViewFor)); - Assert.Throws(() => Locator.Current.GetService>()); - } - - /// - /// Should resolve the views. - /// - [Fact] - public void DryIocDependencyResolver_Should_Register_With_Contract_But_Not_Create_Views() - { - var container = new Container(); - container.UseDryIocDependencyResolver(); - - Splat.Locator.CurrentMutable.Register(() => new ViewThatShouldNotLoad(), typeof(IViewFor), "name"); - Assert.Throws(() => Locator.Current.GetService>("name")); - } - - /// - /// Should resolve the views. - /// - [Fact] - public void DryIocDependencyResolver_Should_Resolve_Views() - { - var container = new Container(); - container.Register, ViewOne>(); - container.Register, ViewTwo>(); - container.UseDryIocDependencyResolver(); - - var viewOne = Locator.Current.GetService(typeof(IViewFor)); - var viewTwo = Locator.Current.GetService(typeof(IViewFor)); - - viewOne.Should().NotBeNull(); - viewOne.Should().BeOfType(); - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Should resolve the views. - /// - [Fact] - public void DryIocDependencyResolver_Should_Resolve_Named_View() - { - var container = new Container(); - container.Register, ViewTwo>(serviceKey: "Other"); - container.UseDryIocDependencyResolver(); + /// + /// Should resolve the views. + /// + [Fact] + public void DryIocDependencyResolver_Should_Register_But_Not_Create_Views() + { + var container = new Container(); + container.UseDryIocDependencyResolver(); - var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other"); + Splat.Locator.CurrentMutable.Register(() => new ViewThatShouldNotLoad(), typeof(IViewFor)); + Assert.Throws(() => Locator.Current.GetService>()); + } - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } + /// + /// Should resolve the views. + /// + [Fact] + public void DryIocDependencyResolver_Should_Register_With_Contract_But_Not_Create_Views() + { + var container = new Container(); + container.UseDryIocDependencyResolver(); - /// - /// Should resolve the view models. - /// - [Fact] - public void DryIocDependencyResolver_Should_Resolve_View_Models() - { - var container = new Container(); - container.Register(); - container.Register(); - container.UseDryIocDependencyResolver(); + Splat.Locator.CurrentMutable.Register(() => new ViewThatShouldNotLoad(), typeof(IViewFor), "name"); + Assert.Throws(() => Locator.Current.GetService>("name")); + } - Splat.Locator.CurrentMutable.Register(() => new ViewThatShouldNotLoad(), typeof(IViewFor), "name"); + /// + /// Should resolve the views. + /// + [Fact] + public void DryIocDependencyResolver_Should_Resolve_Views() + { + var container = new Container(); + container.Register, ViewOne>(); + container.Register, ViewTwo>(); + container.UseDryIocDependencyResolver(); + + var viewOne = Locator.Current.GetService(typeof(IViewFor)); + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewOne.Should().NotBeNull(); + viewOne.Should().BeOfType(); + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } - var vmOne = Locator.Current.GetService(); - var vmTwo = Locator.Current.GetService(); + /// + /// Should resolve the views. + /// + [Fact] + public void DryIocDependencyResolver_Should_Resolve_Named_View() + { + var container = new Container(); + container.Register, ViewTwo>(serviceKey: "Other"); + container.UseDryIocDependencyResolver(); - vmOne.Should().NotBeNull(); - vmTwo.Should().NotBeNull(); - } + var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other"); - /// - /// Should resolve the screen. - /// - [Fact] - public void DryIocDependencyResolver_Should_Resolve_Screen() - { - var builder = new Container(); - builder.Register(Reuse.Singleton); - builder.UseDryIocDependencyResolver(); + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } - var screen = Locator.Current.GetService(); + /// + /// Should resolve the view models. + /// + [Fact] + public void DryIocDependencyResolver_Should_Resolve_View_Models() + { + var container = new Container(); + container.Register(); + container.Register(); + container.UseDryIocDependencyResolver(); - screen.Should().NotBeNull(); - screen.Should().BeOfType(); - } + Splat.Locator.CurrentMutable.Register(() => new ViewThatShouldNotLoad(), typeof(IViewFor), "name"); - /// - /// Should unregister the screen. - /// - [Fact] - public void DryIocDependencyResolver_Should_UnregisterCurrent_Screen() - { - var builder = new Container(); - builder.Register(Reuse.Singleton); - builder.UseDryIocDependencyResolver(); + var vmOne = Locator.Current.GetService(); + var vmTwo = Locator.Current.GetService(); - Locator.Current.GetService().Should().NotBeNull(); + vmOne.Should().NotBeNull(); + vmTwo.Should().NotBeNull(); + } - Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); + /// + /// Should resolve the screen. + /// + [Fact] + public void DryIocDependencyResolver_Should_Resolve_Screen() + { + var builder = new Container(); + builder.Register(Reuse.Singleton); + builder.UseDryIocDependencyResolver(); - Locator.Current.GetService().Should().BeNull(); - } + var screen = Locator.Current.GetService(); - /// - /// Should unregister the screen. - /// - [Fact] - public void DryIocDependencyResolver_Should_UnregisterCurrent_Screen_With_Contract() - { - var builder = new Container(); - builder.Register(Reuse.Singleton, serviceKey: nameof(MockScreen)); - builder.UseDryIocDependencyResolver(); + screen.Should().NotBeNull(); + screen.Should().BeOfType(); + } - Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); + /// + /// Should unregister the screen. + /// + [Fact] + public void DryIocDependencyResolver_Should_UnregisterCurrent_Screen() + { + var builder = new Container(); + builder.Register(Reuse.Singleton); + builder.UseDryIocDependencyResolver(); - Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen), nameof(MockScreen)); + Locator.Current.GetService().Should().NotBeNull(); - Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); - } + Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); - /// - /// Should unregister the screen. - /// - [Fact] - public void DryIocDependencyResolver_Should_UnregisterAll_Screen() - { - var builder = new Container(); - builder.Register(Reuse.Singleton); - builder.UseDryIocDependencyResolver(); + Locator.Current.GetService().Should().BeNull(); + } - Locator.Current.GetService().Should().NotBeNull(); + /// + /// Should unregister the screen. + /// + [Fact] + public void DryIocDependencyResolver_Should_UnregisterCurrent_Screen_With_Contract() + { + var builder = new Container(); + builder.Register(Reuse.Singleton, serviceKey: nameof(MockScreen)); + builder.UseDryIocDependencyResolver(); - Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); + Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); - Locator.Current.GetService().Should().BeNull(); - } + Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen), nameof(MockScreen)); - /// - /// Should unregister the screen. - /// - [Fact] - public void DryIocDependencyResolver_Should_UnregisterAll_Screen_With_Contract() - { - var builder = new Container(); - builder.Register(Reuse.Singleton, serviceKey: nameof(MockScreen)); - builder.UseDryIocDependencyResolver(); + Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); + } - Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); + /// + /// Should unregister the screen. + /// + [Fact] + public void DryIocDependencyResolver_Should_UnregisterAll_Screen() + { + var builder = new Container(); + builder.Register(Reuse.Singleton); + builder.UseDryIocDependencyResolver(); - Locator.CurrentMutable.UnregisterAll(typeof(IScreen), nameof(MockScreen)); + Locator.Current.GetService().Should().NotBeNull(); - Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); - } + Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); - /// - /// Should throw an exception if service registration call back called. - /// - [Fact] - public void DryIocDependencyResolver_Should_Throw_If_ServiceRegistionCallback_Called() - { - var container = new Container(); - container.UseDryIocDependencyResolver(); - - var result = Record.Exception(() => - Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); - - result.Should().BeOfType(); - } - - /// - /// Check to ensure the correct logger is returned. - /// - /// - /// Introduced for Splat #331. - /// - [Fact] - public void DryIocDependencyResolver_Should_ReturnRegisteredLogger() - { - var c = new Container(); - c.UseDryIocDependencyResolver(); - c.Register(ifAlreadyRegistered: IfAlreadyRegistered.Replace); - Locator.CurrentMutable.RegisterConstant( - new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), - typeof(ILogManager)); - - var d = Splat.Locator.Current.GetService(); - Assert.IsType(d); - } - - /// - /// Test that a pre-init logger isn't overriden. - /// - /// - /// Introduced for Splat #331. - /// - [Fact] - public void DryIocDependencyResolver_PreInit_Should_ReturnRegisteredLogger() - { - var c = new Container(); - c.RegisterInstance(typeof(ILogManager), new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); - c.UseDryIocDependencyResolver(); - - var d = Splat.Locator.Current.GetService(); - Assert.IsType(d); - } - - /// - /// DryIoc dependency resolver should resolve after duplicate keyed registratoion. - /// - [Fact] - public void DryIocDependencyResolver_Should_Resolve_AfterDuplicateKeyedRegistration() - { - var container = new Container(); - container.UseDryIocDependencyResolver(); - Locator.CurrentMutable.Register(() => new ViewModelOne(), typeof(ViewModelOne), "ViewModelOne"); - Locator.CurrentMutable.Register(() => new ViewModelOne(), typeof(ViewModelOne), "ViewModelOne"); + Locator.Current.GetService().Should().BeNull(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void DryIocDependencyResolver_Should_UnregisterAll_Screen_With_Contract() + { + var builder = new Container(); + builder.Register(Reuse.Singleton, serviceKey: nameof(MockScreen)); + builder.UseDryIocDependencyResolver(); + + Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); - var vmOne = Locator.Current.GetService("ViewModelOne"); + Locator.CurrentMutable.UnregisterAll(typeof(IScreen), nameof(MockScreen)); - vmOne.Should().NotBeNull(); - } + Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); + } + + /// + /// Should throw an exception if service registration call back called. + /// + [Fact] + public void DryIocDependencyResolver_Should_Throw_If_ServiceRegistionCallback_Called() + { + var container = new Container(); + container.UseDryIocDependencyResolver(); + + var result = Record.Exception(() => + Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); + + result.Should().BeOfType(); + } - /// - /// DryIoc dependency resolver should create a resolved object only once when resolving. - /// - [Fact] - public void DryIocDependencyResolver_Should_Create_Once_When_Resolving() + /// + /// Check to ensure the correct logger is returned. + /// + /// + /// Introduced for Splat #331. + /// + [Fact] + public void DryIocDependencyResolver_Should_ReturnRegisteredLogger() + { + var c = new Container(); + c.UseDryIocDependencyResolver(); + c.Register(ifAlreadyRegistered: IfAlreadyRegistered.Replace); + Locator.CurrentMutable.RegisterConstant( + new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), + typeof(ILogManager)); + + var d = Splat.Locator.Current.GetService(); + Assert.IsType(d); + } + + /// + /// Test that a pre-init logger isn't overriden. + /// + /// + /// Introduced for Splat #331. + /// + [Fact] + public void DryIocDependencyResolver_PreInit_Should_ReturnRegisteredLogger() + { + var c = new Container(); + c.RegisterInstance(typeof(ILogManager), new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); + c.UseDryIocDependencyResolver(); + + var d = Splat.Locator.Current.GetService(); + Assert.IsType(d); + } + + /// + /// DryIoc dependency resolver should resolve after duplicate keyed registratoion. + /// + [Fact] + public void DryIocDependencyResolver_Should_Resolve_AfterDuplicateKeyedRegistration() + { + var container = new Container(); + container.UseDryIocDependencyResolver(); + Locator.CurrentMutable.Register(() => new ViewModelOne(), typeof(ViewModelOne), "ViewModelOne"); + Locator.CurrentMutable.Register(() => new ViewModelOne(), typeof(ViewModelOne), "ViewModelOne"); + + var vmOne = Locator.Current.GetService("ViewModelOne"); + + vmOne.Should().NotBeNull(); + } + + /// + /// DryIoc dependency resolver should create a resolved object only once when resolving. + /// + [Fact] + public void DryIocDependencyResolver_Should_Create_Once_When_Resolving() + { + var container = new Container(); + var count = 0; + container.RegisterDelegate(() => { - var container = new Container(); - var count = 0; - container.RegisterDelegate(() => - { - count++; - return new ViewModelOne(); - }); - - var resolver = new DryIocDependencyResolver(container); - - // Imitate a call to Locator.Current.GetService() - var vms = resolver.GetServices(typeof(ViewModelOne)); - count.Should().Be(1); - var vmOne = vms.LastOrDefault(); - vmOne.Should().NotBeNull(); - count.Should().Be(1); - } + count++; + return new ViewModelOne(); + }); + + var resolver = new DryIocDependencyResolver(container); + + // Imitate a call to Locator.Current.GetService() + var vms = resolver.GetServices(typeof(ViewModelOne)); + count.Should().Be(1); + var vmOne = vms.LastOrDefault(); + vmOne.Should().NotBeNull(); + count.Should().Be(1); } } diff --git a/src/Splat.DryIoc/DryIocDependencyResolver.cs b/src/Splat.DryIoc/DryIocDependencyResolver.cs index 91ebfe4c9..14f83a60e 100644 --- a/src/Splat.DryIoc/DryIocDependencyResolver.cs +++ b/src/Splat.DryIoc/DryIocDependencyResolver.cs @@ -10,238 +10,237 @@ using System.Linq.Expressions; using DryIoc; -namespace Splat.DryIoc +namespace Splat.DryIoc; + +/// +/// DryIoc implementation for . +/// https://bitbucket.org/dadhi/dryioc/wiki/Home. +/// +/// +public class DryIocDependencyResolver : IDependencyResolver { + private IContainer _container; + /// - /// DryIoc implementation for . - /// https://bitbucket.org/dadhi/dryioc/wiki/Home. + /// Initializes a new instance of the class. /// - /// - public class DryIocDependencyResolver : IDependencyResolver + /// The container. + public DryIocDependencyResolver(IContainer? container = null) { - private IContainer _container; + _container = container ?? new Container(); + } + + /// + public virtual object? GetService(Type? serviceType, string? contract = null) => + GetServices(serviceType, contract).LastOrDefault(); - /// - /// Initializes a new instance of the class. - /// - /// The container. - public DryIocDependencyResolver(IContainer? container = null) + /// + public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - _container = container ?? new Container(); + throw new ArgumentNullException(nameof(serviceType)); } - /// - public virtual object? GetService(Type? serviceType, string? contract = null) => - GetServices(serviceType, contract).LastOrDefault(); + var key = (serviceType, contract ?? string.Empty); + var registeredinSplat = _container.ResolveMany(serviceType, behavior: ResolveManyBehavior.AsFixedArray, serviceKey: key); + if (registeredinSplat.Any()) + { + return registeredinSplat; + } - /// - public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + var registeredWithContract = _container.ResolveMany(serviceType, behavior: ResolveManyBehavior.AsFixedArray, serviceKey: contract); + if (registeredWithContract.Any()) { - if (serviceType is null) - { - throw new ArgumentNullException(nameof(serviceType)); - } + return registeredWithContract; + } - var key = (serviceType, contract ?? string.Empty); - var registeredinSplat = _container.ResolveMany(serviceType, behavior: ResolveManyBehavior.AsFixedArray, serviceKey: key); - if (registeredinSplat.Any()) + return _container.ResolveMany(serviceType, behavior: ResolveManyBehavior.AsFixedArray); + } + + /// + public bool HasRegistration(Type? serviceType, string? contract = null) + { + if (serviceType is null) + { + throw new ArgumentNullException(nameof(serviceType)); + } + + return _container.GetServiceRegistrations().Any(x => + { + if (x.ServiceType != serviceType) { - return registeredinSplat; + return false; } - var registeredWithContract = _container.ResolveMany(serviceType, behavior: ResolveManyBehavior.AsFixedArray, serviceKey: contract); - if (registeredWithContract.Any()) + if (contract is null) { - return registeredWithContract; + return x.OptionalServiceKey is null; } - return _container.ResolveMany(serviceType, behavior: ResolveManyBehavior.AsFixedArray); + var key = (serviceType, contract ?? string.Empty); + + return key.Equals(x.OptionalServiceKey) || + (contract is null && x.OptionalServiceKey is null) || + (x.OptionalServiceKey is string serviceKeyAsString + && contract is not null && contract.Equals(serviceKeyAsString, StringComparison.Ordinal)); + }); + } + + /// + public virtual void Register(Func factory, Type? serviceType, string? contract = null) + { + if (factory is null) + { + throw new ArgumentNullException(nameof(factory)); } - /// - public bool HasRegistration(Type? serviceType, string? contract = null) + if (serviceType is null) { - if (serviceType is null) - { - throw new ArgumentNullException(nameof(serviceType)); - } + throw new ArgumentNullException(nameof(serviceType)); + } - return _container.GetServiceRegistrations().Any(x => - { - if (x.ServiceType != serviceType) - { - return false; - } - - if (contract is null) - { - return x.OptionalServiceKey is null; - } - - var key = (serviceType, contract ?? string.Empty); - - return key.Equals(x.OptionalServiceKey) || - (contract is null && x.OptionalServiceKey is null) || - (x.OptionalServiceKey is string serviceKeyAsString - && contract is not null && contract.Equals(serviceKeyAsString, StringComparison.Ordinal)); - }); + if (string.IsNullOrEmpty(contract)) + { + _container.RegisterDelegate( + serviceType, + context => CreateThenConvert(serviceType, factory), + ifAlreadyRegistered: IfAlreadyRegistered.AppendNewImplementation); + + return; + } + + var key = (serviceType, contract); + + if (HasRegistration(serviceType, contract)) + { + Trace.WriteLine($"Warning: Service {serviceType} already exists with key {contract}, the registration will be replaced."); + } + + // Keyed instances can only have a single instance so keep latest + _container.RegisterDelegate( + serviceType, + context => CreateThenConvert(serviceType, factory), + ifAlreadyRegistered: IfAlreadyRegistered.Replace, + serviceKey: key); + } + + /// + public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) + { + if (serviceType is null) + { + throw new ArgumentNullException(nameof(serviceType)); } - /// - public virtual void Register(Func factory, Type? serviceType, string? contract = null) + var key = (serviceType, contract ?? string.Empty); + var hadvalue = _container.GetServiceRegistrations().Any(x => { - if (factory is null) + if (x.ServiceType != serviceType) { - throw new ArgumentNullException(nameof(factory)); + return false; } - if (serviceType is null) + if (key.Equals(x.OptionalServiceKey)) { - throw new ArgumentNullException(nameof(serviceType)); + _container.Unregister(serviceType, key); + return true; } - if (string.IsNullOrEmpty(contract)) + if (contract is null && x.OptionalServiceKey is null) { - _container.RegisterDelegate( - serviceType, - context => CreateThenConvert(serviceType, factory), - ifAlreadyRegistered: IfAlreadyRegistered.AppendNewImplementation); - - return; + _container.Unregister(serviceType); + return true; } - var key = (serviceType, contract); - - if (HasRegistration(serviceType, contract)) + if (x.OptionalServiceKey is string serviceKeyAsString + && contract is not null && contract.Equals(serviceKeyAsString, StringComparison.Ordinal)) { - Trace.WriteLine($"Warning: Service {serviceType} already exists with key {contract}, the registration will be replaced."); + _container.Unregister(serviceType, contract); + return true; } - // Keyed instances can only have a single instance so keep latest - _container.RegisterDelegate( - serviceType, - context => CreateThenConvert(serviceType, factory), - ifAlreadyRegistered: IfAlreadyRegistered.Replace, - serviceKey: key); + return false; + }); + } + + /// + public virtual void UnregisterAll(Type? serviceType, string? contract = null) + { + if (serviceType is null) + { + throw new ArgumentNullException(nameof(serviceType)); } - /// - public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) + var key = (serviceType, contract ?? string.Empty); + foreach (var x in _container.GetServiceRegistrations()) { - if (serviceType is null) + if (x.ServiceType != serviceType) { - throw new ArgumentNullException(nameof(serviceType)); + continue; } - var key = (serviceType, contract ?? string.Empty); - var hadvalue = _container.GetServiceRegistrations().Any(x => + if (key.Equals(x.OptionalServiceKey)) { - if (x.ServiceType != serviceType) - { - return false; - } - - if (key.Equals(x.OptionalServiceKey)) - { - _container.Unregister(serviceType, key); - return true; - } - - if (contract is null && x.OptionalServiceKey is null) - { - _container.Unregister(serviceType); - return true; - } - - if (x.OptionalServiceKey is string serviceKeyAsString - && contract is not null && contract.Equals(serviceKeyAsString, StringComparison.Ordinal)) - { - _container.Unregister(serviceType, contract); - return true; - } - - return false; - }); - } + _container.Unregister(serviceType, key); + continue; + } - /// - public virtual void UnregisterAll(Type? serviceType, string? contract = null) - { - if (serviceType is null) + if (contract is null && x.OptionalServiceKey is null) { - throw new ArgumentNullException(nameof(serviceType)); + _container.Unregister(serviceType); + continue; } - var key = (serviceType, contract ?? string.Empty); - foreach (var x in _container.GetServiceRegistrations()) + if (x.OptionalServiceKey is string serviceKeyAsString + && contract is not null && contract.Equals(serviceKeyAsString, StringComparison.Ordinal)) { - if (x.ServiceType != serviceType) - { - continue; - } - - if (key.Equals(x.OptionalServiceKey)) - { - _container.Unregister(serviceType, key); - continue; - } - - if (contract is null && x.OptionalServiceKey is null) - { - _container.Unregister(serviceType); - continue; - } - - if (x.OptionalServiceKey is string serviceKeyAsString - && contract is not null && contract.Equals(serviceKeyAsString, StringComparison.Ordinal)) - { - _container.Unregister(serviceType, contract); - } + _container.Unregister(serviceType, contract); } } + } - /// - public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) - { - throw new NotImplementedException(); - } + /// + public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + { + throw new NotImplementedException(); + } - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } - /// - /// Disposes of the instance. - /// - /// Whether or not the instance is disposing. - protected virtual void Dispose(bool disposing) + /// + /// Disposes of the instance. + /// + /// Whether or not the instance is disposing. + protected virtual void Dispose(bool disposing) + { + if (disposing) { - if (disposing) - { - _container?.Dispose(); - } + _container?.Dispose(); } + } - private static object? CreateThenConvert(Type serviceType, Func factory) - { - // we need to cast because we pass an object back and dryioc wants it explicitly cast. - // alternative (happy to be proven wrong) is to break the interface and add a Register(...) method? - var instance = factory(); + private static object? CreateThenConvert(Type serviceType, Func factory) + { + // we need to cast because we pass an object back and dryioc wants it explicitly cast. + // alternative (happy to be proven wrong) is to break the interface and add a Register(...) method? + var instance = factory(); - return instance != null ? Cast(serviceType, instance) : null; - } + return instance != null ? Cast(serviceType, instance) : null; + } - private static object? Cast(Type type, object data) - { - // based upon https://stackoverflow.com/a/27584212 - var dataParam = Expression.Parameter(typeof(object), "data"); - var body = Expression.Block(Expression.Convert(Expression.Convert(dataParam, data.GetType()), type)); + private static object? Cast(Type type, object data) + { + // based upon https://stackoverflow.com/a/27584212 + var dataParam = Expression.Parameter(typeof(object), "data"); + var body = Expression.Block(Expression.Convert(Expression.Convert(dataParam, data.GetType()), type)); - var run = Expression.Lambda(body, dataParam).Compile(); - return run.DynamicInvoke(data); - } + var run = Expression.Lambda(body, dataParam).Compile(); + return run.DynamicInvoke(data); } } diff --git a/src/Splat.DryIoc/Splat.DryIoc.csproj b/src/Splat.DryIoc/Splat.DryIoc.csproj index 9b0816ede..1683eda55 100644 --- a/src/Splat.DryIoc/Splat.DryIoc.csproj +++ b/src/Splat.DryIoc/Splat.DryIoc.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/Splat.DryIoc/SplatDryIocExtensions.cs b/src/Splat.DryIoc/SplatDryIocExtensions.cs index b6e06ea0e..fe22421d8 100644 --- a/src/Splat.DryIoc/SplatDryIocExtensions.cs +++ b/src/Splat.DryIoc/SplatDryIocExtensions.cs @@ -5,18 +5,17 @@ using DryIoc; -namespace Splat.DryIoc +namespace Splat.DryIoc; + +/// +/// Extension methods for the DryIoc adapter. +/// +public static class SplatDryIocExtensions { /// - /// Extension methods for the DryIoc adapter. + /// Initializes an instance of that overrides the default . /// - public static class SplatDryIocExtensions - { - /// - /// Initializes an instance of that overrides the default . - /// - /// The container. - public static void UseDryIocDependencyResolver(this IContainer container) => - Locator.SetLocator(new DryIocDependencyResolver(container)); - } + /// The container. + public static void UseDryIocDependencyResolver(this IContainer container) => + Locator.SetLocator(new DryIocDependencyResolver(container)); } diff --git a/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs b/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs index 088c7c081..f445801f0 100644 --- a/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs +++ b/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs @@ -7,77 +7,76 @@ using Exceptionless; using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// Feature Usage Tracking integration for Exceptionless. +/// +public sealed class ExceptionlessFeatureUsageTrackingSession : IFeatureUsageTrackingSession { /// - /// Feature Usage Tracking integration for Exceptionless. + /// Initializes a new instance of the class. /// - public sealed class ExceptionlessFeatureUsageTrackingSession : IFeatureUsageTrackingSession + /// Name of the feature. + public ExceptionlessFeatureUsageTrackingSession(string featureName) + : this(featureName, Guid.Empty) { - /// - /// Initializes a new instance of the class. - /// - /// Name of the feature. - public ExceptionlessFeatureUsageTrackingSession(string featureName) - : this(featureName, Guid.Empty) - { - } + } - internal ExceptionlessFeatureUsageTrackingSession( - string featureName, - Guid parentReference) + internal ExceptionlessFeatureUsageTrackingSession( + string featureName, + Guid parentReference) + { + if (string.IsNullOrWhiteSpace(featureName)) { - if (string.IsNullOrWhiteSpace(featureName)) - { - throw new ArgumentNullException(nameof(featureName)); - } - - ParentReference = parentReference; - FeatureName = featureName; - FeatureReference = Guid.NewGuid(); + throw new ArgumentNullException(nameof(featureName)); + } - var client = ExceptionlessClient.Default; - var eventBuilder = client.CreateFeatureUsage(featureName); + ParentReference = parentReference; + FeatureName = featureName; + FeatureReference = Guid.NewGuid(); - if (!parentReference.Equals(Guid.Empty)) - { - eventBuilder.SetEventReference(FeatureName, FeatureReference.ToString()); - } + var client = ExceptionlessClient.Default; + var eventBuilder = client.CreateFeatureUsage(featureName); - eventBuilder.SetReferenceId(FeatureReference.ToString()); - eventBuilder.Submit(); + if (!parentReference.Equals(Guid.Empty)) + { + eventBuilder.SetEventReference(FeatureName, FeatureReference.ToString()); } - /// - public Guid ParentReference { get; } + eventBuilder.SetReferenceId(FeatureReference.ToString()); + eventBuilder.Submit(); + } - /// - public Guid FeatureReference { get; } + /// + public Guid ParentReference { get; } - /// - public string FeatureName { get; } + /// + public Guid FeatureReference { get; } - /// - public IFeatureUsageTrackingSession SubFeature(string description) - { - return new ExceptionlessFeatureUsageTrackingSession( - description, - FeatureReference); - } + /// + public string FeatureName { get; } - /// - public void OnException(Exception exception) - { - var eventBuilder = exception.ToExceptionless() - .SetEventReference(FeatureName, ParentReference.ToString()) - .SetReferenceId(FeatureReference.ToString()); + /// + public IFeatureUsageTrackingSession SubFeature(string description) + { + return new ExceptionlessFeatureUsageTrackingSession( + description, + FeatureReference); + } - eventBuilder.Submit(); - } + /// + public void OnException(Exception exception) + { + var eventBuilder = exception.ToExceptionless() + .SetEventReference(FeatureName, ParentReference.ToString()) + .SetReferenceId(FeatureReference.ToString()); - /// - public void Dispose() - { - } + eventBuilder.Submit(); + } + + /// + public void Dispose() + { } } diff --git a/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs b/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs index 410fd53ec..bdb2fb5fa 100644 --- a/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs +++ b/src/Splat.Exceptionless/ExceptionlessSplatLogger.cs @@ -10,178 +10,177 @@ using System.Linq; using Exceptionless; -namespace Splat.Exceptionless +namespace Splat.Exceptionless; + +/// +/// Exceptionless Logger into Splat. +/// +[DebuggerDisplay("Name={_sourceType} Level={Level}")] +public sealed class ExceptionlessSplatLogger : ILogger { + private static readonly KeyValuePair[] _mappings = new[] + { + new KeyValuePair(LogLevel.Debug, global::Exceptionless.Logging.LogLevel.Debug), + new KeyValuePair(LogLevel.Info, global::Exceptionless.Logging.LogLevel.Info), + new KeyValuePair(LogLevel.Warn, global::Exceptionless.Logging.LogLevel.Warn), + new KeyValuePair(LogLevel.Error, global::Exceptionless.Logging.LogLevel.Error), + new KeyValuePair(LogLevel.Fatal, global::Exceptionless.Logging.LogLevel.Fatal), + }; + + private static readonly ImmutableDictionary _mappingsDictionary = _mappings.ToImmutableDictionary(); + + private readonly string _sourceType; + private readonly ExceptionlessClient _exceptionlessClient; + /// - /// Exceptionless Logger into Splat. + /// Initializes a new instance of the class. /// - [DebuggerDisplay("Name={_sourceType} Level={Level}")] - public sealed class ExceptionlessSplatLogger : ILogger + /// The type being tracked. + /// The exceptionless client instance to use. + public ExceptionlessSplatLogger( + Type sourceType, + ExceptionlessClient exceptionlessClient) { - private static readonly KeyValuePair[] _mappings = new[] - { - new KeyValuePair(LogLevel.Debug, global::Exceptionless.Logging.LogLevel.Debug), - new KeyValuePair(LogLevel.Info, global::Exceptionless.Logging.LogLevel.Info), - new KeyValuePair(LogLevel.Warn, global::Exceptionless.Logging.LogLevel.Warn), - new KeyValuePair(LogLevel.Error, global::Exceptionless.Logging.LogLevel.Error), - new KeyValuePair(LogLevel.Fatal, global::Exceptionless.Logging.LogLevel.Fatal) - }; - - private static readonly ImmutableDictionary _mappingsDictionary = _mappings.ToImmutableDictionary(); - - private readonly string _sourceType; - private readonly ExceptionlessClient _exceptionlessClient; - - /// - /// Initializes a new instance of the class. - /// - /// The type being tracked. - /// The exceptionless client instance to use. - public ExceptionlessSplatLogger( - Type sourceType, - ExceptionlessClient exceptionlessClient) + if (sourceType is null) { - if (sourceType is null) - { - throw new ArgumentNullException(nameof(sourceType)); - } - - _sourceType = sourceType.FullName ?? throw new ArgumentException("Cannot find the source type name", nameof(sourceType)); - _exceptionlessClient = exceptionlessClient ?? throw new ArgumentNullException(nameof(exceptionlessClient)); - _exceptionlessClient.Configuration.Changed += OnInnerLoggerReconfigured; - - if (_exceptionlessClient.Configuration.Settings.TryGetValue("@@log:*", out var logLevel)) - { - var l = global::Exceptionless.Logging.LogLevel.FromString(logLevel); - Level = _mappingsDictionary.First(x => x.Value == l).Key; - } + throw new ArgumentNullException(nameof(sourceType)); } - /// - public LogLevel Level { get; private set; } + _sourceType = sourceType.FullName ?? throw new ArgumentException("Cannot find the source type name", nameof(sourceType)); + _exceptionlessClient = exceptionlessClient ?? throw new ArgumentNullException(nameof(exceptionlessClient)); + _exceptionlessClient.Configuration.Changed += OnInnerLoggerReconfigured; - /// - public void Write(string message, LogLevel logLevel) + if (_exceptionlessClient.Configuration.Settings.TryGetValue("@@log:*", out var logLevel)) { - if ((int)logLevel < (int)Level) - { - return; - } - - CreateLog(message, _mappingsDictionary[logLevel]); + var l = global::Exceptionless.Logging.LogLevel.FromString(logLevel); + Level = _mappingsDictionary.First(x => x.Value == l).Key; } + } - /// - public void Write(Exception exception, string message, LogLevel logLevel) - { - if ((int)logLevel < (int)Level) - { - return; - } + /// + public LogLevel Level { get; private set; } - CreateLog(exception, message, _mappingsDictionary[logLevel]); + /// + public void Write(string message, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) + { + return; } - /// - public void Write(string message, Type type, LogLevel logLevel) + CreateLog(message, _mappingsDictionary[logLevel]); + } + + /// + public void Write(Exception exception, string message, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } + return; + } - if ((int)logLevel < (int)Level) - { - return; - } + CreateLog(exception, message, _mappingsDictionary[logLevel]); + } - CreateLog(type.FullName ?? "(unknown)", message, _mappingsDictionary[logLevel]); + /// + public void Write(string message, Type type, LogLevel logLevel) + { + if (type is null) + { + throw new ArgumentNullException(nameof(type)); } - /// - public void Write(Exception exception, string message, Type type, LogLevel logLevel) + if ((int)logLevel < (int)Level) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - if ((int)logLevel < (int)Level) - { - return; - } - - CreateLog(exception, type.FullName ?? "(unknown)", message, _mappingsDictionary[logLevel]); + return; } - private void CreateLog(string message, global::Exceptionless.Logging.LogLevel level) + CreateLog(type.FullName ?? "(unknown)", message, _mappingsDictionary[logLevel]); + } + + /// + public void Write(Exception exception, string message, Type type, LogLevel logLevel) + { + if (type is null) { - CreateLog(_sourceType, message, level); + throw new ArgumentNullException(nameof(type)); } - private void CreateLog(string type, string message, global::Exceptionless.Logging.LogLevel level) + if ((int)logLevel < (int)Level) { - _exceptionlessClient.SubmitLog(type, message, level); - _exceptionlessClient.ProcessQueue(); + return; } - private void CreateLog(Exception exception, string message, global::Exceptionless.Logging.LogLevel level) + CreateLog(exception, type.FullName ?? "(unknown)", message, _mappingsDictionary[logLevel]); + } + + 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) + { + _exceptionlessClient.SubmitLog(type, message, level); + _exceptionlessClient.ProcessQueue(); + } + + 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) + { + _exceptionlessClient.CreateLog( + type, + message, + level) + .SetException(exception) + .Submit(); + + _exceptionlessClient.ProcessQueue(); + } + + /// + /// Works out the log level. + /// + /// + /// This was done so the Level property doesn't keep getting re-evaluated each time a Write method is called. + /// + private void SetLogLevel() + { + /* + if (_inner.IsDebugEnabled) { - CreateLog(exception, _sourceType, message, level); + Level = LogLevel.Debug; + return; } - private void CreateLog(Exception exception, string type, string message, global::Exceptionless.Logging.LogLevel level) + if (_inner.IsInfoEnabled) { - _exceptionlessClient.CreateLog( - type, - message, - level) - .SetException(exception) - .Submit(); - - _exceptionlessClient.ProcessQueue(); + Level = LogLevel.Info; + return; } - /// - /// Works out the log level. - /// - /// - /// This was done so the Level property doesn't keep getting re-evaluated each time a Write method is called. - /// - private void SetLogLevel() + if (_inner.IsWarnEnabled) { - /* - if (_inner.IsDebugEnabled) - { - Level = LogLevel.Debug; - return; - } - - if (_inner.IsInfoEnabled) - { - Level = LogLevel.Info; - return; - } - - if (_inner.IsWarnEnabled) - { - Level = LogLevel.Warn; - return; - } - - if (_inner.IsErrorEnabled) - { - Level = LogLevel.Error; - return; - } - */ - - Level = LogLevel.Fatal; + Level = LogLevel.Warn; + return; } - private void OnInnerLoggerReconfigured(object? sender, EventArgs e) + if (_inner.IsErrorEnabled) { - SetLogLevel(); + Level = LogLevel.Error; + return; } + */ + + Level = LogLevel.Fatal; + } + + private void OnInnerLoggerReconfigured(object? sender, EventArgs e) + { + SetLogLevel(); } } diff --git a/src/Splat.Exceptionless/ExceptionlessViewTracking.cs b/src/Splat.Exceptionless/ExceptionlessViewTracking.cs index c191b802a..2aedbf194 100644 --- a/src/Splat.Exceptionless/ExceptionlessViewTracking.cs +++ b/src/Splat.Exceptionless/ExceptionlessViewTracking.cs @@ -4,44 +4,42 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Text; + using Exceptionless; -using Exceptionless.Plugins; + using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// Exceptionless View Tracking integration. +/// +public sealed class ExceptionlessViewTracking : IViewTracking { + private readonly ExceptionlessClient _exceptionlessClient; + + /// + /// Initializes a new instance of the class. + /// + /// The exceptionless client to use. + public ExceptionlessViewTracking(ExceptionlessClient exceptionlessClient) + { + _exceptionlessClient = exceptionlessClient ?? throw new ArgumentNullException(nameof(exceptionlessClient)); + } + /// - /// Exceptionless View Tracking integration. + /// Track a view navigation using just a name. /// - public sealed class ExceptionlessViewTracking : IViewTracking + /// Name of the view. + public void OnViewNavigation(string name) { - private readonly ExceptionlessClient _exceptionlessClient; - - /// - /// Initializes a new instance of the class. - /// - /// The exceptionless client to use. - public ExceptionlessViewTracking(ExceptionlessClient exceptionlessClient) - { - _exceptionlessClient = exceptionlessClient ?? throw new ArgumentNullException(nameof(exceptionlessClient)); - } - - /// - /// Track a view navigation using just a name. - /// - /// Name of the view. - public void OnViewNavigation(string name) - { - // need to consider whether to just use feature event - // and tag it with view specific properties. - var eventBuilder = _exceptionlessClient - .CreateEvent() - .SetType("PageView") - .SetMessage(name); - - eventBuilder.Submit(); - } + // need to consider whether to just use feature event + // and tag it with view specific properties. + var eventBuilder = _exceptionlessClient + .CreateEvent() + .SetType("PageView") + .SetMessage(name); + + eventBuilder.Submit(); } } diff --git a/src/Splat.Exceptionless/MutableDependencyResolverExtensions.cs b/src/Splat.Exceptionless/MutableDependencyResolverExtensions.cs index 9be869db6..bba38b1c1 100644 --- a/src/Splat.Exceptionless/MutableDependencyResolverExtensions.cs +++ b/src/Splat.Exceptionless/MutableDependencyResolverExtensions.cs @@ -5,37 +5,36 @@ using Exceptionless; -namespace Splat.Exceptionless +namespace Splat.Exceptionless; + +/// +/// Exceptionless specific extensions for the Mutable Dependency Resolver. +/// +public static class MutableDependencyResolverExtensions { /// - /// Exceptionless specific extensions for the Mutable Dependency Resolver. + /// Simple helper to initialize Exceptionless within Splat with the Wrapping Full Logger. /// - public static class MutableDependencyResolverExtensions + /// + /// You should configure Exceptionless prior to calling this method. + /// + /// + /// An instance of Mutable Dependency Resolver. + /// + /// The exceptionless client instance to use. + /// + /// + /// Locator.CurrentMutable.UseExceptionlessWithWrappingFullLogger(exception); + /// + /// + public static void UseExceptionlessWithWrappingFullLogger(this IMutableDependencyResolver instance, ExceptionlessClient exceptionlessClient) { - /// - /// Simple helper to initialize Exceptionless within Splat with the Wrapping Full Logger. - /// - /// - /// You should configure Exceptionless prior to calling this method. - /// - /// - /// An instance of Mutable Dependency Resolver. - /// - /// The exceptionless client instance to use. - /// - /// - /// Locator.CurrentMutable.UseExceptionlessWithWrappingFullLogger(exception); - /// - /// - public static void UseExceptionlessWithWrappingFullLogger(this IMutableDependencyResolver instance, ExceptionlessClient exceptionlessClient) + var funcLogManager = new FuncLogManager(type => { - var funcLogManager = new FuncLogManager(type => - { - var miniLoggingWrapper = new ExceptionlessSplatLogger(type, exceptionlessClient); - return new WrappingFullLogger(miniLoggingWrapper); - }); + var miniLoggingWrapper = new ExceptionlessSplatLogger(type, exceptionlessClient); + return new WrappingFullLogger(miniLoggingWrapper); + }); - instance.RegisterConstant(funcLogManager, typeof(ILogManager)); - } + instance.RegisterConstant(funcLogManager, typeof(ILogManager)); } } diff --git a/src/Splat.Log4Net/Log4NetLogger.cs b/src/Splat.Log4Net/Log4NetLogger.cs index 202988c8e..40d4a7729 100644 --- a/src/Splat.Log4Net/Log4NetLogger.cs +++ b/src/Splat.Log4Net/Log4NetLogger.cs @@ -6,202 +6,201 @@ using System; using System.Diagnostics; -namespace Splat.Log4Net +namespace Splat.Log4Net; + +/// +/// Log4Net Logger integration into Splat. +/// +[DebuggerDisplay("Name={_inner.Logger.Name} Level={Level}")] +public sealed class Log4NetLogger : ILogger, IDisposable { + private readonly global::log4net.ILog _inner; + /// - /// Log4Net Logger integration into Splat. + /// Initializes a new instance of the class. /// - [DebuggerDisplay("Name={_inner.Logger.Name} Level={Level}")] - public sealed class Log4NetLogger : ILogger, IDisposable + /// The actual log4net logger. + /// Log4Net logger not passed. + public Log4NetLogger(global::log4net.ILog inner) { - private readonly global::log4net.ILog _inner; - - /// - /// Initializes a new instance of the class. - /// - /// The actual log4net logger. - /// Log4Net logger not passed. - public Log4NetLogger(global::log4net.ILog inner) - { - _inner = inner ?? throw new ArgumentNullException(nameof(inner)); - SetLogLevel(); - _inner.Logger.Repository.ConfigurationChanged += OnInnerLoggerReconfigured; - } + _inner = inner ?? throw new ArgumentNullException(nameof(inner)); + SetLogLevel(); + _inner.Logger.Repository.ConfigurationChanged += OnInnerLoggerReconfigured; + } - /// - public LogLevel Level { get; private set; } + /// + public LogLevel Level { get; private set; } - /// - public void Dispose() + /// + public void Dispose() + { + _inner.Logger.Repository.ConfigurationChanged -= OnInnerLoggerReconfigured; + } + + /// + public void Write(string message, LogLevel logLevel) + { + switch (logLevel) { - _inner.Logger.Repository.ConfigurationChanged -= OnInnerLoggerReconfigured; + case LogLevel.Debug: + _inner.Debug(message); + + break; + case LogLevel.Info: + _inner.Info(message); + + break; + case LogLevel.Warn: + _inner.Warn(message); + + break; + case LogLevel.Error: + _inner.Error(message); + + break; + case LogLevel.Fatal: + _inner.Fatal(message); + + break; + default: + _inner.Debug(message); + + break; } + } - /// - public void Write(string message, LogLevel logLevel) + /// + public void Write(Exception exception, string message, LogLevel logLevel) + { + switch (logLevel) { - switch (logLevel) - { - case LogLevel.Debug: - _inner.Debug(message); + case LogLevel.Debug: + _inner.Debug(message, exception); + break; + case LogLevel.Info: + _inner.Info(message, exception); - break; - case LogLevel.Info: - _inner.Info(message); + break; + case LogLevel.Warn: + _inner.Warn(message, exception); - break; - case LogLevel.Warn: - _inner.Warn(message); + break; + case LogLevel.Error: + _inner.Error(message, exception); - break; - case LogLevel.Error: - _inner.Error(message); + break; + case LogLevel.Fatal: + _inner.Fatal(message, exception); - break; - case LogLevel.Fatal: - _inner.Fatal(message); + break; + default: + _inner.Debug(message, exception); - break; - default: - _inner.Debug(message); + break; + } + } - break; - } + /// + public void Write(string message, Type type, LogLevel logLevel) + { + var logger = LogResolver.Resolve(type); + switch (logLevel) + { + case LogLevel.Debug: + logger.Debug(message); + break; + case LogLevel.Info: + logger.Info(message); + + break; + case LogLevel.Warn: + logger.Warn(message); + + break; + case LogLevel.Error: + logger.Error(message); + + break; + case LogLevel.Fatal: + logger.Fatal(message); + + break; + default: + logger.Debug(message); + + break; } + } - /// - public void Write(Exception exception, string message, LogLevel logLevel) + /// + public void Write(Exception exception, string message, Type type, LogLevel logLevel) + { + var logger = LogResolver.Resolve(type); + switch (logLevel) { - switch (logLevel) - { - case LogLevel.Debug: - _inner.Debug(message, exception); - break; - case LogLevel.Info: - _inner.Info(message, exception); - - break; - case LogLevel.Warn: - _inner.Warn(message, exception); - - break; - case LogLevel.Error: - _inner.Error(message, exception); - - break; - case LogLevel.Fatal: - _inner.Fatal(message, exception); - - break; - default: - _inner.Debug(message, exception); - - break; - } + case LogLevel.Debug: + logger.Debug(message, exception); + break; + case LogLevel.Info: + logger.Info(message, exception); + + break; + case LogLevel.Warn: + logger.Warn(message, exception); + + break; + case LogLevel.Error: + logger.Error(message, exception); + + break; + case LogLevel.Fatal: + logger.Fatal(message, exception); + + break; + default: + logger.Debug(message, exception); + + break; } + } - /// - public void Write(string message, Type type, LogLevel logLevel) + /// + /// Works out the log level. + /// + /// + /// This was done so the Level property doesn't keep getting re-evaluated each time a Write method is called. + /// + private void SetLogLevel() + { + if (_inner.IsDebugEnabled) { - var logger = LogResolver.Resolve(type); - switch (logLevel) - { - case LogLevel.Debug: - logger.Debug(message); - break; - case LogLevel.Info: - logger.Info(message); - - break; - case LogLevel.Warn: - logger.Warn(message); - - break; - case LogLevel.Error: - logger.Error(message); - - break; - case LogLevel.Fatal: - logger.Fatal(message); - - break; - default: - logger.Debug(message); - - break; - } + Level = LogLevel.Debug; + return; } - /// - public void Write(Exception exception, string message, Type type, LogLevel logLevel) + if (_inner.IsInfoEnabled) { - var logger = LogResolver.Resolve(type); - switch (logLevel) - { - case LogLevel.Debug: - logger.Debug(message, exception); - break; - case LogLevel.Info: - logger.Info(message, exception); - - break; - case LogLevel.Warn: - logger.Warn(message, exception); - - break; - case LogLevel.Error: - logger.Error(message, exception); - - break; - case LogLevel.Fatal: - logger.Fatal(message, exception); - - break; - default: - logger.Debug(message, exception); - - break; - } + Level = LogLevel.Info; + return; } - /// - /// Works out the log level. - /// - /// - /// This was done so the Level property doesn't keep getting re-evaluated each time a Write method is called. - /// - private void SetLogLevel() + if (_inner.IsWarnEnabled) { - if (_inner.IsDebugEnabled) - { - Level = LogLevel.Debug; - return; - } - - if (_inner.IsInfoEnabled) - { - Level = LogLevel.Info; - return; - } - - if (_inner.IsWarnEnabled) - { - Level = LogLevel.Warn; - return; - } - - if (_inner.IsErrorEnabled) - { - Level = LogLevel.Error; - return; - } - - Level = LogLevel.Fatal; + Level = LogLevel.Warn; + return; } - private void OnInnerLoggerReconfigured(object sender, EventArgs e) + if (_inner.IsErrorEnabled) { - SetLogLevel(); + Level = LogLevel.Error; + return; } + + Level = LogLevel.Fatal; + } + + private void OnInnerLoggerReconfigured(object sender, EventArgs e) + { + SetLogLevel(); } } diff --git a/src/Splat.Log4Net/LogResolver.cs b/src/Splat.Log4Net/LogResolver.cs index 4e19a4c23..2785cf521 100644 --- a/src/Splat.Log4Net/LogResolver.cs +++ b/src/Splat.Log4Net/LogResolver.cs @@ -5,21 +5,20 @@ using System; -namespace Splat.Log4Net +namespace Splat.Log4Net; + +/// +/// Resolves a logger to the specified type. +/// +internal static class LogResolver { - /// - /// Resolves a logger to the specified type. - /// - internal static class LogResolver - { - private const int MaxCacheSize = 16; - private static readonly MemoizingMRUCache _loggerCache = new( - (type, _) => global::log4net.LogManager.GetLogger(type), - MaxCacheSize); + private const int MaxCacheSize = 16; + private static readonly MemoizingMRUCache _loggerCache = new( + (type, _) => global::log4net.LogManager.GetLogger(type), + MaxCacheSize); - public static global::log4net.ILog Resolve(Type type) - { - return _loggerCache.Get(type, null); - } + public static global::log4net.ILog Resolve(Type type) + { + return _loggerCache.Get(type, null); } } diff --git a/src/Splat.Log4Net/MutableDependencyResolverExtensions.cs b/src/Splat.Log4Net/MutableDependencyResolverExtensions.cs index 4139f5e5e..ee9f6ef4b 100644 --- a/src/Splat.Log4Net/MutableDependencyResolverExtensions.cs +++ b/src/Splat.Log4Net/MutableDependencyResolverExtensions.cs @@ -3,32 +3,31 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.Log4Net +namespace Splat.Log4Net; + +/// +/// Log4net specific extensions for the Mutable Dependency Resolver. +/// +public static class MutableDependencyResolverExtensions { /// - /// Log4net specific extensions for the Mutable Dependency Resolver. + /// Simple helper to initialize Log4Net within Splat with the Wrapping Full Logger. /// - public static class MutableDependencyResolverExtensions + /// + /// You should configure Log4Net prior to calling this method. + /// + /// + /// An instance of Mutable Dependency Resolver. + /// + /// + /// + /// Locator.CurrentMutable.UseLog4NetWithWrappingFullLogger(); + /// + /// + public static void UseLog4NetWithWrappingFullLogger(this IMutableDependencyResolver instance) { - /// - /// Simple helper to initialize Log4Net within Splat with the Wrapping Full Logger. - /// - /// - /// You should configure Log4Net prior to calling this method. - /// - /// - /// An instance of Mutable Dependency Resolver. - /// - /// - /// - /// Locator.CurrentMutable.UseLog4NetWithWrappingFullLogger(); - /// - /// - public static void UseLog4NetWithWrappingFullLogger(this IMutableDependencyResolver instance) - { - var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new Log4NetLogger(LogResolver.Resolve(type)))); + var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new Log4NetLogger(LogResolver.Resolve(type)))); - instance.RegisterConstant(funcLogManager, typeof(ILogManager)); - } + instance.RegisterConstant(funcLogManager, typeof(ILogManager)); } } diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs index 051d4038b..2af1d586f 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/ContainerWrapper.cs @@ -1,26 +1,24 @@ using System; -using System.Collections.Generic; -using System.Text; + using Microsoft.Extensions.DependencyInjection; -namespace Splat.Microsoft.Extensions.DependencyInjection.Tests +namespace Splat.Microsoft.Extensions.DependencyInjection.Tests; + +internal class ContainerWrapper { - internal class ContainerWrapper - { - private IServiceProvider _serviceProvider; + 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() #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - { - ServiceCollection.UseMicrosoftDependencyResolver(); - } + { + ServiceCollection.UseMicrosoftDependencyResolver(); + } - public IServiceCollection ServiceCollection { get; } = new ServiceCollection(); + public IServiceCollection ServiceCollection { get; } = new ServiceCollection(); - public IServiceProvider ServiceProvider => _serviceProvider ??= ServiceCollection.BuildServiceProvider(); + public IServiceProvider ServiceProvider => _serviceProvider ??= ServiceCollection.BuildServiceProvider(); - public void BuildAndUse() => ServiceProvider.UseMicrosoftDependencyResolver(); - } + public void BuildAndUse() => ServiceProvider.UseMicrosoftDependencyResolver(); } diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/DependencyResolverTests.cs b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/DependencyResolverTests.cs index 009125928..29529be77 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/DependencyResolverTests.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/DependencyResolverTests.cs @@ -13,165 +13,161 @@ using Splat.NLog; using Xunit; -namespace Splat.Microsoft.Extensions.DependencyInjection.Tests +namespace Splat.Microsoft.Extensions.DependencyInjection.Tests; + +/// +/// Tests to show the works correctly. +/// +public class DependencyResolverTests { /// - /// Tests to show the works correctly. + /// Should resolve views. + /// + [Fact] + public void MicrosoftDependencyResolver_Should_Resolve_Views() + { + var wrapper = new ContainerWrapper(); + var services = wrapper.ServiceCollection; + services.AddTransient, ViewOne>(); + services.AddTransient, ViewTwo>(); + + wrapper.BuildAndUse(); + + var viewOne = Locator.Current.GetService(typeof(IViewFor)); + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewOne.Should().NotBeNull(); + viewOne.Should().BeOfType(); + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Should resolve views. + /// + [Fact] + public void MicrosoftDependencyResolver_Should_Resolve_Named_View() + { + var wrapper = new ContainerWrapper(); + var services = wrapper.ServiceCollection; + services.AddTransient, ViewTwo>(); + + wrapper.BuildAndUse(); + + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Should resolve view models. + /// + [Fact] + public void MicrosoftDependencyResolver_Should_Resolve_View_Models() + { + var wrapper = new ContainerWrapper(); + var services = wrapper.ServiceCollection; + services.AddTransient(); + services.AddTransient(); + + wrapper.BuildAndUse(); + + var vmOne = Locator.Current.GetService(); + var vmTwo = Locator.Current.GetService(); + + vmOne.Should().NotBeNull(); + vmTwo.Should().NotBeNull(); + } + + /// + /// Should resolve screen. + /// + [Fact] + public void MicrosoftDependencyResolver_Should_Resolve_Screen() + { + var wrapper = new ContainerWrapper(); + var services = wrapper.ServiceCollection; + services.AddSingleton(new MockScreen()); + + wrapper.BuildAndUse(); + + var screen = Locator.Current.GetService(); + + screen.Should().NotBeNull(); + screen.Should().BeOfType(); + } + + /// + /// Should unregister all. + /// + [Fact] + public void MicrosoftDependencyResolver_Should_UnregisterAll() + { + var wrapper = new ContainerWrapper(); + var services = wrapper.ServiceCollection; + + services.AddSingleton(new MockScreen()); + + Locator.CurrentMutable.HasRegistration(typeof(IScreen)) + .Should().BeTrue(); + + Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); + + var result = Locator.Current.GetService(); + result.Should().BeNull(); + } + + /// + /// Should throw an exception if service registration call back called. + /// + [Fact] + public void MicrosoftDependencyResolver_Should_Throw_If_ServiceRegistionCallback_Called() + { + var wrapper = new ContainerWrapper(); + wrapper.BuildAndUse(); + + var result = Record.Exception(() => + Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); + + result.Should().BeOfType(); + } + + /// + /// Should throw an exception if trying to register services when the container is registered as immutable. /// - public class DependencyResolverTests + [Fact] + public void MicrosoftDependencyResolver_Should_Throw_If_Attempt_Registration_After_Build() { - /// - /// Should resolve views. - /// - [Fact] - public void MicrosoftDependencyResolver_Should_Resolve_Views() - { - var wrapper = new ContainerWrapper(); - var services = wrapper.ServiceCollection; - services.AddTransient, ViewOne>(); - services.AddTransient, ViewTwo>(); - - wrapper.BuildAndUse(); - - var viewOne = Locator.Current.GetService(typeof(IViewFor)); - var viewTwo = Locator.Current.GetService(typeof(IViewFor)); - - viewOne.Should().NotBeNull(); - viewOne.Should().BeOfType(); - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Should resolve views. - /// - [Fact] - public void MicrosoftDependencyResolver_Should_Resolve_Named_View() - { - var wrapper = new ContainerWrapper(); - var services = wrapper.ServiceCollection; - services.AddTransient, ViewTwo>(); - - wrapper.BuildAndUse(); - - var viewTwo = Locator.Current.GetService(typeof(IViewFor)); - - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Should resolve view models. - /// - [Fact] - public void MicrosoftDependencyResolver_Should_Resolve_View_Models() - { - var wrapper = new ContainerWrapper(); - var services = wrapper.ServiceCollection; - services.AddTransient(); - services.AddTransient(); - - wrapper.BuildAndUse(); - - var vmOne = Locator.Current.GetService(); - var vmTwo = Locator.Current.GetService(); - - vmOne.Should().NotBeNull(); - vmTwo.Should().NotBeNull(); - } - - /// - /// Should resolve screen. - /// - [Fact] - public void MicrosoftDependencyResolver_Should_Resolve_Screen() - { - var wrapper = new ContainerWrapper(); - var services = wrapper.ServiceCollection; - services.AddSingleton(new MockScreen()); - - wrapper.BuildAndUse(); - - var screen = Locator.Current.GetService(); - - screen.Should().NotBeNull(); - screen.Should().BeOfType(); - } - - /// - /// Should unregister all. - /// - [Fact] - public void MicrosoftDependencyResolver_Should_UnregisterAll() - { - var wrapper = new ContainerWrapper(); - var services = wrapper.ServiceCollection; - - services.AddSingleton(new MockScreen()); - - Locator.CurrentMutable.HasRegistration(typeof(IScreen)) - .Should().BeTrue(); - - Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); - - var result = Locator.Current.GetService(); - result.Should().BeNull(); - } - - /// - /// Should throw an exception if service registration call back called. - /// - [Fact] - public void MicrosoftDependencyResolver_Should_Throw_If_ServiceRegistionCallback_Called() - { - var wrapper = new ContainerWrapper(); - wrapper.BuildAndUse(); - - var result = Record.Exception(() => - Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); - - result.Should().BeOfType(); - } - - /// - /// Should throw an exception if trying to register services when the container is registered as immutable. - /// - [Fact] - public void MicrosoftDependencyResolver_Should_Throw_If_Attempt_Registration_After_Build() - { - var wrapper = new ContainerWrapper(); - - wrapper.BuildAndUse(); - - var result = Record.Exception(() => Locator.CurrentMutable.Register(() => new ViewOne())); - - result.Should().BeOfType(); - } - - /// - /// Tests to ensure NLog registers correctly with different service locators. - /// Based on issue reported in #553. - /// - [Fact] - public void ILogManager_Resolvable() - { - var wrapper = new ContainerWrapper(); - var services = wrapper.ServiceCollection; - - // Setup NLog for Logging (doesn't matter if I actually configure NLog or not) - var funcLogManager = new FuncLogManager(type => new NLogLogger(LogResolver.Resolve(type))); - services.AddSingleton(funcLogManager); - - wrapper.BuildAndUse(); - - // Get the ILogManager instance. - ILogManager? lm = Locator.Current.GetService(); - Assert.NotNull(lm); - -#pragma warning disable CS8604 // Possible null reference argument. - var mgr = lm.GetLogger(); -#pragma warning restore CS8604 // Possible null reference argument. - Assert.NotNull(mgr); - } + var wrapper = new ContainerWrapper(); + + wrapper.BuildAndUse(); + + var result = Record.Exception(() => Locator.CurrentMutable.Register(() => new ViewOne())); + + result.Should().BeOfType(); + } + + /// + /// Tests to ensure NLog registers correctly with different service locators. + /// Based on issue reported in #553. + /// + [Fact] + public void ILogManager_Resolvable() + { + var wrapper = new ContainerWrapper(); + var services = wrapper.ServiceCollection; + + // Setup NLog for Logging (doesn't matter if I actually configure NLog or not) + var funcLogManager = new FuncLogManager(type => new NLogLogger(LogResolver.Resolve(type))); + services.AddSingleton(funcLogManager); + + wrapper.BuildAndUse(); + + // Get the ILogManager instance. + var lm = Locator.Current.GetService(); + Assert.NotNull(lm); + var mgr = lm.GetLogger(); + Assert.NotNull(mgr); } } diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/MicrosoftDependencyResolverTests.cs b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/MicrosoftDependencyResolverTests.cs index 8915d88d9..a4e4ba2f5 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/MicrosoftDependencyResolverTests.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/MicrosoftDependencyResolverTests.cs @@ -1,61 +1,58 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Extensions.DependencyInjection; +using System.Linq; + using Splat.Microsoft.Extensions.DependencyInjection; + using Xunit; -namespace Splat.Tests.ServiceLocation +namespace Splat.Tests.ServiceLocation; + +/// +/// Unit Tests for the Modern Dependency Resolver. +/// +public sealed class MicrosoftDependencyResolverTests : BaseDependencyResolverTests { /// - /// Unit Tests for the Modern Dependency Resolver. + /// Test to ensure container allows registration with null service type. + /// Should really be brought down to the , + /// it fails for some of the DIs. /// - public sealed class MicrosoftDependencyResolverTests : BaseDependencyResolverTests + [Fact] + public void Can_Register_And_Resolve_Null_Types() { - /// - /// Test to ensure container allows registration with null service type. - /// Should really be brought down to the , - /// it fails for some of the DIs. - /// - [Fact] - public void Can_Register_And_Resolve_Null_Types() - { - var resolver = GetDependencyResolver(); - const int foo = 5; - resolver.Register(() => foo, null); - - const int bar = 4; - const string contract = "foo"; - resolver.Register(() => bar, null, contract); - - Assert.True(resolver.HasRegistration(null)); - var value = resolver.GetService(null); - Assert.Equal(foo, value); - - Assert.True(resolver.HasRegistration(null, contract)); - value = resolver.GetService(null, contract); - Assert.Equal(bar, value); - - var values = resolver.GetServices(null); - Assert.Equal(1, values.Count()); - - resolver.UnregisterCurrent(null); - var valuesNC = resolver.GetServices(null); - Assert.Equal(0, valuesNC.Count()); - var valuesC = resolver.GetServices(null, contract); - Assert.Equal(1, valuesC.Count()); - - resolver.UnregisterAll(null); - valuesNC = resolver.GetServices(null); - Assert.Equal(0, valuesNC.Count()); - - resolver.UnregisterAll(null, contract); - valuesC = resolver.GetServices(null, contract); - Assert.Equal(0, valuesC.Count()); - } - - /// - protected override MicrosoftDependencyResolver GetDependencyResolver() => new(); + var resolver = GetDependencyResolver(); + const int foo = 5; + resolver.Register(() => foo, null); + + const int bar = 4; + const string contract = "foo"; + resolver.Register(() => bar, null, contract); + + Assert.True(resolver.HasRegistration(null)); + var value = resolver.GetService(null); + Assert.Equal(foo, value); + + Assert.True(resolver.HasRegistration(null, contract)); + value = resolver.GetService(null, contract); + Assert.Equal(bar, value); + + var values = resolver.GetServices(null); + Assert.Equal(1, values.Count()); + + resolver.UnregisterCurrent(null); + var valuesNC = resolver.GetServices(null); + Assert.Equal(0, valuesNC.Count()); + var valuesC = resolver.GetServices(null, contract); + Assert.Equal(1, valuesC.Count()); + + resolver.UnregisterAll(null); + valuesNC = resolver.GetServices(null); + Assert.Equal(0, valuesNC.Count()); + + resolver.UnregisterAll(null, contract); + valuesC = resolver.GetServices(null, contract); + Assert.Equal(0, valuesC.Count()); } + + /// + protected override MicrosoftDependencyResolver GetDependencyResolver() => new(); } diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs b/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs index 7bcdeda90..abc7767bf 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs @@ -9,406 +9,406 @@ using System.Data; using System.Diagnostics.CodeAnalysis; using System.Linq; + using Microsoft.Extensions.DependencyInjection; -namespace Splat.Microsoft.Extensions.DependencyInjection +namespace Splat.Microsoft.Extensions.DependencyInjection; + +/// +/// Microsoft DI implementation for . +/// +/// +public class MicrosoftDependencyResolver : IDependencyResolver { + private const string ImmutableExceptionMessage = "This container has already been built and cannot be modified."; + private static readonly Type _dictionaryType = typeof(ContractDictionary<>); + private readonly object _syncLock = new(); + private IServiceCollection? _serviceCollection; + private bool _isImmutable; + private IServiceProvider? _serviceProvider; + /// - /// Microsoft DI implementation for . + /// Initializes a new instance of the class with an . /// - /// - public class MicrosoftDependencyResolver : IDependencyResolver + /// An instance of . + public MicrosoftDependencyResolver(IServiceCollection? services = null) { - private const string ImmutableExceptionMessage = "This container has already been built and cannot be modified."; - private static readonly Type _dictionaryType = typeof(ContractDictionary<>); - private readonly object _syncLock = new(); - private IServiceCollection? _serviceCollection; - private bool _isImmutable; - private IServiceProvider? _serviceProvider; - - /// - /// Initializes a new instance of the class with an . - /// - /// An instance of . - public MicrosoftDependencyResolver(IServiceCollection? services = null) - { - _serviceCollection = services ?? new ServiceCollection(); - } + _serviceCollection = services ?? new ServiceCollection(); + } - /// - /// Initializes a new instance of the class with a configured service Provider. - /// - /// A ready to use service provider. - public MicrosoftDependencyResolver(IServiceProvider serviceProvider) => - UpdateContainer(serviceProvider); - - /// - /// Gets the internal Microsoft conainer, - /// or build new if this instance was not initialized with one. - /// - protected virtual IServiceProvider? ServiceProvider + /// + /// Initializes a new instance of the class with a configured service Provider. + /// + /// A ready to use service provider. + public MicrosoftDependencyResolver(IServiceProvider serviceProvider) => + UpdateContainer(serviceProvider); + + /// + /// Gets the internal Microsoft conainer, + /// or build new if this instance was not initialized with one. + /// + protected virtual IServiceProvider? ServiceProvider + { + get { - get + lock (_syncLock) { - lock (_syncLock) + if (_serviceProvider is null) { - if (_serviceProvider is null) - { - _serviceProvider = _serviceCollection?.BuildServiceProvider(); - } - - return _serviceProvider; + _serviceProvider = _serviceCollection?.BuildServiceProvider(); } + + return _serviceProvider; } } + } - /// - /// Updates this instance with a configured service Provider. - /// - /// A ready to use service provider. - public void UpdateContainer(IServiceProvider serviceProvider) + /// + /// Updates this instance with a configured service Provider. + /// + /// A ready to use service provider. + public void UpdateContainer(IServiceProvider serviceProvider) + { + if (serviceProvider is null) { - if (serviceProvider is null) - { - throw new ArgumentNullException(nameof(serviceProvider)); - } + throw new ArgumentNullException(nameof(serviceProvider)); + } - lock (_syncLock) - { - _serviceCollection = null; - _serviceProvider = serviceProvider; - _isImmutable = true; - } + lock (_syncLock) + { + _serviceCollection = null; + _serviceProvider = serviceProvider; + _isImmutable = true; } + } - /// - public virtual object? GetService(Type? serviceType, string? contract = null) => - GetServices(serviceType, contract).LastOrDefault(); + /// + public virtual object? GetService(Type? serviceType, string? contract = null) => + GetServices(serviceType, contract).LastOrDefault(); - /// - public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + /// + public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + { + if (ServiceProvider is null) { - if (ServiceProvider is null) - { - throw new InvalidOperationException("The ServiceProvider is null."); - } + throw new InvalidOperationException("The ServiceProvider is null."); + } - var isNull = serviceType is null; - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + var isNull = serviceType is null; + if (serviceType is null) + { + serviceType = typeof(NullServiceType); + } - IEnumerable services; + IEnumerable services; - if (contract is null || string.IsNullOrWhiteSpace(contract)) - { - // this is to deal with CS8613 that GetServices returns IEnumerable? - services = ServiceProvider.GetServices(serviceType) - .Where(a => a is not null) - .Select(a => a!); + if (contract is null || string.IsNullOrWhiteSpace(contract)) + { + // this is to deal with CS8613 that GetServices returns IEnumerable? + services = ServiceProvider.GetServices(serviceType) + .Where(a => a is not null) + .Select(a => a!); - if (isNull) - { - services = services - .Cast() - .Select(nst => nst.Factory()!); - } - } - else + if (isNull) { - var dic = GetContractDictionary(serviceType, false); - services = dic? - .GetFactories(contract) - .Select(f => f()!) - ?? Array.Empty(); + services = services + .Cast() + .Select(nst => nst.Factory()!); } - - return services; + } + else + { + var dic = GetContractDictionary(serviceType, false); + services = dic? + .GetFactories(contract) + .Select(f => f()!) + ?? Array.Empty(); } - /// - public virtual void Register(Func factory, Type? serviceType, string? contract = null) + return services; + } + + /// + public virtual void Register(Func factory, Type? serviceType, string? contract = null) + { + if (_isImmutable) { - if (_isImmutable) - { - throw new InvalidOperationException(ImmutableExceptionMessage); - } + throw new InvalidOperationException(ImmutableExceptionMessage); + } - var isNull = serviceType is null; + var isNull = serviceType is null; + + if (serviceType is null) + { + serviceType = typeof(NullServiceType); + } - if (serviceType is null) + lock (_syncLock) + { + if (contract is null || string.IsNullOrWhiteSpace(contract)) { - serviceType = typeof(NullServiceType); + _serviceCollection?.AddTransient(serviceType, _ => + isNull + ? new NullServiceType(factory) + : factory()!); } - - lock (_syncLock) + else { - if (contract is null || string.IsNullOrWhiteSpace(contract)) - { - _serviceCollection?.AddTransient(serviceType, _ => - isNull - ? new NullServiceType(factory) - : factory()!); - } - else - { - var dic = GetContractDictionary(serviceType, true); + var dic = GetContractDictionary(serviceType, true); - dic?.AddFactory(contract, factory); - } - - // required so that it gets rebuilt if not injected externally. - _serviceProvider = null; + dic?.AddFactory(contract, factory); } + + // required so that it gets rebuilt if not injected externally. + _serviceProvider = null; } + } - /// - public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) + /// + public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) + { + if (_isImmutable) { - if (_isImmutable) - { - throw new InvalidOperationException(ImmutableExceptionMessage); - } + throw new InvalidOperationException(ImmutableExceptionMessage); + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + if (serviceType is null) + { + serviceType = typeof(NullServiceType); + } - lock (_syncLock) + lock (_syncLock) + { + if (contract is null || string.IsNullOrWhiteSpace(contract)) { - if (contract is null || string.IsNullOrWhiteSpace(contract)) + var sd = _serviceCollection?.LastOrDefault(s => s.ServiceType == serviceType); + if (sd is not null) { - var sd = _serviceCollection?.LastOrDefault(s => s.ServiceType == serviceType); - if (sd is not null) - { - _serviceCollection?.Remove(sd); - } + _serviceCollection?.Remove(sd); } - else + } + else + { + var dic = GetContractDictionary(serviceType, false); + if (dic is not null) { - var dic = GetContractDictionary(serviceType, false); - if (dic is not null) + dic.RemoveLastFactory(contract); + if (dic.IsEmpty) { - dic.RemoveLastFactory(contract); - if (dic.IsEmpty) - { - RemoveContractService(serviceType); - } + RemoveContractService(serviceType); } } - - // required so that it gets rebuilt if not injected externally. - _serviceProvider = null; } + + // required so that it gets rebuilt if not injected externally. + _serviceProvider = null; } + } - /// - /// Unregisters all the values associated with the specified type and contract - or - - /// If the container has already been built, removes the specified contract (scope) entirely, - /// ignoring the argument. - /// - /// The service type to unregister. - /// This parameter is ignored. Service will be removed from all contracts. - public virtual void UnregisterAll(Type? serviceType, string? contract = null) + /// + /// Unregisters all the values associated with the specified type and contract - or - + /// If the container has already been built, removes the specified contract (scope) entirely, + /// ignoring the argument. + /// + /// The service type to unregister. + /// This parameter is ignored. Service will be removed from all contracts. + public virtual void UnregisterAll(Type? serviceType, string? contract = null) + { + if (_isImmutable) { - if (_isImmutable) - { - throw new InvalidOperationException(ImmutableExceptionMessage); - } + throw new InvalidOperationException(ImmutableExceptionMessage); + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + if (serviceType is null) + { + serviceType = typeof(NullServiceType); + } - lock (_syncLock) + lock (_syncLock) + { + if (contract is null && _serviceCollection is not null) { - if (contract is null && _serviceCollection is not null) - { - var sds = _serviceCollection - .Where(s => s.ServiceType == serviceType) - .ToList(); + var sds = _serviceCollection + .Where(s => s.ServiceType == serviceType) + .ToList(); - foreach (var sd in sds) - { - _serviceCollection.Remove(sd); - } - } - else if (contract is null) + foreach (var sd in sds) { - throw new ArgumentException("There must be a valid contract if there is no service collection.", nameof(contract)); + _serviceCollection.Remove(sd); } - else + } + else if (contract is null) + { + throw new ArgumentException("There must be a valid contract if there is no service collection.", nameof(contract)); + } + else + { + var dic = GetContractDictionary(serviceType, false); + if (dic?.TryRemoveContract(contract) == true && dic.IsEmpty) { - var dic = GetContractDictionary(serviceType, false); - if (dic?.TryRemoveContract(contract) == true && dic.IsEmpty) - { - RemoveContractService(serviceType); - } + RemoveContractService(serviceType); } - - // required so that it gets rebuilt if not injected externally. - _serviceProvider = null; } + + // required so that it gets rebuilt if not injected externally. + _serviceProvider = null; } + } - /// - public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + /// + public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + { + // this method is not used by RxUI + throw new NotImplementedException(); + } + + /// + public virtual bool HasRegistration(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - // this method is not used by RxUI - throw new NotImplementedException(); + serviceType = typeof(NullServiceType); } - /// - public virtual bool HasRegistration(Type? serviceType, string? contract = null) + if (!_isImmutable) { - if (serviceType is null) + if (contract is null || string.IsNullOrWhiteSpace(contract)) { - serviceType = typeof(NullServiceType); + return _serviceCollection?.Any(sd => sd.ServiceType == serviceType) == true; } - if (!_isImmutable) - { - if (contract is null || string.IsNullOrWhiteSpace(contract)) - { - return _serviceCollection?.Any(sd => sd.ServiceType == serviceType) == true; - } + var dictionary = (ContractDictionary?)_serviceCollection?.FirstOrDefault(sd => sd.ServiceType == GetDictionaryType(serviceType))?.ImplementationInstance; - var dictionary = (ContractDictionary?)_serviceCollection?.FirstOrDefault(sd => sd.ServiceType == GetDictionaryType(serviceType))?.ImplementationInstance; - - if (dictionary is null) - { - return false; - } - - return dictionary.GetFactories(contract).Select(f => f()).Any(); - } - - if (contract is null) + if (dictionary is null) { - var service = _serviceProvider?.GetService(serviceType); - return service is not null; + return false; } - var dic = GetContractDictionary(serviceType, false); - return dic?.IsEmpty == false; + return dictionary.GetFactories(contract).Select(f => f()).Any(); } - /// - public void Dispose() + if (contract is null) { - Dispose(true); - GC.SuppressFinalize(this); + var service = _serviceProvider?.GetService(serviceType); + return service is not null; } - /// - /// Disposes of the instance. - /// - /// Whether or not the instance is disposing. - protected virtual void Dispose(bool disposing) + var dic = GetContractDictionary(serviceType, false); + return dic?.IsEmpty == false; + } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Disposes of the instance. + /// + /// Whether or not the instance is disposing. + protected virtual void Dispose(bool disposing) + { + } + + private static Type GetDictionaryType(Type serviceType) => _dictionaryType.MakeGenericType(serviceType); + + private void RemoveContractService(Type serviceType) + { + var dicType = GetDictionaryType(serviceType); + var sd = _serviceCollection?.SingleOrDefault(s => s.ServiceType == serviceType); + + if (sd is not null) { + _serviceCollection?.Remove(sd); } + } - private static Type GetDictionaryType(Type serviceType) => _dictionaryType.MakeGenericType(serviceType); + [SuppressMessage("Naming Rules", "SA1300", Justification = "Intentional")] + private ContractDictionary? GetContractDictionary(Type serviceType, bool createIfNotExists) + { + var dicType = GetDictionaryType(serviceType); - private void RemoveContractService(Type serviceType) + if (ServiceProvider is null) { - var dicType = GetDictionaryType(serviceType); - var sd = _serviceCollection?.SingleOrDefault(s => s.ServiceType == serviceType); - - if (sd is not null) - { - _serviceCollection?.Remove(sd); - } + throw new InvalidOperationException("The ServiceProvider is null."); } - [SuppressMessage("Naming Rules", "SA1300", Justification = "Intentional")] - private ContractDictionary? GetContractDictionary(Type serviceType, bool createIfNotExists) + if (_isImmutable) { - var dicType = GetDictionaryType(serviceType); - - if (ServiceProvider is null) - { - throw new InvalidOperationException("The ServiceProvider is null."); - } - - if (_isImmutable) - { - return (ContractDictionary?)ServiceProvider.GetService(dicType); - } + return (ContractDictionary?)ServiceProvider.GetService(dicType); + } - var dic = getDictionary(); - if (createIfNotExists && dic is null) + var dic = getDictionary(); + if (createIfNotExists && dic is null) + { + lock (_syncLock) { - lock (_syncLock) + if (createIfNotExists) { - if (createIfNotExists) - { - dic = (ContractDictionary?)Activator.CreateInstance(dicType); + dic = (ContractDictionary?)Activator.CreateInstance(dicType); - if (dic is not null) - { - _serviceCollection?.AddSingleton(dicType, dic); - } + if (dic is not null) + { + _serviceCollection?.AddSingleton(dicType, dic); } } } + } - return dic; + return dic; - ContractDictionary? getDictionary() => _serviceCollection? - .Where(sd => sd.ServiceType == dicType) - .Select(sd => sd.ImplementationInstance) - .Cast() - .SingleOrDefault(); - } + ContractDictionary? getDictionary() => _serviceCollection? + .Where(sd => sd.ServiceType == dicType) + .Select(sd => sd.ImplementationInstance) + .Cast() + .SingleOrDefault(); + } - private class ContractDictionary - { - private readonly ConcurrentDictionary>> _dictionary = new(); + private class ContractDictionary + { + private readonly ConcurrentDictionary>> _dictionary = new(); - public bool IsEmpty => _dictionary.IsEmpty; + public bool IsEmpty => _dictionary.IsEmpty; - public bool TryRemoveContract(string contract) => - _dictionary.TryRemove(contract, out var _); + public bool TryRemoveContract(string contract) => + _dictionary.TryRemove(contract, out var _); - public Func? GetFactory(string contract) => - GetFactories(contract) - .LastOrDefault(); + public Func? GetFactory(string contract) => + GetFactories(contract) + .LastOrDefault(); - public IEnumerable> GetFactories(string contract) => - _dictionary.TryGetValue(contract, out var collection) - ? collection ?? Enumerable.Empty>() - : Array.Empty>(); + public IEnumerable> GetFactories(string contract) => + _dictionary.TryGetValue(contract, out var collection) + ? collection ?? Enumerable.Empty>() + : Array.Empty>(); - public void AddFactory(string contract, Func factory) => - _dictionary.AddOrUpdate(contract, _ => new List> { factory }, (_, list) => - { - (list ??= new List>()).Add(factory); - return list; - }); + public void AddFactory(string contract, Func factory) => + _dictionary.AddOrUpdate(contract, _ => new List> { factory }, (_, list) => + { + (list ??= new List>()).Add(factory); + return list; + }); - public void RemoveLastFactory(string contract) => - _dictionary.AddOrUpdate(contract, new List>(), (_, list) => + public void RemoveLastFactory(string contract) => + _dictionary.AddOrUpdate(contract, new List>(), (_, list) => + { + var lastIndex = list.Count - 1; + if (lastIndex > 0) { - var lastIndex = list.Count - 1; - if (lastIndex > 0) - { - list.RemoveAt(lastIndex); - } + list.RemoveAt(lastIndex); + } - // TODO if list empty remove contract entirely - // need to find how to atomically update or remove - // https://github.com/dotnet/corefx/issues/24246 - return list; - }); - } + // TODO if list empty remove contract entirely + // need to find how to atomically update or remove + // https://github.com/dotnet/corefx/issues/24246 + return list; + }); + } - [SuppressMessage("Design", "CA1812: Unused class.", Justification = "Used in reflection.")] - private class ContractDictionary : ContractDictionary - { - } + [SuppressMessage("Design", "CA1812: Unused class.", Justification = "Used in reflection.")] + private class ContractDictionary : ContractDictionary + { } } diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection/SplatMicrosoftExtensions.cs b/src/Splat.Microsoft.Extensions.DependencyInjection/SplatMicrosoftExtensions.cs index 129dda5e9..7387dfedb 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection/SplatMicrosoftExtensions.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection/SplatMicrosoftExtensions.cs @@ -4,43 +4,42 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Diagnostics.CodeAnalysis; + using Microsoft.Extensions.DependencyInjection; -namespace Splat.Microsoft.Extensions.DependencyInjection +namespace Splat.Microsoft.Extensions.DependencyInjection; + +/// +/// Extension methods for . +/// +public static class SplatMicrosoftExtensions { /// - /// Extension methods for . + /// Initializes an instance of that overrides the default . /// - public static class SplatMicrosoftExtensions - { - /// - /// Initializes an instance of that overrides the default . - /// - /// The . - public static void UseMicrosoftDependencyResolver(this IServiceCollection serviceCollection) => - Locator.SetLocator(new MicrosoftDependencyResolver(serviceCollection)); + /// The . + public static void UseMicrosoftDependencyResolver(this IServiceCollection serviceCollection) => + Locator.SetLocator(new MicrosoftDependencyResolver(serviceCollection)); - /// - /// Initializes an instance of that overrides the default - /// with a built . - /// - /// - /// If there is already a serving as the - /// , it'll instead update it to use the specified - /// . - /// - /// The . - public static void UseMicrosoftDependencyResolver(this IServiceProvider serviceProvider) + /// + /// Initializes an instance of that overrides the default + /// with a built . + /// + /// + /// If there is already a serving as the + /// , it'll instead update it to use the specified + /// . + /// + /// The . + public static void UseMicrosoftDependencyResolver(this IServiceProvider serviceProvider) + { + if (Locator.Current is MicrosoftDependencyResolver resolver) + { + resolver.UpdateContainer(serviceProvider); + } + else { - if (Locator.Current is MicrosoftDependencyResolver resolver) - { - resolver.UpdateContainer(serviceProvider); - } - else - { - Locator.SetLocator(new MicrosoftDependencyResolver(serviceProvider)); - } + Locator.SetLocator(new MicrosoftDependencyResolver(serviceProvider)); } } } diff --git a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs index 6cce8988f..0bb0dda24 100644 --- a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs +++ b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLogProvider.cs @@ -4,73 +4,69 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; + using Microsoft.Extensions.Logging; -namespace Splat.Microsoft.Extensions.Logging +namespace Splat.Microsoft.Extensions.Logging; + +/// +/// A logging provider which talks to Splat. +/// +public sealed class MicrosoftExtensionsLogProvider : ILoggerProvider { - /// - /// A logging provider which talks to Splat. - /// - public sealed class MicrosoftExtensionsLogProvider : ILoggerProvider + /// + public void Dispose() { - /// - public void Dispose() - { - } + } - /// - public global::Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName) + /// + public global::Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName) + { + return new SplatLoggingAdapter(categoryName); + } + + private class SplatLoggingAdapter : global::Microsoft.Extensions.Logging.ILogger + { + private readonly string _categoryName; + + public SplatLoggingAdapter(string categoryName) { - return new SplatLoggingAdapter(categoryName); + _categoryName = categoryName; } - private class SplatLoggingAdapter : global::Microsoft.Extensions.Logging.ILogger + /// + public void Log(global::Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { - private readonly string _categoryName; - - public SplatLoggingAdapter(string categoryName) + if (!IsEnabled(logLevel)) { - _categoryName = categoryName; + return; } - /// - public void Log(global::Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + if (formatter is null) { - if (!IsEnabled(logLevel)) - { - return; - } - - if (formatter is null) - { - throw new ArgumentNullException(nameof(formatter)); - } + throw new ArgumentNullException(nameof(formatter)); + } - var splatLogLevel = MsLoggingHelpers.MsLog2SplatDictionary[logLevel]; + var splatLogLevel = MsLoggingHelpers.MsLog2SplatDictionary[logLevel]; - var message = formatter(state, exception); + var message = formatter(state, exception); - LogHost.Default.Write(exception!, message, splatLogLevel); - } + LogHost.Default.Write(exception!, message, splatLogLevel); + } - /// - public bool IsEnabled(global::Microsoft.Extensions.Logging.LogLevel logLevel) - { - return logLevel != global::Microsoft.Extensions.Logging.LogLevel.None; - } + /// + public bool IsEnabled(global::Microsoft.Extensions.Logging.LogLevel logLevel) + { + return logLevel != global::Microsoft.Extensions.Logging.LogLevel.None; + } - /// - public IDisposable BeginScope(TState state) - where TState : notnull - { - // documentation states we're allowed to return null. - // NRT in net6 causing build issue as of 2021-11-10. - return null!; - } + /// + public IDisposable BeginScope(TState state) + where TState : notnull + { + // documentation states we're allowed to return null. + // NRT in net6 causing build issue as of 2021-11-10. + return null!; } } } diff --git a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs index 95d2e1463..fbb79bd03 100644 --- a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs +++ b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingExtensions.cs @@ -6,75 +6,74 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -namespace Splat.Microsoft.Extensions.Logging +namespace Splat.Microsoft.Extensions.Logging; + +/// +/// Microsoft.Extensions.Logging specific extensions for the Mutable Dependency Resolver. +/// +public static class MicrosoftExtensionsLoggingExtensions { /// - /// Microsoft.Extensions.Logging specific extensions for the Mutable Dependency Resolver. + /// Simple helper to initialize Microsoft.Extensions.Logging within Splat with the Wrapping Full Logger. /// - public static class MicrosoftExtensionsLoggingExtensions + /// + /// You should configure Microsoft.Extensions.Logging prior to calling this method. + /// + /// + /// An instance of Mutable Dependency Resolver. + /// + /// + /// An instance of the Microsoft.Extensions.Logging Logger Factory. + /// + /// + /// + /// Locator.CurrentMutable.UseMicrosoftExtensionsLoggingWithWrappingFullLogger(); + /// + /// + public static void UseMicrosoftExtensionsLoggingWithWrappingFullLogger( + this IMutableDependencyResolver instance, + ILoggerFactory loggerFactory) { - /// - /// Simple helper to initialize Microsoft.Extensions.Logging within Splat with the Wrapping Full Logger. - /// - /// - /// You should configure Microsoft.Extensions.Logging prior to calling this method. - /// - /// - /// An instance of Mutable Dependency Resolver. - /// - /// - /// An instance of the Microsoft.Extensions.Logging Logger Factory. - /// - /// - /// - /// Locator.CurrentMutable.UseMicrosoftExtensionsLoggingWithWrappingFullLogger(); - /// - /// - public static void UseMicrosoftExtensionsLoggingWithWrappingFullLogger( - this IMutableDependencyResolver instance, - ILoggerFactory loggerFactory) + var funcLogManager = new FuncLogManager(type => { - var funcLogManager = new FuncLogManager(type => - { - var actualLogger = loggerFactory.CreateLogger(type.ToString()); - var miniLoggingWrapper = new MicrosoftExtensionsLoggingLogger(actualLogger); - return new WrappingFullLogger(miniLoggingWrapper); - }); + var actualLogger = loggerFactory.CreateLogger(type.ToString()); + var miniLoggingWrapper = new MicrosoftExtensionsLoggingLogger(actualLogger); + return new WrappingFullLogger(miniLoggingWrapper); + }); - instance.RegisterConstant(funcLogManager, typeof(ILogManager)); - } + instance.RegisterConstant(funcLogManager, typeof(ILogManager)); + } - /// - /// Registers a with the service collection. - /// - /// The logging builder to register. - /// The logging builder. - public static ILoggingBuilder AddSplat(this ILoggingBuilder builder) + /// + /// Registers a with the service collection. + /// + /// The logging builder to register. + /// The logging builder. + public static ILoggingBuilder AddSplat(this ILoggingBuilder builder) + { + if (builder is null) { - if (builder is null) - { - throw new System.ArgumentNullException(nameof(builder)); - } + throw new System.ArgumentNullException(nameof(builder)); + } - builder.Services.AddSingleton(); + builder.Services.AddSingleton(); - return builder; - } + return builder; + } - /// - /// Adds a to the logger factory. - /// - /// Our logger provider. - /// The factory. - public static ILoggerFactory AddSplat(this ILoggerFactory loggerFactory) + /// + /// Adds a to the logger factory. + /// + /// Our logger provider. + /// The factory. + public static ILoggerFactory AddSplat(this ILoggerFactory loggerFactory) + { + if (loggerFactory is null) { - if (loggerFactory is null) - { - throw new System.ArgumentNullException(nameof(loggerFactory)); - } - - loggerFactory.AddProvider(new MicrosoftExtensionsLogProvider()); - return loggerFactory; + throw new System.ArgumentNullException(nameof(loggerFactory)); } + + loggerFactory.AddProvider(new MicrosoftExtensionsLogProvider()); + return loggerFactory; } } diff --git a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs index f170c3eac..a41d4791a 100644 --- a/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs +++ b/src/Splat.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLogger.cs @@ -4,95 +4,93 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Collections.Immutable; using System.Diagnostics; + using Microsoft.Extensions.Logging; -namespace Splat.Microsoft.Extensions.Logging +namespace Splat.Microsoft.Extensions.Logging; + +/// +/// Microsoft.Extensions.Logging Logger integration into Splat. +/// +[DebuggerDisplay("Name={_inner.GetType()} Level={Level}")] +public sealed class MicrosoftExtensionsLoggingLogger : ILogger { + private readonly global::Microsoft.Extensions.Logging.ILogger _inner; + /// - /// Microsoft.Extensions.Logging Logger integration into Splat. + /// Initializes a new instance of the class. /// - [DebuggerDisplay("Name={_inner.GetType()} Level={Level}")] - public sealed class MicrosoftExtensionsLoggingLogger : ILogger + /// The actual Microsoft.Extensions.Logging logger. + /// Microsoft.Extensions.Logging logger not passed. + public MicrosoftExtensionsLoggingLogger(global::Microsoft.Extensions.Logging.ILogger inner) { - private readonly global::Microsoft.Extensions.Logging.ILogger _inner; - - /// - /// Initializes a new instance of the class. - /// - /// The actual Microsoft.Extensions.Logging logger. - /// Microsoft.Extensions.Logging logger not passed. - public MicrosoftExtensionsLoggingLogger(global::Microsoft.Extensions.Logging.ILogger inner) - { - _inner = inner ?? throw new ArgumentNullException(nameof(inner)); - } + _inner = inner ?? throw new ArgumentNullException(nameof(inner)); + } - /// - public LogLevel Level + /// + public LogLevel Level + { + get { - get + foreach (var mapping in MsLoggingHelpers.Mappings) { - foreach (var mapping in MsLoggingHelpers.Mappings) + if (_inner.IsEnabled(mapping.Value)) { - if (_inner.IsEnabled(mapping.Value)) - { - return mapping.Key; - } + return mapping.Key; } - - // Default to Fatal, it should always be enabled anyway. - return LogLevel.Fatal; } + + // Default to Fatal, it should always be enabled anyway. + return LogLevel.Fatal; } + } + + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "Deliberate Usage")] + public void Write(string message, LogLevel logLevel) + { + _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], message); + } + + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "Deliberate Usage")] + public void Write(Exception exception, string message, LogLevel logLevel) + { + _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], exception, message); + } - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "Deliberate Usage")] - public void Write(string message, LogLevel logLevel) + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] + [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 (type is null) { - _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], message); + throw new ArgumentNullException(nameof(type)); } - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "Deliberate Usage")] - public void Write(Exception exception, string message, LogLevel logLevel) + using (_inner.BeginScope(type.ToString())) { - _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], exception, message); + _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], message); } + } - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "Deliberate Usage")] - public void Write(string message, Type type, LogLevel logLevel) + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] + [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 (type is null) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - using (_inner.BeginScope(type.ToString())) - { - _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], message); - } + throw new ArgumentNullException(nameof(type)); } - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Deliberate Usage")] - [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) + using (_inner.BeginScope(type.ToString())) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - using (_inner.BeginScope(type.ToString())) - { - _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], exception, message); - } + _inner.Log(MsLoggingHelpers.Splat2MsLogDictionary[logLevel], exception, message); } } } diff --git a/src/Splat.Microsoft.Extensions.Logging/MsLoggingHelpers.cs b/src/Splat.Microsoft.Extensions.Logging/MsLoggingHelpers.cs index bf98f9a37..32e9bf66b 100644 --- a/src/Splat.Microsoft.Extensions.Logging/MsLoggingHelpers.cs +++ b/src/Splat.Microsoft.Extensions.Logging/MsLoggingHelpers.cs @@ -3,26 +3,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Text; -namespace Splat.Microsoft.Extensions.Logging +namespace Splat.Microsoft.Extensions.Logging; + +internal static class MsLoggingHelpers { - internal static class MsLoggingHelpers + public static KeyValuePair[] Mappings { get; } = { - public static KeyValuePair[] Mappings { get; } = - { - new(LogLevel.Debug, global::Microsoft.Extensions.Logging.LogLevel.Debug), - new(LogLevel.Info, global::Microsoft.Extensions.Logging.LogLevel.Information), - new(LogLevel.Warn, global::Microsoft.Extensions.Logging.LogLevel.Warning), - new(LogLevel.Error, global::Microsoft.Extensions.Logging.LogLevel.Error), - new(LogLevel.Fatal, global::Microsoft.Extensions.Logging.LogLevel.Critical) - }; + new(LogLevel.Debug, global::Microsoft.Extensions.Logging.LogLevel.Debug), + new(LogLevel.Info, global::Microsoft.Extensions.Logging.LogLevel.Information), + new(LogLevel.Warn, global::Microsoft.Extensions.Logging.LogLevel.Warning), + new(LogLevel.Error, global::Microsoft.Extensions.Logging.LogLevel.Error), + new(LogLevel.Fatal, global::Microsoft.Extensions.Logging.LogLevel.Critical), + }; - public static ImmutableDictionary Splat2MsLogDictionary { get; } = Mappings.ToImmutableDictionary(); + public static ImmutableDictionary Splat2MsLogDictionary { get; } = Mappings.ToImmutableDictionary(); - public static ImmutableDictionary MsLog2SplatDictionary { get; } = Mappings.ToImmutableDictionary(x => x.Value, x => x.Key); - } + public static ImmutableDictionary MsLog2SplatDictionary { get; } = Mappings.ToImmutableDictionary(x => x.Value, x => x.Key); } diff --git a/src/Splat.NLog/LogResolver.cs b/src/Splat.NLog/LogResolver.cs index 5a15b1323..6f7d32264 100644 --- a/src/Splat.NLog/LogResolver.cs +++ b/src/Splat.NLog/LogResolver.cs @@ -4,24 +4,21 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Text; -namespace Splat.NLog +namespace Splat.NLog; + +/// +/// Resolves a type to a NLog instance. +/// +internal static class LogResolver { - /// - /// Resolves a type to a NLog instance. - /// - internal static class LogResolver - { - private const int MaxCacheSize = 16; - private static readonly MemoizingMRUCache _loggerCache = new( - (type, _) => global::NLog.LogManager.GetLogger(type.ToString()), - MaxCacheSize); + private const int MaxCacheSize = 16; + private static readonly MemoizingMRUCache _loggerCache = new( + (type, _) => global::NLog.LogManager.GetLogger(type.ToString()), + MaxCacheSize); - public static global::NLog.ILogger Resolve(Type type) - { - return _loggerCache.Get(type, null); - } + public static global::NLog.ILogger Resolve(Type type) + { + return _loggerCache.Get(type, null); } } diff --git a/src/Splat.NLog/MutableDependencyResolverExtensions.cs b/src/Splat.NLog/MutableDependencyResolverExtensions.cs index 07606eceb..12fd6f471 100644 --- a/src/Splat.NLog/MutableDependencyResolverExtensions.cs +++ b/src/Splat.NLog/MutableDependencyResolverExtensions.cs @@ -3,32 +3,31 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.NLog +namespace Splat.NLog; + +/// +/// NLog specific extensions for the Mutable Dependency Resolver. +/// +public static class MutableDependencyResolverExtensions { /// - /// NLog specific extensions for the Mutable Dependency Resolver. + /// Simple helper to initialize NLog within Splat with the Wrapping Full Logger. /// - public static class MutableDependencyResolverExtensions + /// + /// You should configure NLog prior to calling this method. + /// + /// + /// An instance of Mutable Dependency Resolver. + /// + /// + /// + /// Locator.CurrentMutable.UseNLogWithWrappingFullLogger(); + /// + /// + public static void UseNLogWithWrappingFullLogger(this IMutableDependencyResolver instance) { - /// - /// Simple helper to initialize NLog within Splat with the Wrapping Full Logger. - /// - /// - /// You should configure NLog prior to calling this method. - /// - /// - /// An instance of Mutable Dependency Resolver. - /// - /// - /// - /// Locator.CurrentMutable.UseNLogWithWrappingFullLogger(); - /// - /// - public static void UseNLogWithWrappingFullLogger(this IMutableDependencyResolver instance) - { - var funcLogManager = new FuncLogManager(type => new NLogLogger(LogResolver.Resolve(type))); + var funcLogManager = new FuncLogManager(type => new NLogLogger(LogResolver.Resolve(type))); - instance.RegisterConstant(funcLogManager, typeof(ILogManager)); - } + instance.RegisterConstant(funcLogManager, typeof(ILogManager)); } } diff --git a/src/Splat.NLog/NLogLogger.cs b/src/Splat.NLog/NLogLogger.cs index c91de07c8..e281b8de7 100644 --- a/src/Splat.NLog/NLogLogger.cs +++ b/src/Splat.NLog/NLogLogger.cs @@ -9,1074 +9,1073 @@ using System.Diagnostics; using System.Globalization; -namespace Splat.NLog +namespace Splat.NLog; + +/// +/// NLog Logger taken from ReactiveUI 5. +/// +[DebuggerDisplay("Name={_inner.Name} Level={Level}")] +public sealed class NLogLogger : IFullLogger, IDisposable { - /// - /// NLog Logger taken from ReactiveUI 5. - /// - [DebuggerDisplay("Name={_inner.Name} Level={Level}")] - public sealed class NLogLogger : IFullLogger, IDisposable + private static readonly KeyValuePair[] _mappings = { - private static readonly KeyValuePair[] _mappings = - { - new(LogLevel.Debug, global::NLog.LogLevel.Debug), - new(LogLevel.Info, global::NLog.LogLevel.Info), - new(LogLevel.Warn, global::NLog.LogLevel.Warn), - new(LogLevel.Error, global::NLog.LogLevel.Error), - new(LogLevel.Fatal, global::NLog.LogLevel.Fatal) - }; - - private static readonly ImmutableDictionary _mappingsDictionary = _mappings.ToImmutableDictionary(); - - private readonly global::NLog.ILogger _inner; - - /// - /// Initializes a new instance of the class. - /// - /// The actual nlog logger. - /// NLog logger not passed. - public NLogLogger(global::NLog.ILogger inner) - { - _inner = inner ?? throw new ArgumentNullException(nameof(inner)); - SetLogLevel(); - _inner.LoggerReconfigured += OnInnerLoggerReconfigured; - } + new(LogLevel.Debug, global::NLog.LogLevel.Debug), + new(LogLevel.Info, global::NLog.LogLevel.Info), + new(LogLevel.Warn, global::NLog.LogLevel.Warn), + new(LogLevel.Error, global::NLog.LogLevel.Error), + new(LogLevel.Fatal, global::NLog.LogLevel.Fatal), + }; - /// - public LogLevel Level - { - get; private set; - } + private static readonly ImmutableDictionary _mappingsDictionary = _mappings.ToImmutableDictionary(); - /// - public bool IsDebugEnabled => _inner.IsEnabled(global::NLog.LogLevel.Debug); + private readonly global::NLog.ILogger _inner; - /// - public bool IsInfoEnabled => _inner.IsEnabled(global::NLog.LogLevel.Info); + /// + /// Initializes a new instance of the class. + /// + /// The actual nlog logger. + /// NLog logger not passed. + public NLogLogger(global::NLog.ILogger inner) + { + _inner = inner ?? throw new ArgumentNullException(nameof(inner)); + SetLogLevel(); + _inner.LoggerReconfigured += OnInnerLoggerReconfigured; + } - /// - public bool IsWarnEnabled => _inner.IsEnabled(global::NLog.LogLevel.Warn); + /// + public LogLevel Level + { + get; private set; + } - /// - public bool IsErrorEnabled => _inner.IsEnabled(global::NLog.LogLevel.Error); + /// + public bool IsDebugEnabled => _inner.IsEnabled(global::NLog.LogLevel.Debug); - /// - public bool IsFatalEnabled => _inner.IsEnabled(global::NLog.LogLevel.Fatal); + /// + public bool IsInfoEnabled => _inner.IsEnabled(global::NLog.LogLevel.Info); - /// - public void Dispose() - { - _inner.LoggerReconfigured -= OnInnerLoggerReconfigured; - } + /// + public bool IsWarnEnabled => _inner.IsEnabled(global::NLog.LogLevel.Warn); - /// - public void Write(string message, LogLevel logLevel) - { - _inner.Log(_mappingsDictionary[logLevel], message); - } + /// + public bool IsErrorEnabled => _inner.IsEnabled(global::NLog.LogLevel.Error); - /// - public void Write(Exception exception, string message, LogLevel logLevel) - { - _inner.Log(_mappingsDictionary[logLevel], exception, message); - } + /// + public bool IsFatalEnabled => _inner.IsEnabled(global::NLog.LogLevel.Fatal); - /// - public void Write(string message, Type type, LogLevel logLevel) - { - LogResolver.Resolve(type).Log(_mappingsDictionary[logLevel], message); - } + /// + public void Dispose() + { + _inner.LoggerReconfigured -= OnInnerLoggerReconfigured; + } - /// - public void Write(Exception exception, string message, Type type, LogLevel logLevel) - { - LogResolver.Resolve(type).Log(_mappingsDictionary[logLevel], exception, message); - } + /// + public void Write(string message, LogLevel logLevel) + { + _inner.Log(_mappingsDictionary[logLevel], message); + } - /// - public void Debug(string message, TArgument args) - { - _inner.Debug(CultureInfo.InvariantCulture, message, args); - } + /// + public void Write(Exception exception, string message, LogLevel logLevel) + { + _inner.Log(_mappingsDictionary[logLevel], exception, message); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); - } + /// + public void Write(string message, Type type, LogLevel logLevel) + { + LogResolver.Resolve(type).Log(_mappingsDictionary[logLevel], message); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); - } + /// + public void Write(Exception exception, string message, Type type, LogLevel logLevel) + { + LogResolver.Resolve(type).Log(_mappingsDictionary[logLevel], exception, message); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Debug(string message, TArgument args) + { + _inner.Debug(CultureInfo.InvariantCulture, message, args); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Info(string message, TArgument args) - { - _inner.Info(CultureInfo.InvariantCulture, message, args); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); - } + /// + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Info(string message, TArgument args) + { + _inner.Info(CultureInfo.InvariantCulture, message, args); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Warn(string message, TArgument args) - { - _inner.Warn(CultureInfo.InvariantCulture, message, args); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); - } + /// + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Warn(string message, TArgument args) + { + _inner.Warn(CultureInfo.InvariantCulture, message, args); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Error(string message, TArgument args) - { - _inner.Error(CultureInfo.InvariantCulture, message, args); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); - } + /// + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Error(string message, TArgument args) + { + _inner.Error(CultureInfo.InvariantCulture, message, args); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Fatal(string message, TArgument args) - { - _inner.Fatal(CultureInfo.InvariantCulture, message, args); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); - } + /// + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Fatal(string message, TArgument args) + { + _inner.Fatal(CultureInfo.InvariantCulture, message, args); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Debug(T value) - { - _inner.Debug(value); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Debug(IFormatProvider formatProvider, T value) - { - _inner.Debug(formatProvider, value); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void DebugException(string? message, Exception exception) - { - _inner.Debug(exception, message); - } + /// + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Debug(Exception exception, string? message) - { - _inner.Debug(exception, message); - } + /// + public void Debug(T value) + { + _inner.Debug(value); + } - /// - public void Debug(IFormatProvider formatProvider, string message, params object[] args) - { - _inner.Debug(formatProvider, message, args); - } + /// + public void Debug(IFormatProvider formatProvider, T value) + { + _inner.Debug(formatProvider, value); + } - /// - public void Debug(string? message) - { - _inner.Debug(message); - } + /// + public void DebugException(string? message, Exception exception) + { + _inner.Debug(exception, message); + } - /// - public void Debug(string? message) - { - LogResolver.Resolve(typeof(T)).Debug(message); - } + /// + public void Debug(Exception exception, string? message) + { + _inner.Debug(exception, message); + } - /// - public void Debug(string message, params object[] args) - { - _inner.Debug(CultureInfo.InvariantCulture, message, args); - } + /// + public void Debug(IFormatProvider formatProvider, string message, params object[] args) + { + _inner.Debug(formatProvider, message, args); + } - /// - public void Debug(string message, params object[] args) - { - LogResolver.Resolve(typeof(T)).Debug(CultureInfo.InvariantCulture, message, args); - } + /// + public void Debug(string? message) + { + _inner.Debug(message); + } - /// - public void Debug(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Debug(formatProvider, message, argument); - } + /// + public void Debug(string? message) + { + LogResolver.Resolve(typeof(T)).Debug(message); + } - /// - public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Debug(formatProvider, message, argument1, argument2); - } + /// + public void Debug(string message, params object[] args) + { + _inner.Debug(CultureInfo.InvariantCulture, message, args); + } - /// - public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Debug(formatProvider, message, argument1, argument2, argument3); - } + /// + public void Debug(string message, params object[] args) + { + LogResolver.Resolve(typeof(T)).Debug(CultureInfo.InvariantCulture, message, args); + } - /// - public void Info(T value) - { - LogResolver.Resolve(typeof(T)).Info(value); - } + /// + public void Debug(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Debug(formatProvider, message, argument); + } - /// - public void Info(IFormatProvider formatProvider, T value) - { - _inner.Info(formatProvider, value); - } + /// + public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Debug(formatProvider, message, argument1, argument2); + } - /// - public void InfoException(string? message, Exception exception) - { - _inner.Info(exception, message); - } + /// + public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Debug(formatProvider, message, argument1, argument2, argument3); + } - /// - public void Info(Exception exception, string? message) - { - _inner.Info(exception, message); - } + /// + public void Info(T value) + { + LogResolver.Resolve(typeof(T)).Info(value); + } - /// - public void Info(IFormatProvider formatProvider, string message, params object[] args) - { - _inner.Info(formatProvider, message, args); - } + /// + public void Info(IFormatProvider formatProvider, T value) + { + _inner.Info(formatProvider, value); + } - /// - public void Info(string? message) - { - _inner.Info(message); - } + /// + public void InfoException(string? message, Exception exception) + { + _inner.Info(exception, message); + } - /// - public void Info(string? message) - { - LogResolver.Resolve(typeof(T)).Info(message); - } + /// + public void Info(Exception exception, string? message) + { + _inner.Info(exception, message); + } - /// - public void Info(string message, params object[] args) - { - _inner.Info(CultureInfo.InvariantCulture, message, args); - } + /// + public void Info(IFormatProvider formatProvider, string message, params object[] args) + { + _inner.Info(formatProvider, message, args); + } - /// - public void Info(string message, params object[] args) - { - LogResolver.Resolve(typeof(T)).Info(CultureInfo.InvariantCulture, message, args); - } + /// + public void Info(string? message) + { + _inner.Info(message); + } - /// - public void Info(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Info(formatProvider, message, argument); - } + /// + public void Info(string? message) + { + LogResolver.Resolve(typeof(T)).Info(message); + } - /// - public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Info(formatProvider, message, argument1, argument2); - } + /// + public void Info(string message, params object[] args) + { + _inner.Info(CultureInfo.InvariantCulture, message, args); + } - /// - public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Info(formatProvider, message, argument1, argument2, argument3); - } + /// + public void Info(string message, params object[] args) + { + LogResolver.Resolve(typeof(T)).Info(CultureInfo.InvariantCulture, message, args); + } - /// - public void Warn(T value) - { - LogResolver.Resolve(typeof(T)).Warn(value); - } + /// + public void Info(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Info(formatProvider, message, argument); + } - /// - public void Warn(IFormatProvider formatProvider, T value) - { - _inner.Warn(formatProvider, value); - } + /// + public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Info(formatProvider, message, argument1, argument2); + } - /// - public void WarnException(string? message, Exception exception) - { - _inner.Warn(exception, message); - } + /// + public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Info(formatProvider, message, argument1, argument2, argument3); + } - /// - public void Warn(Exception exception, string? message) - { - _inner.Warn(exception, message); - } + /// + public void Warn(T value) + { + LogResolver.Resolve(typeof(T)).Warn(value); + } - /// - public void Warn(IFormatProvider formatProvider, string message, params object[] args) - { - _inner.Warn(formatProvider, message, args); - } + /// + public void Warn(IFormatProvider formatProvider, T value) + { + _inner.Warn(formatProvider, value); + } - /// - public void Warn(string? message) - { - _inner.Warn(message); - } + /// + public void WarnException(string? message, Exception exception) + { + _inner.Warn(exception, message); + } - /// - public void Warn(string? message) - { - LogResolver.Resolve(typeof(T)).Warn(message); - } + /// + public void Warn(Exception exception, string? message) + { + _inner.Warn(exception, message); + } - /// - public void Warn(string message, params object[] args) - { - _inner.Warn(CultureInfo.InvariantCulture, message, args); - } + /// + public void Warn(IFormatProvider formatProvider, string message, params object[] args) + { + _inner.Warn(formatProvider, message, args); + } - /// - public void Warn(string message, params object[] args) - { - LogResolver.Resolve(typeof(T)).Warn(CultureInfo.InvariantCulture, message, args); - } + /// + public void Warn(string? message) + { + _inner.Warn(message); + } - /// - public void Warn(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Warn(formatProvider, message, argument); - } + /// + public void Warn(string? message) + { + LogResolver.Resolve(typeof(T)).Warn(message); + } - /// - public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Warn(formatProvider, message, argument1, argument2); - } + /// + public void Warn(string message, params object[] args) + { + _inner.Warn(CultureInfo.InvariantCulture, message, args); + } - /// - public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Warn(formatProvider, message, argument1, argument2, argument3); - } + /// + public void Warn(string message, params object[] args) + { + LogResolver.Resolve(typeof(T)).Warn(CultureInfo.InvariantCulture, message, args); + } - /// - public void Error(T value) - { - LogResolver.Resolve(typeof(T)).Error(value); - } + /// + public void Warn(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Warn(formatProvider, message, argument); + } - /// - public void Error(IFormatProvider formatProvider, T value) - { - _inner.Error(formatProvider, value); - } + /// + public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Warn(formatProvider, message, argument1, argument2); + } - /// - public void ErrorException(string? message, Exception exception) - { - _inner.Error(exception, message); - } + /// + public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Warn(formatProvider, message, argument1, argument2, argument3); + } - /// - public void Error(Exception exception, string? message) - { - _inner.Error(exception, message); - } + /// + public void Error(T value) + { + LogResolver.Resolve(typeof(T)).Error(value); + } - /// - public void Error(IFormatProvider formatProvider, string message, params object[] args) - { - _inner.Error(formatProvider, message, args); - } + /// + public void Error(IFormatProvider formatProvider, T value) + { + _inner.Error(formatProvider, value); + } - /// - public void Error(string? message) - { - _inner.Error(message); - } + /// + public void ErrorException(string? message, Exception exception) + { + _inner.Error(exception, message); + } - /// - public void Error(string? message) - { - LogResolver.Resolve(typeof(T)).Error(message); - } + /// + public void Error(Exception exception, string? message) + { + _inner.Error(exception, message); + } - /// - public void Error(string message, params object[] args) - { - _inner.Error(CultureInfo.InvariantCulture, message, args); - } + /// + public void Error(IFormatProvider formatProvider, string message, params object[] args) + { + _inner.Error(formatProvider, message, args); + } - /// - public void Error(string message, params object[] args) - { - LogResolver.Resolve(typeof(T)).Error(CultureInfo.InvariantCulture, message, args); - } + /// + public void Error(string? message) + { + _inner.Error(message); + } - /// - public void Error(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Error(formatProvider, message, argument); - } + /// + public void Error(string? message) + { + LogResolver.Resolve(typeof(T)).Error(message); + } - /// - public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Error(formatProvider, message, argument1, argument2); - } + /// + public void Error(string message, params object[] args) + { + _inner.Error(CultureInfo.InvariantCulture, message, args); + } - /// - public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Error(formatProvider, message, argument1, argument2, argument3); - } + /// + public void Error(string message, params object[] args) + { + LogResolver.Resolve(typeof(T)).Error(CultureInfo.InvariantCulture, message, args); + } - /// - public void Fatal(T value) - { - LogResolver.Resolve(typeof(T)).Fatal(value); - } + /// + public void Error(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Error(formatProvider, message, argument); + } - /// - public void Fatal(IFormatProvider formatProvider, T value) - { - _inner.Fatal(formatProvider, value); - } + /// + public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Error(formatProvider, message, argument1, argument2); + } - /// - public void FatalException(string? message, Exception exception) - { - _inner.Fatal(exception, message); - } + /// + public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Error(formatProvider, message, argument1, argument2, argument3); + } - /// - public void Fatal(Exception exception, string? message) - { - _inner.Fatal(exception, message); - } + /// + public void Fatal(T value) + { + LogResolver.Resolve(typeof(T)).Fatal(value); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, params object[] args) - { - _inner.Fatal(formatProvider, message, args); - } + /// + public void Fatal(IFormatProvider formatProvider, T value) + { + _inner.Fatal(formatProvider, value); + } - /// - public void Fatal(string? message) - { - _inner.Fatal(message); - } + /// + public void FatalException(string? message, Exception exception) + { + _inner.Fatal(exception, message); + } - /// - public void Fatal(string? message) - { - LogResolver.Resolve(typeof(T)).Fatal(message); - } + /// + public void Fatal(Exception exception, string? message) + { + _inner.Fatal(exception, message); + } - /// - public void Fatal(string message, params object[] args) - { - _inner.Fatal(CultureInfo.InvariantCulture, message, args); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, params object[] args) + { + _inner.Fatal(formatProvider, message, args); + } - /// - public void Fatal(string message, params object[] args) - { - LogResolver.Resolve(typeof(T)).Fatal(CultureInfo.InvariantCulture, message, args); - } + /// + public void Fatal(string? message) + { + _inner.Fatal(message); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Fatal(formatProvider, message, argument); - } + /// + public void Fatal(string? message) + { + LogResolver.Resolve(typeof(T)).Fatal(message); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Fatal(formatProvider, message, argument1, argument2); - } + /// + public void Fatal(string message, params object[] args) + { + _inner.Fatal(CultureInfo.InvariantCulture, message, args); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Fatal(formatProvider, message, argument1, argument2, argument3); - } + /// + public void Fatal(string message, params object[] args) + { + LogResolver.Resolve(typeof(T)).Fatal(CultureInfo.InvariantCulture, message, args); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument argument) - { - _inner.Debug(exception, messageFormat, argument); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Fatal(formatProvider, message, argument); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Debug(exception, messageFormat, argument1, argument2); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Fatal(formatProvider, message, argument1, argument2); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Fatal(formatProvider, message, argument1, argument2, argument3); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument argument) + { + _inner.Debug(exception, messageFormat, argument); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Debug(exception, messageFormat, argument1, argument2); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Info(Exception exception, string messageFormat, TArgument argument) - { - _inner.Info(exception, messageFormat, argument); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Info(exception, messageFormat, argument1, argument2); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Info(Exception exception, string messageFormat, TArgument argument) + { + _inner.Info(exception, messageFormat, argument); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Info(exception, messageFormat, argument1, argument2); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument argument) - { - _inner.Warn(exception, messageFormat, argument); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Warn(exception, messageFormat, argument1, argument2); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Info(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument argument) + { + _inner.Warn(exception, messageFormat, argument); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Warn(exception, messageFormat, argument1, argument2); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Error(Exception exception, string messageFormat, TArgument argument) - { - _inner.Error(exception, messageFormat, argument); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Error(exception, messageFormat, argument1, argument2); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Warn(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Error(Exception exception, string messageFormat, TArgument argument) + { + _inner.Error(exception, messageFormat, argument); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Error(exception, messageFormat, argument1, argument2); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument argument) - { - _inner.Fatal(exception, messageFormat, argument); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _inner.Fatal(exception, messageFormat, argument1, argument2); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Fatal(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument argument) + { + _inner.Fatal(exception, messageFormat, argument); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _inner.Fatal(exception, messageFormat, argument1, argument2); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Fatal(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - private void OnInnerLoggerReconfigured(object? sender, EventArgs e) - { - SetLogLevel(); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _inner.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } + + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - /// Works out the log level. - /// - /// - /// This was done so the Level property doesn't keep getting re-evaluated each time a Write method is called. - /// - private void SetLogLevel() + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _inner.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } + + private void OnInnerLoggerReconfigured(object? sender, EventArgs e) + { + SetLogLevel(); + } + + /// + /// Works out the log level. + /// + /// + /// This was done so the Level property doesn't keep getting re-evaluated each time a Write method is called. + /// + private void SetLogLevel() + { + foreach (var mapping in _mappings) { - foreach (var mapping in _mappings) + if (_inner.IsEnabled(mapping.Value)) { - if (_inner.IsEnabled(mapping.Value)) - { - Level = mapping.Key; - return; - } + Level = mapping.Key; + return; } - - // Default to Fatal, it should always be enabled anyway. - Level = LogLevel.Fatal; } + + // Default to Fatal, it should always be enabled anyway. + Level = LogLevel.Fatal; } } diff --git a/src/Splat.NLog/Splat.NLog.csproj b/src/Splat.NLog/Splat.NLog.csproj index abe9084d3..f8af5ddae 100644 --- a/src/Splat.NLog/Splat.NLog.csproj +++ b/src/Splat.NLog/Splat.NLog.csproj @@ -11,7 +11,7 @@ enable - + diff --git a/src/Splat.Ninject.Tests/DependencyResolverTests.cs b/src/Splat.Ninject.Tests/DependencyResolverTests.cs index 39c25651b..f8e3e5f4b 100644 --- a/src/Splat.Ninject.Tests/DependencyResolverTests.cs +++ b/src/Splat.Ninject.Tests/DependencyResolverTests.cs @@ -4,169 +4,168 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Linq; using FluentAssertions; using Ninject; + using Splat.Common.Test; + using Xunit; -namespace Splat.Ninject.Tests +namespace Splat.Ninject.Tests; + +/// +/// Tests to show the works correctly. +/// +public class DependencyResolverTests { /// - /// Tests to show the works correctly. + /// Should resolve views. + /// + [Fact] + public void NinjectDependencyResolver_Should_Resolve_Views() + { + var container = new StandardKernel(); + container.Bind>().To(); + container.Bind>().To(); + container.UseNinjectDependencyResolver(); + + var viewOne = Locator.Current.GetService(typeof(IViewFor)); + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewOne.Should().NotBeNull(); + viewOne.Should().BeOfType(); + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Should resolve views. /// - public class DependencyResolverTests + [Fact] + public void NinjectDependencyResolver_Should_Return_Null() { - /// - /// Should resolve views. - /// - [Fact] - public void NinjectDependencyResolver_Should_Resolve_Views() - { - var container = new StandardKernel(); - container.Bind>().To(); - container.Bind>().To(); - container.UseNinjectDependencyResolver(); - - var viewOne = Locator.Current.GetService(typeof(IViewFor)); - var viewTwo = Locator.Current.GetService(typeof(IViewFor)); - - viewOne.Should().NotBeNull(); - viewOne.Should().BeOfType(); - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Should resolve views. - /// - [Fact] - public void NinjectDependencyResolver_Should_Return_Null() - { - var container = new StandardKernel(); - container.UseNinjectDependencyResolver(); - - var viewOne = Locator.Current.GetService(typeof(IViewFor)); - - viewOne.Should().BeNull(); - } - - /// - /// Should resolve views. - /// - [Fact] - public void NinjectDependencyResolver_GetServices_Should_Return_Empty_Collection() - { - var container = new StandardKernel(); - container.UseNinjectDependencyResolver(); - - var viewOne = Locator.Current.GetServices(typeof(IViewFor)); - - viewOne.Should().BeEmpty(); - } - - /// - /// Should resolve views. - /// - [Fact] - public void NinjectDependencyResolver_Should_Resolve_Named_View() - { - var container = new StandardKernel(); - container.Bind>().To(); - container.UseNinjectDependencyResolver(); - - var viewTwo = Locator.Current.GetService(typeof(IViewFor)); - - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Should resolve view models. - /// - [Fact] - public void NinjectDependencyResolver_Should_Resolve_View_Models() - { - var container = new StandardKernel(); - container.Bind().ToSelf(); - container.Bind().ToSelf(); - container.UseNinjectDependencyResolver(); - - var vmOne = Locator.Current.GetService(); - var vmTwo = Locator.Current.GetService(); - - vmOne.Should().NotBeNull(); - vmTwo.Should().NotBeNull(); - } - - /// - /// Should resolve screen. - /// - [Fact] - public void NinjectDependencyResolver_Should_Resolve_Screen() - { - var container = new StandardKernel(); - container.Bind().ToConstant(new MockScreen()); - container.UseNinjectDependencyResolver(); - - var screen = Locator.Current.GetService(); - - screen.Should().NotBeNull(); - screen.Should().BeOfType(); - } - - /// - /// Should throw an exception if service registration call back called. - /// - [Fact(Skip = "Further testing required")] - public void NinjectDependencyResolver_Should_Throw_If_UnregisterCurrent_Called() - { - var container = new StandardKernel(); - container.UseNinjectDependencyResolver(); - - Action result = () => - Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); - - result.Should().Throw(); - } - - /// - /// Should unregister all. - /// - [Fact] - public void NinjectDependencyResolver_Should_UnregisterAll() - { - var container = new StandardKernel(); - container.Bind().ToConstant(new MockScreen()); - container.UseNinjectDependencyResolver(); - - var screen = Locator.Current.GetService(); - - screen.Should().NotBeNull(); - screen.Should().BeOfType(); - - Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); - - var result = Locator.Current.GetService(); - result.Should().BeNull(); - } - - /// - /// Should throw an exception if service registration call back called. - /// - [Fact] - public void NinjectDependencyResolver_Should_Throw_If_ServiceRegistionCallback_Called() - { - var container = new StandardKernel(); - container.UseNinjectDependencyResolver(); - - var result = Record.Exception(() => - Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); - - result.Should().BeOfType(); - } + var container = new StandardKernel(); + container.UseNinjectDependencyResolver(); + + var viewOne = Locator.Current.GetService(typeof(IViewFor)); + + viewOne.Should().BeNull(); + } + + /// + /// Should resolve views. + /// + [Fact] + public void NinjectDependencyResolver_GetServices_Should_Return_Empty_Collection() + { + var container = new StandardKernel(); + container.UseNinjectDependencyResolver(); + + var viewOne = Locator.Current.GetServices(typeof(IViewFor)); + + viewOne.Should().BeEmpty(); + } + + /// + /// Should resolve views. + /// + [Fact] + public void NinjectDependencyResolver_Should_Resolve_Named_View() + { + var container = new StandardKernel(); + container.Bind>().To(); + container.UseNinjectDependencyResolver(); + + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Should resolve view models. + /// + [Fact] + public void NinjectDependencyResolver_Should_Resolve_View_Models() + { + var container = new StandardKernel(); + container.Bind().ToSelf(); + container.Bind().ToSelf(); + container.UseNinjectDependencyResolver(); + + var vmOne = Locator.Current.GetService(); + var vmTwo = Locator.Current.GetService(); + + vmOne.Should().NotBeNull(); + vmTwo.Should().NotBeNull(); + } + + /// + /// Should resolve screen. + /// + [Fact] + public void NinjectDependencyResolver_Should_Resolve_Screen() + { + var container = new StandardKernel(); + container.Bind().ToConstant(new MockScreen()); + container.UseNinjectDependencyResolver(); + + var screen = Locator.Current.GetService(); + + screen.Should().NotBeNull(); + screen.Should().BeOfType(); + } + + /// + /// Should throw an exception if service registration call back called. + /// + [Fact(Skip = "Further testing required")] + public void NinjectDependencyResolver_Should_Throw_If_UnregisterCurrent_Called() + { + var container = new StandardKernel(); + container.UseNinjectDependencyResolver(); + + Action result = () => + Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); + + result.Should().Throw(); + } + + /// + /// Should unregister all. + /// + [Fact] + public void NinjectDependencyResolver_Should_UnregisterAll() + { + var container = new StandardKernel(); + container.Bind().ToConstant(new MockScreen()); + container.UseNinjectDependencyResolver(); + + var screen = Locator.Current.GetService(); + + screen.Should().NotBeNull(); + screen.Should().BeOfType(); + + Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); + + var result = Locator.Current.GetService(); + result.Should().BeNull(); + } + + /// + /// Should throw an exception if service registration call back called. + /// + [Fact] + public void NinjectDependencyResolver_Should_Throw_If_ServiceRegistionCallback_Called() + { + var container = new StandardKernel(); + container.UseNinjectDependencyResolver(); + + var result = Record.Exception(() => + Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { })); + + result.Should().BeOfType(); } } diff --git a/src/Splat.Ninject.Tests/NInjectDependencyResolverTests.cs b/src/Splat.Ninject.Tests/NInjectDependencyResolverTests.cs index 5239c3f12..d1282335a 100644 --- a/src/Splat.Ninject.Tests/NInjectDependencyResolverTests.cs +++ b/src/Splat.Ninject.Tests/NInjectDependencyResolverTests.cs @@ -1,61 +1,60 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; + using Ninject; + using Splat.Tests.ServiceLocation; + using Xunit; -namespace Splat.Ninject.Tests +namespace Splat.Ninject.Tests; + +/// +/// Unit Tests for the Modern Dependency Resolver. +/// +public sealed class NInjectDependencyResolverTests : BaseDependencyResolverTests { /// - /// Unit Tests for the Modern Dependency Resolver. + /// Test to ensure container allows registration with null service type. + /// Should really be brought down to the , + /// it fails for some of the DIs. /// - public sealed class NInjectDependencyResolverTests : BaseDependencyResolverTests + [Fact] + public void Can_Register_And_Resolve_Null_Types() { - /// - /// Test to ensure container allows registration with null service type. - /// Should really be brought down to the , - /// it fails for some of the DIs. - /// - [Fact] - public void Can_Register_And_Resolve_Null_Types() - { - var resolver = GetDependencyResolver(); - var foo = 5; - resolver.Register(() => foo, null); - - var bar = 4; - var contract = "foo"; - resolver.Register(() => bar, null, contract); - - Assert.True(resolver.HasRegistration(null)); - var value = resolver.GetService(null); - Assert.Equal(foo, value); - - Assert.True(resolver.HasRegistration(null, contract)); - value = resolver.GetService(null, contract); - Assert.Equal(bar, value); - - var values = resolver.GetServices(null); - Assert.Equal(1, values.Count()); - - resolver.UnregisterCurrent(null); - var valuesNC = resolver.GetServices(null); - Assert.Equal(0, valuesNC.Count()); - var valuesC = resolver.GetServices(null, contract); - Assert.Equal(1, valuesC.Count()); - - resolver.UnregisterAll(null); - valuesNC = resolver.GetServices(null); - Assert.Equal(0, valuesNC.Count()); - - resolver.UnregisterAll(null, contract); - valuesC = resolver.GetServices(null, contract); - Assert.Equal(0, valuesC.Count()); - } - - /// - protected override NinjectDependencyResolver GetDependencyResolver() => new(new StandardKernel()); + var resolver = GetDependencyResolver(); + var foo = 5; + resolver.Register(() => foo, null); + + var bar = 4; + var contract = "foo"; + resolver.Register(() => bar, null, contract); + + Assert.True(resolver.HasRegistration(null)); + var value = resolver.GetService(null); + Assert.Equal(foo, value); + + Assert.True(resolver.HasRegistration(null, contract)); + value = resolver.GetService(null, contract); + Assert.Equal(bar, value); + + var values = resolver.GetServices(null); + Assert.Equal(1, values.Count()); + + resolver.UnregisterCurrent(null); + var valuesNC = resolver.GetServices(null); + Assert.Equal(0, valuesNC.Count()); + var valuesC = resolver.GetServices(null, contract); + Assert.Equal(1, valuesC.Count()); + + resolver.UnregisterAll(null); + valuesNC = resolver.GetServices(null); + Assert.Equal(0, valuesNC.Count()); + + resolver.UnregisterAll(null, contract); + valuesC = resolver.GetServices(null, contract); + Assert.Equal(0, valuesC.Count()); } + + /// + protected override NinjectDependencyResolver GetDependencyResolver() => new(new StandardKernel()); } diff --git a/src/Splat.Ninject/NinjectDependencyResolver.cs b/src/Splat.Ninject/NinjectDependencyResolver.cs index 958091a79..90f9beb15 100644 --- a/src/Splat.Ninject/NinjectDependencyResolver.cs +++ b/src/Splat.Ninject/NinjectDependencyResolver.cs @@ -5,174 +5,173 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; + using Ninject; using Ninject.Planning.Bindings; -namespace Splat.Ninject +namespace Splat.Ninject; + +/// +/// Ninject implementation for . +/// +/// +public class NinjectDependencyResolver : IDependencyResolver { + private IKernel _kernel; + /// - /// Ninject implementation for . + /// Initializes a new instance of the class. /// - /// - public class NinjectDependencyResolver : IDependencyResolver + /// The kernel. + public NinjectDependencyResolver(IKernel kernel) { - private IKernel _kernel; + _kernel = kernel; + } + + /// + public virtual object? GetService(Type? serviceType, string? contract = null) => + GetServices(serviceType, contract).LastOrDefault()!; - /// - /// Initializes a new instance of the class. - /// - /// The kernel. - public NinjectDependencyResolver(IKernel kernel) + /// + public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; + if (serviceType is null) { - _kernel = kernel; + serviceType = typeof(NullServiceType); } - /// - public virtual object? GetService(Type? serviceType, string? contract = null) => - GetServices(serviceType, contract).LastOrDefault()!; - - /// - public virtual IEnumerable GetServices(Type? serviceType, string? contract = null) + if (isNull) { - var isNull = serviceType is null; - if (serviceType is null) + try { - serviceType = typeof(NullServiceType); + return _kernel.GetAll(typeof(NullServiceType), contract).ToArray(); } - - if (isNull) + catch { - try - { - return _kernel.GetAll(typeof(NullServiceType), contract).ToArray(); - } - catch - { - return Array.Empty(); - } + return Array.Empty(); } - - return _kernel.GetAll(serviceType, contract); } - /// - public bool HasRegistration(Type? serviceType, string? contract = null) - { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - return _kernel.CanResolve(serviceType, metadata => IsCorrectMetadata(metadata, contract)); - } + return _kernel.GetAll(serviceType, contract); + } - /// - public virtual void Register(Func factory, Type? serviceType, string? contract = null) + /// + public bool HasRegistration(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - var isNull = serviceType is null; + serviceType = typeof(NullServiceType); + } - if (isNull) - { - serviceType = typeof(NullServiceType); - } + return _kernel.CanResolve(serviceType, metadata => IsCorrectMetadata(metadata, contract)); + } - if (string.IsNullOrWhiteSpace(contract)) - { - _kernel.Bind(serviceType).ToMethod(_ => factory()); - return; - } + /// + public virtual void Register(Func factory, Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; - _kernel.Bind(serviceType).ToMethod(_ => factory()).Named(contract); + if (isNull) + { + serviceType = typeof(NullServiceType); } - /// - public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) + if (string.IsNullOrWhiteSpace(contract)) { - var isNull = serviceType is null; - - if (isNull) - { - serviceType = typeof(NullServiceType); - } - - var bindings = _kernel.GetBindings(serviceType).ToArray(); - - if (bindings is null || bindings.Length < 1) - { - return; - } + _kernel.Bind(serviceType).ToMethod(_ => factory()); + return; + } - var matchingBinding = bindings.LastOrDefault(x => IsCorrectMetadata(x.BindingConfiguration.Metadata, contract)); + _kernel.Bind(serviceType).ToMethod(_ => factory()).Named(contract); + } - if (matchingBinding is null) - { - return; - } + /// + public virtual void UnregisterCurrent(Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; - _kernel.RemoveBinding(matchingBinding); + if (isNull) + { + serviceType = typeof(NullServiceType); } - /// - public virtual void UnregisterAll(Type? serviceType, string? contract = null) - { - var isNull = serviceType is null; + var bindings = _kernel.GetBindings(serviceType).ToArray(); - if (isNull) - { - serviceType = typeof(NullServiceType); - } + if (bindings is null || bindings.Length < 1) + { + return; + } - var bindings = _kernel.GetBindings(serviceType).ToArray(); + var matchingBinding = bindings.LastOrDefault(x => IsCorrectMetadata(x.BindingConfiguration.Metadata, contract)); - if (bindings is null || bindings.Length < 1) - { - return; - } + if (matchingBinding is null) + { + return; + } - var matchingBinding = bindings.Where(x => IsCorrectMetadata(x.BindingConfiguration.Metadata, contract)).ToArray(); + _kernel.RemoveBinding(matchingBinding); + } - if (matchingBinding.Length < 1) - { - return; - } + /// + public virtual void UnregisterAll(Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; - foreach (IBinding binding in matchingBinding) - { - _kernel.RemoveBinding(binding); - } + if (isNull) + { + serviceType = typeof(NullServiceType); } - /// - public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + var bindings = _kernel.GetBindings(serviceType).ToArray(); + + if (bindings is null || bindings.Length < 1) { - throw new NotImplementedException(); + return; } - /// - public void Dispose() + var matchingBinding = bindings.Where(x => IsCorrectMetadata(x.BindingConfiguration.Metadata, contract)).ToArray(); + + if (matchingBinding.Length < 1) { - Dispose(true); - GC.SuppressFinalize(this); + return; } - /// - /// Disposes of the instance. - /// - /// Whether or not the instance is disposing. - protected virtual void Dispose(bool disposing) + foreach (var binding in matchingBinding) { - if (disposing) - { - _kernel?.Dispose(); - } + _kernel.RemoveBinding(binding); } + } - private static bool IsCorrectMetadata(global::Ninject.Planning.Bindings.IBindingMetadata metadata, string? contract) + /// + public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + { + throw new NotImplementedException(); + } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Disposes of the instance. + /// + /// Whether or not the instance is disposing. + protected virtual void Dispose(bool disposing) + { + if (disposing) { - return (metadata?.Name is null && string.IsNullOrWhiteSpace(contract)) - || (metadata?.Name is not null && metadata.Name.Equals(contract, StringComparison.OrdinalIgnoreCase)); + _kernel?.Dispose(); } } + + private static bool IsCorrectMetadata(global::Ninject.Planning.Bindings.IBindingMetadata metadata, string? contract) + { + return (metadata?.Name is null && string.IsNullOrWhiteSpace(contract)) + || (metadata?.Name is not null && metadata.Name.Equals(contract, StringComparison.OrdinalIgnoreCase)); + } } diff --git a/src/Splat.Ninject/SplatNinjectExtensions.cs b/src/Splat.Ninject/SplatNinjectExtensions.cs index d379c801b..31b13f238 100644 --- a/src/Splat.Ninject/SplatNinjectExtensions.cs +++ b/src/Splat.Ninject/SplatNinjectExtensions.cs @@ -5,18 +5,17 @@ using Ninject; -namespace Splat.Ninject +namespace Splat.Ninject; + +/// +/// Extension methods for the Ninject adapter. +/// +public static class SplatNinjectExtensions { /// - /// Extension methods for the Ninject adapter. + /// Initializes an instance of that overrides the default . /// - public static class SplatNinjectExtensions - { - /// - /// Initializes an instance of that overrides the default . - /// - /// The kernel. - public static void UseNinjectDependencyResolver(this IKernel kernel) => - Locator.SetLocator(new NinjectDependencyResolver(kernel)); - } + /// The kernel. + public static void UseNinjectDependencyResolver(this IKernel kernel) => + Locator.SetLocator(new NinjectDependencyResolver(kernel)); } diff --git a/src/Splat.Prism.Forms/PrismApplication.cs b/src/Splat.Prism.Forms/PrismApplication.cs index aad49b131..cb22f53da 100644 --- a/src/Splat.Prism.Forms/PrismApplication.cs +++ b/src/Splat.Prism.Forms/PrismApplication.cs @@ -3,34 +3,30 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; using Prism; using Prism.Ioc; [assembly: Xamarin.Forms.XmlnsDefinition("http://prismlibrary.com", "Splat.Prism.Forms")] -namespace Splat.Prism.Forms +namespace Splat.Prism.Forms; + +/// +/// A application instance which supports Prism types. +/// +public abstract class PrismApplication : PrismApplicationBase { /// - /// A application instance which supports Prism types. + /// Initializes a new instance of the class. /// - public abstract class PrismApplication : PrismApplicationBase + /// An initializer for initializing the platform. + protected PrismApplication(IPlatformInitializer? initializer = null) + : base(initializer) { - /// - /// Initializes a new instance of the class. - /// - /// An initializer for initializing the platform. - protected PrismApplication(IPlatformInitializer? initializer = null) - : base(initializer) - { - } + } - /// - protected override IContainerExtension CreateContainerExtension() - { - return new SplatContainerExtension(); - } + /// + protected override IContainerExtension CreateContainerExtension() + { + return new SplatContainerExtension(); } } diff --git a/src/Splat.Prism.Tests/DependencyResolverTests.cs b/src/Splat.Prism.Tests/DependencyResolverTests.cs index 84c184408..302101fa9 100644 --- a/src/Splat.Prism.Tests/DependencyResolverTests.cs +++ b/src/Splat.Prism.Tests/DependencyResolverTests.cs @@ -11,279 +11,278 @@ using Xunit; -namespace Splat.Prism.Tests +namespace Splat.Prism.Tests; + +/// +/// Tests to show the works correctly. +/// +public class DependencyResolverTests { /// - /// Tests to show the works correctly. + /// Tracks CreateScope not being implemented in case it's changed in future. + /// + [Fact] + public void CreateScope_Throws_NotImplementedException() + { + using var container = new SplatContainerExtension(); + Assert.Throws(() => container.CreateScope()); + } + + /// + /// Tracks RegisterScoped not being implemented in case it's changed in future. + /// + [Fact] + public void RegisterScoped_Throws_NotImplementedException() + { + using var container = new SplatContainerExtension(); + Assert.Throws(() => container.RegisterScoped( + typeof(IViewFor), + () => new ViewOne())); + } + + /// + /// Tracks RegisterManySingleton not being implemented in case it's changed in future. + /// + [Fact] + public void RegisterManySingleton_Throws_NotImplementedException() + { + using var container = new SplatContainerExtension(); + Assert.Throws(() => container.RegisterManySingleton( + typeof(IViewFor), + typeof(ViewOne))); + } + + /// + /// Test to ensure register many succeeds. + /// + [Fact] + public void RegisterMany_Succeeds() + { + using var container = new SplatContainerExtension(); + container.RegisterMany( + typeof(IViewFor), + typeof(ViewOne)); + } + + /// + /// Test to ensure a simple resolve succeeds. + /// + [Fact] + public void Resolve_Succeeds() + { + using var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewOne)); + + var instance = container.Resolve(typeof(IViewFor)); + + Assert.NotNull(instance); + } + + /// + /// Test to ensure a resolve with name succeeds. + /// + [Fact] + public void Resolve_With_Name_Succeeds() + { + using var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewOne), "name"); + + var instance = container.Resolve(typeof(IViewFor), "name"); + + Assert.NotNull(instance); + } + + /// + /// Test to ensure a simple is registered check succeeds. + /// + [Fact] + public void IsRegistered_Returns_True() + { + using var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewOne)); + + var instance = container.IsRegistered(typeof(IViewFor)); + + Assert.True(instance); + } + + /// + /// Test to ensure a simple is registered check succeeds. + /// + [Fact] + public void IsRegistered_With_Name_Returns_True() + { + using var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewOne), "name"); + + var instance = container.IsRegistered(typeof(IViewFor), "name"); + + Assert.True(instance); + } + + /// + /// Should resolve the views. + /// + [Fact] + public void PrismDependencyResolver_Should_Resolve_Views() + { + using var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewOne)); + container.Register(typeof(IViewFor), typeof(ViewTwo)); + + var viewOne = Locator.Current.GetService(typeof(IViewFor)); + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewOne.Should().NotBeNull(); + viewOne.Should().BeOfType(); + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Should resolve the views. + /// + [Fact] + public void PrismDependencyResolver_Should_Resolve_Named_View() + { + using var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewTwo), "Other"); + + var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other"); + + viewTwo.Should().NotBeNull(); + viewTwo.Should().BeOfType(); + } + + /// + /// Should resolve the view models. + /// + [Fact] + public void PrismDependencyResolver_Should_Resolve_View_Models() + { + using var container = new SplatContainerExtension(); + + container.Register(typeof(ViewModelOne), typeof(ViewModelOne)); + container.Register(typeof(ViewModelTwo), typeof(ViewModelTwo)); + + var vmOne = Locator.Current.GetService(); + var vmTwo = Locator.Current.GetService(); + + vmOne.Should().NotBeNull(); + vmTwo.Should().NotBeNull(); + } + + /// + /// Should resolve the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_Resolve_Screen() + { + using var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); + + var screen = Locator.Current.GetService(); + + screen.Should().NotBeNull(); + screen.Should().BeOfType(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_UnregisterCurrent_Screen() + { + using var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); + + Locator.Current.GetService().Should().NotBeNull(); + + Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); + + Locator.Current.GetService().Should().BeNull(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_UnregisterCurrent_Screen_With_Contract() + { + using var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); + + Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_UnregisterAll_Screen() + { + using var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); + + Locator.Current.GetService().Should().NotBeNull(); + + Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); + + Locator.Current.GetService().Should().BeNull(); + } + + /// + /// Should unregister the screen. /// - public class DependencyResolverTests + [Fact] + public void PrismDependencyResolver_Should_UnregisterAll_Screen_With_Contract() { - /// - /// Tracks CreateScope not being implemented in case it's changed in future. - /// - [Fact] - public void CreateScope_Throws_NotImplementedException() - { - using var container = new SplatContainerExtension(); - Assert.Throws(() => container.CreateScope()); - } - - /// - /// Tracks RegisterScoped not being implemented in case it's changed in future. - /// - [Fact] - public void RegisterScoped_Throws_NotImplementedException() - { - using var container = new SplatContainerExtension(); - Assert.Throws(() => container.RegisterScoped( - typeof(IViewFor), - () => new ViewOne())); - } - - /// - /// Tracks RegisterManySingleton not being implemented in case it's changed in future. - /// - [Fact] - public void RegisterManySingleton_Throws_NotImplementedException() - { - using var container = new SplatContainerExtension(); - Assert.Throws(() => container.RegisterManySingleton( - typeof(IViewFor), - typeof(ViewOne))); - } - - /// - /// Test to ensure register many succeeds. - /// - [Fact] - public void RegisterMany_Succeeds() - { - using var container = new SplatContainerExtension(); - container.RegisterMany( - typeof(IViewFor), - typeof(ViewOne)); - } - - /// - /// Test to ensure a simple resolve succeeds. - /// - [Fact] - public void Resolve_Succeeds() - { - using var container = new SplatContainerExtension(); - container.Register(typeof(IViewFor), typeof(ViewOne)); - - var instance = container.Resolve(typeof(IViewFor)); - - Assert.NotNull(instance); - } - - /// - /// Test to ensure a resolve with name succeeds. - /// - [Fact] - public void Resolve_With_Name_Succeeds() - { - using var container = new SplatContainerExtension(); - container.Register(typeof(IViewFor), typeof(ViewOne), "name"); - - var instance = container.Resolve(typeof(IViewFor), "name"); - - Assert.NotNull(instance); - } - - /// - /// Test to ensure a simple is registered check succeeds. - /// - [Fact] - public void IsRegistered_Returns_True() - { - using var container = new SplatContainerExtension(); - container.Register(typeof(IViewFor), typeof(ViewOne)); - - var instance = container.IsRegistered(typeof(IViewFor)); - - Assert.True(instance); - } - - /// - /// Test to ensure a simple is registered check succeeds. - /// - [Fact] - public void IsRegistered_With_Name_Returns_True() - { - using var container = new SplatContainerExtension(); - container.Register(typeof(IViewFor), typeof(ViewOne), "name"); - - var instance = container.IsRegistered(typeof(IViewFor), "name"); - - Assert.True(instance); - } - - /// - /// Should resolve the views. - /// - [Fact] - public void PrismDependencyResolver_Should_Resolve_Views() - { - using var container = new SplatContainerExtension(); - container.Register(typeof(IViewFor), typeof(ViewOne)); - container.Register(typeof(IViewFor), typeof(ViewTwo)); - - var viewOne = Locator.Current.GetService(typeof(IViewFor)); - var viewTwo = Locator.Current.GetService(typeof(IViewFor)); - - viewOne.Should().NotBeNull(); - viewOne.Should().BeOfType(); - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Should resolve the views. - /// - [Fact] - public void PrismDependencyResolver_Should_Resolve_Named_View() - { - using var container = new SplatContainerExtension(); - container.Register(typeof(IViewFor), typeof(ViewTwo), "Other"); - - var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other"); - - viewTwo.Should().NotBeNull(); - viewTwo.Should().BeOfType(); - } - - /// - /// Should resolve the view models. - /// - [Fact] - public void PrismDependencyResolver_Should_Resolve_View_Models() - { - using var container = new SplatContainerExtension(); - - container.Register(typeof(ViewModelOne), typeof(ViewModelOne)); - container.Register(typeof(ViewModelTwo), typeof(ViewModelTwo)); - - var vmOne = Locator.Current.GetService(); - var vmTwo = Locator.Current.GetService(); - - vmOne.Should().NotBeNull(); - vmTwo.Should().NotBeNull(); - } - - /// - /// Should resolve the screen. - /// - [Fact] - public void PrismDependencyResolver_Should_Resolve_Screen() - { - using var builder = new SplatContainerExtension(); - builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); - - var screen = Locator.Current.GetService(); - - screen.Should().NotBeNull(); - screen.Should().BeOfType(); - } - - /// - /// Should unregister the screen. - /// - [Fact] - public void PrismDependencyResolver_Should_UnregisterCurrent_Screen() - { - using var builder = new SplatContainerExtension(); - builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); - - Locator.Current.GetService().Should().NotBeNull(); - - Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); - - Locator.Current.GetService().Should().BeNull(); - } - - /// - /// Should unregister the screen. - /// - [Fact] - public void PrismDependencyResolver_Should_UnregisterCurrent_Screen_With_Contract() - { - using var builder = new SplatContainerExtension(); - builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); - - Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); - - Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen), nameof(MockScreen)); - - Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); - } - - /// - /// Should unregister the screen. - /// - [Fact] - public void PrismDependencyResolver_Should_UnregisterAll_Screen() - { - using var builder = new SplatContainerExtension(); - builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); - - Locator.Current.GetService().Should().NotBeNull(); - - Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); - - Locator.Current.GetService().Should().BeNull(); - } - - /// - /// Should unregister the screen. - /// - [Fact] - public void PrismDependencyResolver_Should_UnregisterAll_Screen_With_Contract() - { - using var builder = new SplatContainerExtension(); - builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); - - Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); - - Locator.CurrentMutable.UnregisterAll(typeof(IScreen), nameof(MockScreen)); - - Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); - } - - /// - /// Check to ensure the correct logger is returned. - /// - /// - /// Introduced for Splat #331. - /// - [Fact] - public void PrismDependencyResolver_Should_ReturnRegisteredLogger() - { - using var c = new SplatContainerExtension(); - c.Register(typeof(ILogger), typeof(ConsoleLogger)); - Locator.CurrentMutable.RegisterConstant( - new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), - typeof(ILogManager)); - - var d = Splat.Locator.Current.GetService(); - Assert.IsType(d); - } - - /// - /// Test that a pre-init logger isn't overriden. - /// - /// - /// Introduced for Splat #331. - /// - [Fact] - public void PrismDependencyResolver_PreInit_Should_ReturnRegisteredLogger() - { - using var c = new SplatContainerExtension(); - c.RegisterInstance(typeof(ILogManager), new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); - - var d = Splat.Locator.Current.GetService(); - Assert.IsType(d); - } + using var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).Should().NotBeNull(); + + Locator.CurrentMutable.UnregisterAll(typeof(IScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).Should().BeNull(); + } + + /// + /// Check to ensure the correct logger is returned. + /// + /// + /// Introduced for Splat #331. + /// + [Fact] + public void PrismDependencyResolver_Should_ReturnRegisteredLogger() + { + using var c = new SplatContainerExtension(); + c.Register(typeof(ILogger), typeof(ConsoleLogger)); + Locator.CurrentMutable.RegisterConstant( + new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), + typeof(ILogManager)); + + var d = Splat.Locator.Current.GetService(); + Assert.IsType(d); + } + + /// + /// Test that a pre-init logger isn't overriden. + /// + /// + /// Introduced for Splat #331. + /// + [Fact] + public void PrismDependencyResolver_PreInit_Should_ReturnRegisteredLogger() + { + using var c = new SplatContainerExtension(); + c.RegisterInstance(typeof(ILogManager), new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); + + var d = Splat.Locator.Current.GetService(); + Assert.IsType(d); } } diff --git a/src/Splat.Prism/SplatContainerExtension.cs b/src/Splat.Prism/SplatContainerExtension.cs index cab36beac..e109bda8e 100644 --- a/src/Splat.Prism/SplatContainerExtension.cs +++ b/src/Splat.Prism/SplatContainerExtension.cs @@ -5,289 +5,290 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Linq; using System.Threading; + using Prism.Ioc; -namespace Splat.Prism +namespace Splat.Prism; + +/// +/// A container for the Prism application. +/// +[System.Diagnostics.CodeAnalysis.SuppressMessage("Analyzers", "CA1065: Don't throw exceptions from properties", Justification = "Deliberate usage")] +public class SplatContainerExtension : IContainerExtension, IDisposable { + private readonly ConcurrentDictionary<(Type type, string? contract), Type> _types = new(); + private Action? _disposeAction; + /// - /// A container for the Prism application. + /// Initializes a new instance of the class. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Analyzers", "CA1065: Don't throw exceptions from properties", Justification = "Deliberate usage")] - public class SplatContainerExtension : IContainerExtension, IDisposable + public SplatContainerExtension() { - private readonly ConcurrentDictionary<(Type type, string? contract), Type> _types = new(); - private Action? _disposeAction; + Locator.SetLocator(Instance); + _disposeAction = () => Locator.SetLocator(new ModernDependencyResolver()); + } - /// - /// Initializes a new instance of the class. - /// - public SplatContainerExtension() - { - Locator.SetLocator(Instance); - _disposeAction = () => Locator.SetLocator(new ModernDependencyResolver()); - } + /// + /// Gets the dependency resolver. + /// + public IDependencyResolver Instance { get; } = new ModernDependencyResolver(); - /// - /// Gets the dependency resolver. - /// - public IDependencyResolver Instance { get; } = new ModernDependencyResolver(); + /// + public IScopedProvider CurrentScope => throw new NotImplementedException(); - /// - public IScopedProvider CurrentScope => throw new NotImplementedException(); + /// + public IScopedProvider CreateScope() + { + throw new NotSupportedException(); + } - /// - public IScopedProvider CreateScope() - { - throw new NotSupportedException(); - } + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + /// + public void FinalizeExtension() + { + } - /// - public void FinalizeExtension() - { - } + /// + public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) + { + throw new NotSupportedException(); + } - /// - public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) - { - throw new NotSupportedException(); - } + /// + public bool IsRegistered(Type type) + { + return Instance.HasRegistration(type); + } - /// - public bool IsRegistered(Type type) - { - return Instance.HasRegistration(type); - } + /// + public bool IsRegistered(Type type, string name) + { + return Instance.HasRegistration(type, name); + } - /// - public bool IsRegistered(Type type, string name) - { - return Instance.HasRegistration(type, name); - } + /// + public IContainerRegistry RegisterManySingleton(Type type, params Type[] serviceTypes) + { + throw new NotSupportedException(); + } - /// - public IContainerRegistry RegisterManySingleton(Type type, params Type[] serviceTypes) - { - throw new NotSupportedException(); - } + /// + public IContainerRegistry Register(Type from, Type to) + { + _types[(from, null)] = to; + Instance.Register(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from); + return this; + } - /// - public IContainerRegistry Register(Type from, Type to) - { - _types[(from, null)] = to; - Instance.Register(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from); - return this; - } + /// + /// Registers an object with the default registration func. + /// + /// The type to transform from. + /// The type to transform to. + /// A creation func for generating the type. + /// The container registry for builder operations. + public IContainerRegistry Register(Type from, Type to, Func defaultCreationFunc) + { + _types[(from, null)] = to; + Instance.Register(defaultCreationFunc, from); + return this; + } - /// - /// Registers an object with the default registration func. - /// - /// The type to transform from. - /// The type to transform to. - /// A creation func for generating the type. - /// The container registry for builder operations. - public IContainerRegistry Register(Type from, Type to, Func defaultCreationFunc) - { - _types[(from, null)] = to; - Instance.Register(defaultCreationFunc, from); - return this; - } + /// + public IContainerRegistry Register(Type from, Type to, string name) + { + _types[(from, name)] = to; + Instance.Register(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from, name); + return this; + } - /// - public IContainerRegistry Register(Type from, Type to, string name) - { - _types[(from, name)] = to; - Instance.Register(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from, name); - return this; - } + /// + public IContainerRegistry Register(Type type, Func factoryMethod) + { + Instance.Register(factoryMethod, type); + return this; + } - /// - public IContainerRegistry Register(Type type, Func factoryMethod) - { - Instance.Register(factoryMethod, type); - return this; - } + /// + public IContainerRegistry Register(Type type, Func factoryMethod) + { + Instance.Register(() => factoryMethod(this), type); + return this; + } - /// - public IContainerRegistry Register(Type type, Func factoryMethod) + /// + public IContainerRegistry RegisterMany(Type type, params Type[] serviceTypes) + { + if (serviceTypes is null) { - Instance.Register(() => factoryMethod(this), type); return this; } - /// - public IContainerRegistry RegisterMany(Type type, params Type[] serviceTypes) + foreach (var serviceType in serviceTypes) { - if (serviceTypes is null) - { - return this; - } + Instance.Register(() => Activator.CreateInstance(type) ?? throw new InvalidOperationException("Could not create type"), serviceType); + } - foreach (Type serviceType in serviceTypes) - { - Instance.Register(() => Activator.CreateInstance(type) ?? throw new InvalidOperationException("Could not create type"), serviceType); - } + return this; + } - return this; - } + /// + public IContainerRegistry RegisterScoped(Type @from, Type to) + { + throw new NotSupportedException(); + } - /// - public IContainerRegistry RegisterScoped(Type @from, Type to) - { - throw new NotSupportedException(); - } + /// + public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) + { + throw new NotSupportedException(); + } - /// - public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) - { - throw new NotSupportedException(); - } + /// + /// Registers an object with the default registration func. + /// + /// The type to transform from. + /// The type to transform to. + /// The contract name. + /// A creation func for generating the type. + /// The container registry for builder operations. + public IContainerRegistry Register(Type from, Type to, string name, Func defaultCreationFunc) + { + _types[(from, name)] = to; + Instance.Register(defaultCreationFunc, from, name); + return this; + } - /// - /// Registers an object with the default registration func. - /// - /// The type to transform from. - /// The type to transform to. - /// The contract name. - /// A creation func for generating the type. - /// The container registry for builder operations. - public IContainerRegistry Register(Type from, Type to, string name, Func defaultCreationFunc) - { - _types[(from, name)] = to; - Instance.Register(defaultCreationFunc, from, name); - return this; - } + /// + public IContainerRegistry RegisterInstance(Type type, object instance) + { + Instance.RegisterConstant(instance, type); + return this; + } - /// - public IContainerRegistry RegisterInstance(Type type, object instance) - { - Instance.RegisterConstant(instance, type); - return this; - } + /// + public IContainerRegistry RegisterInstance(Type type, object instance, string name) + { + Instance.RegisterConstant(instance, type, name); + return this; + } - /// - public IContainerRegistry RegisterInstance(Type type, object instance, string name) - { - Instance.RegisterConstant(instance, type, name); - return this; - } + /// + public IContainerRegistry RegisterSingleton(Type from, Type to) + { + _types[(from, null)] = to; + Instance.RegisterLazySingleton(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from); + return this; + } - /// - public IContainerRegistry RegisterSingleton(Type from, Type to) - { - _types[(from, null)] = to; - Instance.RegisterLazySingleton(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from); - return this; - } + /// + /// Registers an object with the default registration func. + /// + /// The type to transform from. + /// The type to transform to. + /// A creation func for generating the type. + /// The container registry for builder operations. + public IContainerRegistry RegisterSingleton(Type from, Type to, Func defaultCreationFunc) + { + _types[(from, null)] = to; + Instance.RegisterLazySingleton(defaultCreationFunc, from); + return this; + } - /// - /// Registers an object with the default registration func. - /// - /// The type to transform from. - /// The type to transform to. - /// A creation func for generating the type. - /// The container registry for builder operations. - public IContainerRegistry RegisterSingleton(Type from, Type to, Func defaultCreationFunc) - { - _types[(from, null)] = to; - Instance.RegisterLazySingleton(defaultCreationFunc, from); - return this; - } + /// + /// Registers an object with the default registration func. + /// + /// The type to transform from. + /// The type to transform to. + /// The contract name. + /// A creation func for generating the type. + /// The container registry for builder operations. + public IContainerRegistry RegisterSingleton(Type from, Type to, string name, Func defaultCreationFunc) + { + _types[(from, name)] = to; + Instance.RegisterLazySingleton(defaultCreationFunc, from); + return this; + } - /// - /// Registers an object with the default registration func. - /// - /// The type to transform from. - /// The type to transform to. - /// The contract name. - /// A creation func for generating the type. - /// The container registry for builder operations. - public IContainerRegistry RegisterSingleton(Type from, Type to, string name, Func defaultCreationFunc) - { - _types[(from, name)] = to; - Instance.RegisterLazySingleton(defaultCreationFunc, from); - return this; - } + /// + public IContainerRegistry RegisterSingleton(Type from, Type to, string name) + { + _types[(from, null)] = to; + Instance.RegisterLazySingleton(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from, name); + return this; + } - /// - public IContainerRegistry RegisterSingleton(Type from, Type to, string name) - { - _types[(from, null)] = to; - Instance.RegisterLazySingleton(() => Activator.CreateInstance(to) ?? throw new InvalidOperationException("Could not create type"), from, name); - return this; - } + /// + public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) + { + throw new NotSupportedException(); + } - /// - public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) - { - throw new NotSupportedException(); - } + /// + public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) + { + throw new NotSupportedException(); + } - /// - public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) - { - throw new NotSupportedException(); - } + /// + public object? Resolve(Type type) + { + return Instance.GetService(type); + } - /// - public object? Resolve(Type type) + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1316:Tuple element names should use correct casing", Justification = "Defined by outside interface not in Splat")] + public object? Resolve(Type type, params (Type Type, object Instance)[] parameters) + { + if (_types.TryGetValue((type, null), out var resolvedType)) { - return Instance.GetService(type); + return Activator.CreateInstance(resolvedType, parameters.Select(x => x.Instance)) ?? throw new InvalidOperationException("Could not create type"); } - /// - public object? Resolve(Type type, params (Type Type, object Instance)[] parameters) - { - if (_types.TryGetValue((type, null), out var resolvedType)) - { - return Activator.CreateInstance(resolvedType, parameters.Select(x => x.Instance)) ?? throw new InvalidOperationException("Could not create type"); - } - - return default; - } + return default; + } - /// - public object? Resolve(Type type, string name) - { - return Instance.GetService(type, name); - } + /// + public object? Resolve(Type type, string name) + { + return Instance.GetService(type, name); + } - /// - public object? Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1316:Tuple element names should use correct casing", Justification = "Defined by outside interface not in Splat")] + public object? Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) + { + if (!_types.TryGetValue((type, name), out var resolvedType)) { - if (!_types.TryGetValue((type, name), out var resolvedType)) + if (resolvedType is null) { - if (resolvedType is null) - { - return default; - } - - return Activator.CreateInstance(resolvedType, parameters.Select(x => x.Instance))!; + return default; } - return default; + return Activator.CreateInstance(resolvedType, parameters.Select(x => x.Instance))!; } - /// - /// Disposes data associated with the extension. - /// - /// If we are getting called by the Dispose() method rather than a finalizer. - protected virtual void Dispose(bool isDisposing) + return default; + } + + /// + /// Disposes data associated with the extension. + /// + /// If we are getting called by the Dispose() method rather than a finalizer. + protected virtual void Dispose(bool isDisposing) + { + if (isDisposing) { - if (isDisposing) - { - Interlocked.Exchange(ref _disposeAction, null)?.Invoke(); - _types.Clear(); - } + Interlocked.Exchange(ref _disposeAction, null)?.Invoke(); + _types.Clear(); } } } diff --git a/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs b/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs index ca41a2775..09c55110a 100644 --- a/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs +++ b/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs @@ -5,107 +5,105 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + using Mindscape.Raygun4Net; + using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// Feature Usage Tracking integration for Raygun. +/// +public sealed class RaygunFeatureUsageTrackingSession : IFeatureUsageTrackingSession { + private readonly RaygunClient _raygunClient; + private readonly RaygunSettings _raygunSettings; + /// - /// Feature Usage Tracking integration for Raygun. + /// Initializes a new instance of the class. /// - public sealed class RaygunFeatureUsageTrackingSession : IFeatureUsageTrackingSession + /// Name of the feature. + /// Raygun client instance. + /// Raygun settings instance. + public RaygunFeatureUsageTrackingSession( + string featureName, + RaygunClient raygunClient, + RaygunSettings raygunSettings) + : this( + featureName, + Guid.Empty, + raygunClient, + raygunSettings) + { + } + + internal RaygunFeatureUsageTrackingSession( + string featureName, + Guid parentReference, + RaygunClient raygunClient, + RaygunSettings raygunSettings) { - private readonly RaygunClient _raygunClient; - private readonly RaygunSettings _raygunSettings; - - /// - /// Initializes a new instance of the class. - /// - /// Name of the feature. - /// Raygun client instance. - /// Raygun settings instance. - public RaygunFeatureUsageTrackingSession( - string featureName, - RaygunClient raygunClient, - RaygunSettings raygunSettings) - : this( - featureName, - Guid.Empty, - raygunClient, - raygunSettings) + if (string.IsNullOrWhiteSpace(featureName)) { + throw new ArgumentNullException(nameof(featureName)); } - internal RaygunFeatureUsageTrackingSession( - string featureName, - Guid parentReference, - RaygunClient raygunClient, - RaygunSettings raygunSettings) + _raygunClient = raygunClient; + _raygunSettings = raygunSettings; + + ParentReference = parentReference; + FeatureName = featureName; + FeatureReference = Guid.NewGuid(); + + var userCustomData = new Dictionary { - if (string.IsNullOrWhiteSpace(featureName)) - { - throw new ArgumentNullException(nameof(featureName)); - } - - _raygunClient = raygunClient; - _raygunSettings = raygunSettings; - - ParentReference = parentReference; - FeatureName = featureName; - FeatureReference = Guid.NewGuid(); - - var userCustomData = new Dictionary - { - { "EventType", "FeatureUsage" }, - { "EventReference", FeatureReference.ToString() }, - { "ParentReference", parentReference.ToString() } - }; - - // keep an eye on - // https://raygun.com/forums/thread/92182 + { "EventType", "FeatureUsage" }, + { "EventReference", FeatureReference.ToString() }, + { "ParentReference", parentReference.ToString() }, + }; + + // keep an eye on + // https://raygun.com/forums/thread/92182 #if NET462 - var messageBuilder = RaygunMessageBuilder.New + var messageBuilder = RaygunMessageBuilder.New #else - var messageBuilder = RaygunMessageBuilder.New(raygunSettings) + var messageBuilder = RaygunMessageBuilder.New(raygunSettings) #endif - .SetClientDetails() - .SetEnvironmentDetails() - .SetUserCustomData(userCustomData); - var raygunMessage = messageBuilder.Build(); - _raygunClient.SendInBackground(raygunMessage); - } + .SetClientDetails() + .SetEnvironmentDetails() + .SetUserCustomData(userCustomData); + var raygunMessage = messageBuilder.Build(); + _raygunClient.SendInBackground(raygunMessage); + } - /// - public Guid ParentReference { get; } + /// + public Guid ParentReference { get; } - /// - public Guid FeatureReference { get; } + /// + public Guid FeatureReference { get; } - /// - public string FeatureName { get; } + /// + public string FeatureName { get; } - /// - public IFeatureUsageTrackingSession SubFeature(string description) - { - return new RaygunFeatureUsageTrackingSession( - description, - FeatureReference, - _raygunClient, - _raygunSettings); - } + /// + public IFeatureUsageTrackingSession SubFeature(string description) + { + return new RaygunFeatureUsageTrackingSession( + description, + FeatureReference, + _raygunClient, + _raygunSettings); + } - /// - public void OnException(Exception exception) - { - _raygunClient.SendInBackground(exception); - } + /// + public void OnException(Exception exception) + { + _raygunClient.SendInBackground(exception); + } - /// - public void Dispose() - { - } + /// + public void Dispose() + { } } diff --git a/src/Splat.Serilog/MutableDependencyResolverExtensions.cs b/src/Splat.Serilog/MutableDependencyResolverExtensions.cs index 58862c233..b46c216ce 100644 --- a/src/Splat.Serilog/MutableDependencyResolverExtensions.cs +++ b/src/Splat.Serilog/MutableDependencyResolverExtensions.cs @@ -3,54 +3,53 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.Serilog +namespace Splat.Serilog; + +/// +/// Serilog specific extensions for the Mutable Dependency Resolver. +/// +public static class MutableDependencyResolverExtensions { /// - /// Serilog specific extensions for the Mutable Dependency Resolver. + /// Simple helper to initialize Serilog within Splat with the Wrapping Full Logger. /// - public static class MutableDependencyResolverExtensions + /// + /// You should configure Serilog prior to calling this method. + /// + /// An instance of Mutable Dependency Resolver. + /// + /// + /// Locator.CurrentMutable.UseSerilogWithWrappingFullLogger(); + /// + /// + public static void UseSerilogFullLogger(this IMutableDependencyResolver instance) { - /// - /// Simple helper to initialize Serilog within Splat with the Wrapping Full Logger. - /// - /// - /// You should configure Serilog prior to calling this method. - /// - /// An instance of Mutable Dependency Resolver. - /// - /// - /// Locator.CurrentMutable.UseSerilogWithWrappingFullLogger(); - /// - /// - public static void UseSerilogFullLogger(this IMutableDependencyResolver instance) + var funcLogManager = new FuncLogManager(type => { - var funcLogManager = new FuncLogManager(type => - { - var actualLogger = global::Serilog.Log.ForContext(type); - return new SerilogFullLogger(actualLogger); - }); + var actualLogger = global::Serilog.Log.ForContext(type); + return new SerilogFullLogger(actualLogger); + }); - instance.RegisterConstant(funcLogManager, typeof(ILogManager)); - } + instance.RegisterConstant(funcLogManager, typeof(ILogManager)); + } - /// - /// Simple helper to initialize Serilog within Splat with the Wrapping Full Logger. - /// - /// - /// You should configure Serilog prior to calling this method. - /// - /// An instance of Mutable Dependency Resolver. - /// The serilog logger to register. - /// - /// - /// Locator.CurrentMutable.UseSerilogWithWrappingFullLogger(); - /// - /// - public static void UseSerilogFullLogger(this IMutableDependencyResolver instance, global::Serilog.ILogger actualLogger) - { - var funcLogManager = new FuncLogManager(type => new SerilogFullLogger(actualLogger.ForContext(type))); + /// + /// Simple helper to initialize Serilog within Splat with the Wrapping Full Logger. + /// + /// + /// You should configure Serilog prior to calling this method. + /// + /// An instance of Mutable Dependency Resolver. + /// The serilog logger to register. + /// + /// + /// Locator.CurrentMutable.UseSerilogWithWrappingFullLogger(); + /// + /// + public static void UseSerilogFullLogger(this IMutableDependencyResolver instance, global::Serilog.ILogger actualLogger) + { + var funcLogManager = new FuncLogManager(type => new SerilogFullLogger(actualLogger.ForContext(type))); - instance.RegisterConstant(funcLogManager, typeof(ILogManager)); - } + instance.RegisterConstant(funcLogManager, typeof(ILogManager)); } } diff --git a/src/Splat.Serilog/Registration.cs b/src/Splat.Serilog/Registration.cs index ca16e314f..ed14075a8 100644 --- a/src/Splat.Serilog/Registration.cs +++ b/src/Splat.Serilog/Registration.cs @@ -6,24 +6,23 @@ using System; using System.ComponentModel; -namespace Splat.Serilog +namespace Splat.Serilog; + +/// +/// Provides a legacy interface for registrations that was compatible with the old +/// Serilog interfaces provided by Joel Weiss. +/// +[EditorBrowsable(EditorBrowsableState.Never)] +public static class Registration { /// - /// Provides a legacy interface for registrations that was compatible with the old - /// Serilog interfaces provided by Joel Weiss. + /// Registers a serilog logger with Splat. /// + /// The logger to register. [EditorBrowsable(EditorBrowsableState.Never)] - public static class Registration + [Obsolete("This method will be removed in the future, Use Splat.Locator.CurrentMutable.UseSerilogWithWrappingFullLogger() instead.")] + public static void Register(global::Serilog.ILogger logger) { - /// - /// Registers a serilog logger with Splat. - /// - /// The logger to register. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed in the future, Use Splat.Locator.CurrentMutable.UseSerilogWithWrappingFullLogger() instead.")] - public static void Register(global::Serilog.ILogger logger) - { - Locator.CurrentMutable.UseSerilogFullLogger(logger); - } + Locator.CurrentMutable.UseSerilogFullLogger(logger); } } diff --git a/src/Splat.Serilog/SerilogFullLogger.cs b/src/Splat.Serilog/SerilogFullLogger.cs index d9bc14785..4f1a4cd00 100644 --- a/src/Splat.Serilog/SerilogFullLogger.cs +++ b/src/Splat.Serilog/SerilogFullLogger.cs @@ -7,1044 +7,1043 @@ using System.ComponentModel; using Serilog.Events; -namespace Splat +namespace Splat; + +/// +/// A full wrapping logger over Serilog. +/// +public class SerilogFullLogger : IFullLogger { + private readonly global::Serilog.ILogger _logger; + /// - /// A full wrapping logger over Serilog. + /// Initializes a new instance of the class. /// - public class SerilogFullLogger : IFullLogger + /// The logger we are wrapping. + public SerilogFullLogger(global::Serilog.ILogger logger) { - private readonly global::Serilog.ILogger _logger; - - /// - /// Initializes a new instance of the class. - /// - /// The logger we are wrapping. - public SerilogFullLogger(global::Serilog.ILogger logger) - { - _logger = logger; - } + _logger = logger; + } - /// - public bool IsDebugEnabled => _logger.IsEnabled(LogEventLevel.Debug); + /// + public bool IsDebugEnabled => _logger.IsEnabled(LogEventLevel.Debug); - /// - public bool IsInfoEnabled => _logger.IsEnabled(LogEventLevel.Information); + /// + public bool IsInfoEnabled => _logger.IsEnabled(LogEventLevel.Information); - /// - public bool IsWarnEnabled => _logger.IsEnabled(LogEventLevel.Warning); + /// + public bool IsWarnEnabled => _logger.IsEnabled(LogEventLevel.Warning); - /// - public bool IsErrorEnabled => _logger.IsEnabled(LogEventLevel.Error); + /// + public bool IsErrorEnabled => _logger.IsEnabled(LogEventLevel.Error); - /// - public bool IsFatalEnabled => _logger.IsEnabled(LogEventLevel.Fatal); + /// + public bool IsFatalEnabled => _logger.IsEnabled(LogEventLevel.Fatal); - /// - public LogLevel Level + /// + public LogLevel Level + { + get { - get + foreach (var mapping in SerilogHelper.Mappings) { - foreach (var mapping in SerilogHelper.Mappings) + if (_logger.IsEnabled(mapping.Value)) { - if (_logger.IsEnabled(mapping.Value)) - { - return mapping.Key; - } + return mapping.Key; } - - // Default to Fatal, it should always be enabled anyway. - return LogLevel.Fatal; } - set - { - // Do nothing. set is going soon anyway. - } + // Default to Fatal, it should always be enabled anyway. + return LogLevel.Fatal; } - /// - public void Debug(T value) + set { - _logger.Debug(value?.ToString() ?? string.Empty); + // Do nothing. set is going soon anyway. } + } - /// - public void Debug(IFormatProvider formatProvider, T value) - { - _logger.Debug(string.Format(formatProvider, "{0}", value)); - } + /// + public void Debug(T value) + { + _logger.Debug(value?.ToString() ?? string.Empty); + } - /// - public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) - { - _logger.Debug(string.Format(formatProvider, message, args)); - } + /// + public void Debug(IFormatProvider formatProvider, T value) + { + _logger.Debug(string.Format(formatProvider, "{0}", value)); + } - /// - public void Debug([Localizable(false)] string? message) - { - _logger.Debug(message ?? string.Empty); - } + /// + public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) + { + _logger.Debug(string.Format(formatProvider, message, args)); + } - /// - public void Debug([Localizable(false)] string? message) - { - _logger.ForContext().Debug(message ?? string.Empty); - } + /// + public void Debug([Localizable(false)] string? message) + { + _logger.Debug(message ?? string.Empty); + } - /// - public void Debug([Localizable(false)] string message, params object[] args) - { - _logger.Debug(message, args); - } + /// + public void Debug([Localizable(false)] string? message) + { + _logger.ForContext().Debug(message ?? string.Empty); + } - /// - public void Debug([Localizable(false)] string message, params object[] args) - { - _logger.ForContext().Debug(message, args); - } + /// + public void Debug([Localizable(false)] string message, params object[] args) + { + _logger.Debug(message, args); + } - /// - public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) - { - _logger.Debug(string.Format(formatProvider, message, argument)); - } + /// + public void Debug([Localizable(false)] string message, params object[] args) + { + _logger.ForContext().Debug(message, args); + } - /// - public void Debug([Localizable(false)] string message, TArgument args) - { - _logger.Debug(message, args); - } + /// + public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) + { + _logger.Debug(string.Format(formatProvider, message, argument)); + } - /// - public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) - { - _logger.Debug(string.Format(formatProvider, message, argument1, argument2)); - } + /// + public void Debug([Localizable(false)] string message, TArgument args) + { + _logger.Debug(message, args); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Debug(messageFormat, argument1, argument2); - } + /// + public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + { + _logger.Debug(string.Format(formatProvider, message, argument1, argument2)); + } - /// - public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Debug(string.Format(formatProvider, message, argument1, argument2, argument3)); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Debug(messageFormat, argument1, argument2); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Debug(messageFormat, argument1, argument2, argument3); - } + /// + public void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Debug(string.Format(formatProvider, message, argument1, argument2, argument3)); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Debug(messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Debug(messageFormat, argument1, argument2, argument3); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Debug(messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void DebugException([Localizable(false)] string? message, Exception exception) - { - _logger.Debug(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Debug(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Debug(Exception exception, [Localizable(false)] string? message) - { - _logger.Debug(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void DebugException([Localizable(false)] string? message, Exception exception) + { + _logger.Debug(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Error(T value) - { - _logger.Error(value?.ToString() ?? string.Empty); - } + /// + public void Debug(Exception exception, [Localizable(false)] string? message) + { + _logger.Debug(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Error(IFormatProvider formatProvider, T value) - { - _logger.Error(string.Format(formatProvider, "{0}", value)); - } + /// + public void Error(T value) + { + _logger.Error(value?.ToString() ?? string.Empty); + } - /// - public void Error(Exception exception, string? message) - { - _logger.Error(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Error(IFormatProvider formatProvider, T value) + { + _logger.Error(string.Format(formatProvider, "{0}", value)); + } - /// - public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) - { - _logger.Error(string.Format(formatProvider, message, args)); - } + /// + public void Error(Exception exception, string? message) + { + _logger.Error(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Error([Localizable(false)] string? message) - { - _logger.Error(message ?? string.Empty); - } + /// + public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) + { + _logger.Error(string.Format(formatProvider, message, args)); + } - /// - public void Error([Localizable(false)] string? message) - { - _logger.ForContext().Error(message ?? string.Empty); - } + /// + public void Error([Localizable(false)] string? message) + { + _logger.Error(message ?? string.Empty); + } - /// - public void Error([Localizable(false)] string message, params object[] args) - { - _logger.Error(message, args); - } + /// + public void Error([Localizable(false)] string? message) + { + _logger.ForContext().Error(message ?? string.Empty); + } - /// - public void Error([Localizable(false)] string message, params object[] args) - { - _logger.ForContext().Error(message, args); - } + /// + public void Error([Localizable(false)] string message, params object[] args) + { + _logger.Error(message, args); + } - /// - public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) - { - _logger.Error(string.Format(formatProvider, message, argument)); - } + /// + public void Error([Localizable(false)] string message, params object[] args) + { + _logger.ForContext().Error(message, args); + } - /// - public void Error([Localizable(false)] string message, TArgument args) - { - _logger.Error(message, args); - } + /// + public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) + { + _logger.Error(string.Format(formatProvider, message, argument)); + } - /// - public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) - { - _logger.Error(string.Format(formatProvider, message, argument1, argument2)); - } + /// + public void Error([Localizable(false)] string message, TArgument args) + { + _logger.Error(message, args); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Error(messageFormat, argument1, argument2); - } + /// + public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + { + _logger.Error(string.Format(formatProvider, message, argument1, argument2)); + } - /// - public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Error(string.Format(formatProvider, message, argument1, argument2, argument3)); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Error(messageFormat, argument1, argument2); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Error(messageFormat, argument1, argument2, argument3); - } + /// + public void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Error(string.Format(formatProvider, message, argument1, argument2, argument3)); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Error(messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Error(messageFormat, argument1, argument2, argument3); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Error(messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void ErrorException([Localizable(false)] string? message, Exception exception) - { - _logger.Error(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Error(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Fatal(T value) - { - _logger.Fatal(value?.ToString() ?? string.Empty); - } + /// + public void ErrorException([Localizable(false)] string? message, Exception exception) + { + _logger.Error(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Fatal(IFormatProvider formatProvider, T value) - { - _logger.Fatal(string.Format(formatProvider, "{0}", value)); - } + /// + public void Fatal(T value) + { + _logger.Fatal(value?.ToString() ?? string.Empty); + } - /// - public void Fatal(Exception exception, string? message) - { - _logger.Fatal(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Fatal(IFormatProvider formatProvider, T value) + { + _logger.Fatal(string.Format(formatProvider, "{0}", value)); + } - /// - public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) - { - _logger.Fatal(string.Format(formatProvider, message, args)); - } + /// + public void Fatal(Exception exception, string? message) + { + _logger.Fatal(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Fatal([Localizable(false)] string? message) - { - _logger.Fatal(message ?? string.Empty); - } + /// + public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) + { + _logger.Fatal(string.Format(formatProvider, message, args)); + } - /// - public void Fatal([Localizable(false)] string? message) - { - _logger.ForContext().Fatal(message ?? string.Empty); - } + /// + public void Fatal([Localizable(false)] string? message) + { + _logger.Fatal(message ?? string.Empty); + } - /// - public void Fatal([Localizable(false)] string message, params object[] args) - { - _logger.Fatal(message, args); - } + /// + public void Fatal([Localizable(false)] string? message) + { + _logger.ForContext().Fatal(message ?? string.Empty); + } - /// - public void Fatal([Localizable(false)] string message, params object[] args) - { - _logger.ForContext().Fatal(message, args); - } + /// + public void Fatal([Localizable(false)] string message, params object[] args) + { + _logger.Fatal(message, args); + } - /// - public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) - { - _logger.Fatal(string.Format(formatProvider, message, argument)); - } + /// + public void Fatal([Localizable(false)] string message, params object[] args) + { + _logger.ForContext().Fatal(message, args); + } - /// - public void Fatal([Localizable(false)] string message, TArgument args) - { - _logger.Fatal(message, args); - } + /// + public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) + { + _logger.Fatal(string.Format(formatProvider, message, argument)); + } - /// - public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) - { - _logger.Fatal(string.Format(formatProvider, message, argument1, argument2)); - } + /// + public void Fatal([Localizable(false)] string message, TArgument args) + { + _logger.Fatal(message, args); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Fatal(messageFormat, argument1, argument2); - } + /// + public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + { + _logger.Fatal(string.Format(formatProvider, message, argument1, argument2)); + } - /// - public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Fatal(string.Format(formatProvider, message, argument1, argument2, argument3)); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Fatal(messageFormat, argument1, argument2); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3); - } + /// + public void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Fatal(string.Format(formatProvider, message, argument1, argument2, argument3)); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void FatalException([Localizable(false)] string? message, Exception exception) - { - _logger.Fatal(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Fatal(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Info(T value) - { - _logger.Information(value?.ToString() ?? string.Empty); - } + /// + public void FatalException([Localizable(false)] string? message, Exception exception) + { + _logger.Fatal(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Info(IFormatProvider formatProvider, T value) - { - _logger.Information(string.Format(formatProvider, "{0}", value)); - } + /// + public void Info(T value) + { + _logger.Information(value?.ToString() ?? string.Empty); + } - /// - public void Info(Exception exception, string? message) - { - _logger.Information(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Info(IFormatProvider formatProvider, T value) + { + _logger.Information(string.Format(formatProvider, "{0}", value)); + } - /// - public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) - { - _logger.Information(string.Format(formatProvider, message, args)); - } + /// + public void Info(Exception exception, string? message) + { + _logger.Information(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Info([Localizable(false)] string? message) - { - _logger.Information(message ?? string.Empty); - } + /// + public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) + { + _logger.Information(string.Format(formatProvider, message, args)); + } - /// - public void Info([Localizable(false)] string? message) - { - _logger.ForContext().Information(message ?? string.Empty); - } + /// + public void Info([Localizable(false)] string? message) + { + _logger.Information(message ?? string.Empty); + } - /// - public void Info([Localizable(false)] string message, params object[] args) - { - _logger.Information(message, args); - } + /// + public void Info([Localizable(false)] string? message) + { + _logger.ForContext().Information(message ?? string.Empty); + } - /// - public void Info([Localizable(false)] string message, params object[] args) - { - _logger.ForContext().Information(message, args); - } + /// + public void Info([Localizable(false)] string message, params object[] args) + { + _logger.Information(message, args); + } - /// - public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) - { - _logger.Information(string.Format(formatProvider, message, argument)); - } + /// + public void Info([Localizable(false)] string message, params object[] args) + { + _logger.ForContext().Information(message, args); + } - /// - public void Info([Localizable(false)] string message, TArgument args) - { - _logger.Information(message, args); - } + /// + public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) + { + _logger.Information(string.Format(formatProvider, message, argument)); + } - /// - public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) - { - _logger.Information(string.Format(formatProvider, message, argument1, argument2)); - } + /// + public void Info([Localizable(false)] string message, TArgument args) + { + _logger.Information(message, args); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Information(messageFormat, argument1, argument2); - } + /// + public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + { + _logger.Information(string.Format(formatProvider, message, argument1, argument2)); + } - /// - public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Information(string.Format(formatProvider, message, argument1, argument2, argument3)); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Information(messageFormat, argument1, argument2); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Information(messageFormat, argument1, argument2, argument3); - } + /// + public void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Information(string.Format(formatProvider, message, argument1, argument2, argument3)); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Information(messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Information(messageFormat, argument1, argument2, argument3); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Information(messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void InfoException([Localizable(false)] string? message, Exception exception) - { - _logger.Information(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Information(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Warn(T value) - { - _logger.Warning(value?.ToString() ?? string.Empty); - } + /// + public void InfoException([Localizable(false)] string? message, Exception exception) + { + _logger.Information(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Warn(IFormatProvider formatProvider, T value) - { - _logger.Warning(string.Format(formatProvider, "{0}", value)); - } + /// + public void Warn(T value) + { + _logger.Warning(value?.ToString() ?? string.Empty); + } - /// - public void Warn(Exception exception, string? message) - { - _logger.Warning(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Warn(IFormatProvider formatProvider, T value) + { + _logger.Warning(string.Format(formatProvider, "{0}", value)); + } - /// - public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) - { - _logger.Warning(string.Format(formatProvider, message, args)); - } + /// + public void Warn(Exception exception, string? message) + { + _logger.Warning(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Warn([Localizable(false)] string? message) - { - _logger.Warning(message ?? string.Empty); - } + /// + public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args) + { + _logger.Warning(string.Format(formatProvider, message, args)); + } - /// - public void Warn([Localizable(false)] string? message) - { - _logger.ForContext().Warning(message ?? string.Empty); - } + /// + public void Warn([Localizable(false)] string? message) + { + _logger.Warning(message ?? string.Empty); + } - /// - public void Warn([Localizable(false)] string message, params object[] args) - { - _logger.Warning(message, args); - } + /// + public void Warn([Localizable(false)] string? message) + { + _logger.ForContext().Warning(message ?? string.Empty); + } - /// - public void Warn([Localizable(false)] string message, params object[] args) - { - _logger.ForContext().Warning(message, args); - } + /// + public void Warn([Localizable(false)] string message, params object[] args) + { + _logger.Warning(message, args); + } - /// - public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) - { - _logger.Warning(string.Format(formatProvider, message, argument)); - } + /// + public void Warn([Localizable(false)] string message, params object[] args) + { + _logger.ForContext().Warning(message, args); + } - /// - public void Warn([Localizable(false)] string message, TArgument args) - { - _logger.Warning(message, args); - } + /// + public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument) + { + _logger.Warning(string.Format(formatProvider, message, argument)); + } - /// - public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) - { - _logger.Warning(string.Format(formatProvider, message, argument1, argument2)); - } + /// + public void Warn([Localizable(false)] string message, TArgument args) + { + _logger.Warning(message, args); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Warning(messageFormat, argument1, argument2); - } + /// + public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + { + _logger.Warning(string.Format(formatProvider, message, argument1, argument2)); + } - /// - public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Warning(string.Format(formatProvider, message, argument1, argument2, argument3)); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Warning(messageFormat, argument1, argument2); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Warning(messageFormat, argument1, argument2, argument3); - } + /// + public void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Warning(string.Format(formatProvider, message, argument1, argument2, argument3)); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Warning(messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Warning(messageFormat, argument1, argument2, argument3); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Warning(messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void WarnException([Localizable(false)] string? message, Exception exception) - { - _logger.Warning(exception, message ?? exception?.Message ?? string.Empty); - } + /// + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Warning(messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Write(string message, LogLevel logLevel) - { - _logger.Write(SerilogHelper.MappingsDictionary[logLevel], message); - } + /// + public void WarnException([Localizable(false)] string? message, Exception exception) + { + _logger.Warning(exception, message ?? exception?.Message ?? string.Empty); + } - /// - public void Write(Exception exception, string message, LogLevel logLevel) - { - _logger.Write(SerilogHelper.MappingsDictionary[logLevel], exception, message); - } + /// + public void Write(string message, LogLevel logLevel) + { + _logger.Write(SerilogHelper.MappingsDictionary[logLevel], message); + } - /// - public void Write(string message, Type type, LogLevel logLevel) - { - _logger.ForContext(type).Write(SerilogHelper.MappingsDictionary[logLevel], message); - } + /// + public void Write(Exception exception, string message, LogLevel logLevel) + { + _logger.Write(SerilogHelper.MappingsDictionary[logLevel], exception, message); + } - /// - public void Write(Exception exception, string message, Type type, LogLevel logLevel) - { - _logger.ForContext(type).Write(SerilogHelper.MappingsDictionary[logLevel], exception, message); - } + /// + public void Write(string message, Type type, LogLevel logLevel) + { + _logger.ForContext(type).Write(SerilogHelper.MappingsDictionary[logLevel], message); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument argument) - { - _logger.Debug(exception, messageFormat, argument); - } + /// + public void Write(Exception exception, string message, Type type, LogLevel logLevel) + { + _logger.ForContext(type).Write(SerilogHelper.MappingsDictionary[logLevel], exception, message); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Debug(exception, messageFormat, argument1, argument2); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument argument) + { + _logger.Debug(exception, messageFormat, argument); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Debug(exception, messageFormat, argument1, argument2); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Info(Exception exception, string messageFormat, TArgument argument) - { - _logger.Information(exception, messageFormat, argument); - } + /// + public void Debug(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Debug(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Information(exception, messageFormat, argument1, argument2); - } + /// + public void Info(Exception exception, string messageFormat, TArgument argument) + { + _logger.Information(exception, messageFormat, argument); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Information(exception, messageFormat, argument1, argument2); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument argument) - { - _logger.Warning(exception, messageFormat, argument); - } + /// + public void Info(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Information(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Warning(exception, messageFormat, argument1, argument2); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument argument) + { + _logger.Warning(exception, messageFormat, argument); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Warning(exception, messageFormat, argument1, argument2); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Error(Exception exception, string messageFormat, TArgument argument) - { - _logger.Error(exception, messageFormat, argument); - } + /// + public void Warn(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Warning(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Error(exception, messageFormat, argument1, argument2); - } + /// + public void Error(Exception exception, string messageFormat, TArgument argument) + { + _logger.Error(exception, messageFormat, argument); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Error(exception, messageFormat, argument1, argument2); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument argument) - { - _logger.Fatal(exception, messageFormat, argument); - } + /// + public void Error(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - _logger.Fatal(exception, messageFormat, argument1, argument2); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument argument) + { + _logger.Fatal(exception, messageFormat, argument); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _logger.Fatal(exception, messageFormat, argument1, argument2, argument3); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + _logger.Fatal(exception, messageFormat, argument1, argument2); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) - { - _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _logger.Fatal(exception, messageFormat, argument1, argument2, argument3); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) - { - _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4) + { + _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) - { - _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5) + { + _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) - { - _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6) + { + _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) - { - _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7) + { + _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) - { - _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8) + { + _logger.Error(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8); + } - /// - public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) - { - _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); - } + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) + { + _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9); + } + + /// + public void Fatal(Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) + { + _logger.Fatal(exception, messageFormat, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10); } } diff --git a/src/Splat.Serilog/SerilogHelper.cs b/src/Splat.Serilog/SerilogHelper.cs index 824016e89..ae35bb063 100644 --- a/src/Splat.Serilog/SerilogHelper.cs +++ b/src/Splat.Serilog/SerilogHelper.cs @@ -3,33 +3,29 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + using Serilog.Events; -namespace Splat +namespace Splat; + +internal static class SerilogHelper { - internal static class SerilogHelper + /// + /// Gets a list of mappings of Serilog levels and equivalent Splat log levels. + /// + public static KeyValuePair[] Mappings { get; } = { - /// - /// Gets a list of mappings of Serilog levels and equivalent Splat log levels. - /// - public static KeyValuePair[] Mappings { get; } = - { - new(LogLevel.Debug, LogEventLevel.Debug), - new(LogLevel.Info, LogEventLevel.Information), - new(LogLevel.Warn, LogEventLevel.Warning), - new(LogLevel.Error, LogEventLevel.Error), - new(LogLevel.Fatal, LogEventLevel.Fatal) - }; + new(LogLevel.Debug, LogEventLevel.Debug), + new(LogLevel.Info, LogEventLevel.Information), + new(LogLevel.Warn, LogEventLevel.Warning), + new(LogLevel.Error, LogEventLevel.Error), + new(LogLevel.Fatal, LogEventLevel.Fatal), + }; - /// - /// Gets a dictionary which maps Splat log levels to Serilogs. - /// - public static ImmutableDictionary MappingsDictionary { get; } = Mappings.ToImmutableDictionary(); - } + /// + /// Gets a dictionary which maps Splat log levels to Serilogs. + /// + public static ImmutableDictionary MappingsDictionary { get; } = Mappings.ToImmutableDictionary(); } diff --git a/src/Splat.SimpleInjector.Tests/DependencyResolverTests.cs b/src/Splat.SimpleInjector.Tests/DependencyResolverTests.cs index f88fc1a28..3a6c906f8 100644 --- a/src/Splat.SimpleInjector.Tests/DependencyResolverTests.cs +++ b/src/Splat.SimpleInjector.Tests/DependencyResolverTests.cs @@ -12,118 +12,117 @@ using Xunit; -namespace Splat.Simplnjector +namespace Splat.Simplnjector; + +/// +/// Tests to show the works correctly. +/// +public class DependencyResolverTests { /// - /// Tests to show the works correctly. + /// Simples the injector dependency resolver should resolve a view model. + /// + [Fact] + public void SimpleInjectorDependencyResolver_Should_Resolve_View_Model() + { + var container = new Container(); + container.Register(); + container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); + + var viewModel = Locator.Current.GetService(typeof(ViewModelOne)); + + viewModel.Should().NotBeNull(); + viewModel.Should().BeOfType(); + } + + /// + /// Simples the injector dependency resolver should resolve a view model. + /// + [Fact] + public void SimpleInjectorDependencyResolver_Should_Resolve_View_Model_Directly() + { + var container = new SimpleInjectorInitializer(); + container.Register(() => new ViewModelOne()); + + var viewModel = container.GetService(); + + viewModel.Should().NotBeNull(); + viewModel.Should().BeOfType(); + } + + /// + /// Simples the injector dependency resolver should resolve a view. + /// + [Fact] + public void SimpleInjectorDependencyResolver_Should_Resolve_View() + { + var container = new Container(); + container.Register, ViewOne>(); + container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); + + var view = Locator.Current.GetService(typeof(IViewFor)); + + view.Should().NotBeNull(); + view.Should().BeOfType(); + } + + /// + /// Simples the injector dependency resolver should resolve the screen. /// - public class DependencyResolverTests + [Fact] + public void SimpleInjectorDependencyResolver_Should_Resolve_Screen() { - /// - /// Simples the injector dependency resolver should resolve a view model. - /// - [Fact] - public void SimpleInjectorDependencyResolver_Should_Resolve_View_Model() - { - var container = new Container(); - container.Register(); - container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); - - var viewModel = Locator.Current.GetService(typeof(ViewModelOne)); - - viewModel.Should().NotBeNull(); - viewModel.Should().BeOfType(); - } - - /// - /// Simples the injector dependency resolver should resolve a view model. - /// - [Fact] - public void SimpleInjectorDependencyResolver_Should_Resolve_View_Model_Directly() - { - var container = new SimpleInjectorInitializer(); - container.Register(() => new ViewModelOne()); - - var viewModel = container.GetService(); - - viewModel.Should().NotBeNull(); - viewModel.Should().BeOfType(); - } - - /// - /// Simples the injector dependency resolver should resolve a view. - /// - [Fact] - public void SimpleInjectorDependencyResolver_Should_Resolve_View() - { - var container = new Container(); - container.Register, ViewOne>(); - container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); - - var view = Locator.Current.GetService(typeof(IViewFor)); - - view.Should().NotBeNull(); - view.Should().BeOfType(); - } - - /// - /// Simples the injector dependency resolver should resolve the screen. - /// - [Fact] - public void SimpleInjectorDependencyResolver_Should_Resolve_Screen() - { - var container = new Container(); - container.RegisterSingleton(); - container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); - - var screen = Locator.Current.GetService(typeof(IScreen)); - - screen.Should().NotBeNull(); - screen.Should().BeOfType(); - } - - /// - /// Should not throw during initialization of ReactiveUI. - /// - [Fact] - public void SimpleInjectorDependencyResolver_Splat_Initialization_ShouldNotThrow() - { - Container container = new(); - SimpleInjectorInitializer initializer = new(); - - Locator.SetLocator(initializer); - Locator.CurrentMutable.InitializeSplat(); - container.UseSimpleInjectorDependencyResolver(initializer); - } - - /// - /// Should resolve dependency registered during Splat initialization. - /// - [Fact] - public void SimpleInjectorDependencyResolver_ShouldResolveSplatRegisteredDependency() - { - Container container = new(); - SimpleInjectorInitializer initializer = new(); - - Locator.SetLocator(initializer); - Locator.CurrentMutable.InitializeSplat(); - container.UseSimpleInjectorDependencyResolver(initializer); - - var dependency = Locator.Current.GetService(typeof(ILogger)) as ILogger; - Assert.NotNull(dependency); - } - - /// - /// Should resolve dependency registered during Splat initialization. - /// - [Fact] - public void SimpleInjectorDependencyResolver_CollectionShouldNeverReturnNull() - { - var container = new Container(); - container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); - - var views = Locator.Current.GetServices(typeof(ViewOne)); - Assert.NotNull(views); - } + var container = new Container(); + container.RegisterSingleton(); + container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); + + var screen = Locator.Current.GetService(typeof(IScreen)); + + screen.Should().NotBeNull(); + screen.Should().BeOfType(); + } + + /// + /// Should not throw during initialization of ReactiveUI. + /// + [Fact] + public void SimpleInjectorDependencyResolver_Splat_Initialization_ShouldNotThrow() + { + Container container = new(); + SimpleInjectorInitializer initializer = new(); + + Locator.SetLocator(initializer); + Locator.CurrentMutable.InitializeSplat(); + container.UseSimpleInjectorDependencyResolver(initializer); + } + + /// + /// Should resolve dependency registered during Splat initialization. + /// + [Fact] + public void SimpleInjectorDependencyResolver_ShouldResolveSplatRegisteredDependency() + { + Container container = new(); + SimpleInjectorInitializer initializer = new(); + + Locator.SetLocator(initializer); + Locator.CurrentMutable.InitializeSplat(); + container.UseSimpleInjectorDependencyResolver(initializer); + + var dependency = Locator.Current.GetService(typeof(ILogger)) as ILogger; + Assert.NotNull(dependency); + } + + /// + /// Should resolve dependency registered during Splat initialization. + /// + [Fact] + public void SimpleInjectorDependencyResolver_CollectionShouldNeverReturnNull() + { + var container = new Container(); + container.UseSimpleInjectorDependencyResolver(new SimpleInjectorInitializer()); + + var views = Locator.Current.GetServices(typeof(ViewOne)); + Assert.NotNull(views); } } diff --git a/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs b/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs index 0768f9696..bcd18e9cd 100644 --- a/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs +++ b/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs @@ -8,142 +8,141 @@ using System.Linq; using SimpleInjector; -namespace Splat.SimpleInjector +namespace Splat.SimpleInjector; + +/// +/// Simple Injector implementation for . +/// +/// +public class SimpleInjectorDependencyResolver : IDependencyResolver { + private Container _container; + /// - /// Simple Injector implementation for . + /// Initializes a new instance of the class. /// - /// - public class SimpleInjectorDependencyResolver : IDependencyResolver + /// The container. + /// The initializer. + public SimpleInjectorDependencyResolver(Container container, SimpleInjectorInitializer initializer) { - private Container _container; - - /// - /// Initializes a new instance of the class. - /// - /// The container. - /// The initializer. - public SimpleInjectorDependencyResolver(Container container, SimpleInjectorInitializer initializer) - { - _container = container ?? throw new ArgumentNullException(nameof(container)); - _ = initializer ?? throw new ArgumentNullException(nameof(initializer)); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _ = initializer ?? throw new ArgumentNullException(nameof(initializer)); - RegisterFactories(initializer); - } + RegisterFactories(initializer); + } - /// - public object? GetService(Type? serviceType, string? contract = null) + /// + public object? GetService(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - try - { - InstanceProducer? registration = _container.GetRegistration(serviceType); - if (registration is not null) - { - return registration.GetInstance(); - } - - IEnumerable registers = _container.GetAllInstances(serviceType); - return registers.LastOrDefault()!; - } - catch - { - return default; - } + serviceType = typeof(NullServiceType); } - /// - public IEnumerable GetServices(Type? serviceType, string? contract = null) + try { - if (serviceType is null) + var registration = _container.GetRegistration(serviceType); + if (registration is not null) { - serviceType = typeof(NullServiceType); + return registration.GetInstance(); } - try - { - return _container.GetAllInstances(serviceType); - } - catch - { - InstanceProducer? registration = _container.GetRegistration(serviceType); - if (registration is not null) - { - return new[] { registration.GetInstance() }; - } - - return Array.Empty(); - } + var registers = _container.GetAllInstances(serviceType); + return registers.LastOrDefault()!; } - - /// - public bool HasRegistration(Type? serviceType, string? contract = null) + catch { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - return _container.GetCurrentRegistrations().Any(x => x.ServiceType == serviceType); + return default; } + } - /// - public void Register(Func factory, Type? serviceType, string? contract = null) + /// + public IEnumerable GetServices(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - // The function does nothing because there should be no registration called on this object. - // Anyway, Locator.SetLocator performs some unnecessary registrations. + serviceType = typeof(NullServiceType); } - /// - public void UnregisterCurrent(Type? serviceType, string? contract = null) + try { - throw new NotImplementedException(); + return _container.GetAllInstances(serviceType); } - - /// - public void UnregisterAll(Type? serviceType, string? contract = null) + catch { - throw new NotImplementedException(); - } + var registration = _container.GetRegistration(serviceType); + if (registration is not null) + { + return new[] { registration.GetInstance() }; + } - /// - public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) - { - throw new NotImplementedException(); + return Array.Empty(); } + } - /// - public void Dispose() + /// + public bool HasRegistration(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - Dispose(true); - GC.SuppressFinalize(this); + serviceType = typeof(NullServiceType); } - /// - /// Disposes of the instance. - /// - /// Whether or not the instance is disposing. - protected virtual void Dispose(bool disposing) + return _container.GetCurrentRegistrations().Any(x => x.ServiceType == serviceType); + } + + /// + public void Register(Func factory, Type? serviceType, string? contract = null) + { + // The function does nothing because there should be no registration called on this object. + // Anyway, Locator.SetLocator performs some unnecessary registrations. + } + + /// + public void UnregisterCurrent(Type? serviceType, string? contract = null) + { + throw new NotImplementedException(); + } + + /// + public void UnregisterAll(Type? serviceType, string? contract = null) + { + throw new NotImplementedException(); + } + + /// + public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + { + throw new NotImplementedException(); + } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Disposes of the instance. + /// + /// Whether or not the instance is disposing. + protected virtual void Dispose(bool disposing) + { + if (disposing) { - if (disposing) - { - _container.Dispose(); - } + _container.Dispose(); } + } - private void RegisterFactories(SimpleInjectorInitializer initializer) + private void RegisterFactories(SimpleInjectorInitializer initializer) + { + foreach (var typeFactories in initializer.RegisteredFactories) { - foreach (KeyValuePair>> typeFactories in initializer.RegisteredFactories) - { - _container.Collection.Register( - typeFactories.Key, - typeFactories.Value.Select(n => - new TransientSimpleInjectorRegistration(_container, typeFactories.Key, n))); - } + _container.Collection.Register( + typeFactories.Key, + typeFactories.Value.Select(n => + new TransientSimpleInjectorRegistration(_container, typeFactories.Key, n))); } } } diff --git a/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs b/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs index 5f711d7be..bc261e5ce 100644 --- a/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs +++ b/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs @@ -6,133 +6,131 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -namespace Splat.SimpleInjector +namespace Splat.SimpleInjector; + +/// +/// sad. +/// +public class SimpleInjectorInitializer : IDependencyResolver { + private readonly object _lockObject = new(); + /// - /// sad. + /// Gets dictionary of registered factories. /// - public class SimpleInjectorInitializer : IDependencyResolver - { - private readonly object _lockObject = new(); - - /// - /// Gets dictionary of registered factories. - /// - public Dictionary>> RegisteredFactories { get; } - = new(); + public Dictionary>> RegisteredFactories { get; } + = new(); - /// - public object? GetService(Type? serviceType, string? contract = null) + /// + public object? GetService(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - lock (_lockObject) - { - Func? fact = RegisteredFactories[serviceType].LastOrDefault(); - return fact?.Invoke()!; - } + serviceType = typeof(NullServiceType); } - /// - public IEnumerable GetServices(Type? serviceType, string? contract = null) + lock (_lockObject) { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - lock (_lockObject) - { - return RegisteredFactories[serviceType] - .Select(n => n()!); - } + var fact = RegisteredFactories[serviceType].LastOrDefault(); + return fact?.Invoke()!; } + } - /// - public bool HasRegistration(Type? serviceType, string? contract = null) + /// + public IEnumerable GetServices(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + serviceType = typeof(NullServiceType); + } - lock (_lockObject) - { - return RegisteredFactories.TryGetValue(serviceType, out var values) - && values.Count > 0; - } + lock (_lockObject) + { + return RegisteredFactories[serviceType] + .Select(n => n()!); } + } - /// - public void Register(Func factory, Type? serviceType, string? contract = null) + /// + public bool HasRegistration(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - var isNull = serviceType is null; - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + serviceType = typeof(NullServiceType); + } - lock (_lockObject) - { - if (!RegisteredFactories.ContainsKey(serviceType)) - { - RegisteredFactories.Add(serviceType, new List>()); - } - - RegisteredFactories[serviceType].Add(() => - isNull - ? new NullServiceType(factory) - : factory()); - } + lock (_lockObject) + { + return RegisteredFactories.TryGetValue(serviceType, out var values) + && values.Count > 0; } + } - /// - public void UnregisterCurrent(Type? serviceType, string? contract = null) + /// + public void Register(Func factory, Type? serviceType, string? contract = null) + { + var isNull = serviceType is null; + if (serviceType is null) { - throw new NotImplementedException(); + serviceType = typeof(NullServiceType); } - /// - public void UnregisterAll(Type? serviceType, string? contract = null) + lock (_lockObject) { - if (serviceType is null) + if (!RegisteredFactories.ContainsKey(serviceType)) { - serviceType = typeof(NullServiceType); + RegisteredFactories.Add(serviceType, new List>()); } - lock (_lockObject) - { - if (RegisteredFactories.ContainsKey(serviceType)) - { - RegisteredFactories.Remove(serviceType); - } - } + RegisteredFactories[serviceType].Add(() => + isNull + ? new NullServiceType(factory) + : factory()); } + } - /// - public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) - { - throw new NotImplementedException(); - } + /// + public void UnregisterCurrent(Type? serviceType, string? contract = null) + { + throw new NotImplementedException(); + } - /// - public void Dispose() + /// + public void UnregisterAll(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - Dispose(true); - GC.SuppressFinalize(this); + serviceType = typeof(NullServiceType); } - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool isDisposing) + lock (_lockObject) { + if (RegisteredFactories.ContainsKey(serviceType)) + { + RegisteredFactories.Remove(serviceType); + } } } + + /// + public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + { + throw new NotImplementedException(); + } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool isDisposing) + { + } } diff --git a/src/Splat.SimpleInjector/SplatSimpleInjectorExtensions.cs b/src/Splat.SimpleInjector/SplatSimpleInjectorExtensions.cs index 00207cbbb..17bb87cd8 100644 --- a/src/Splat.SimpleInjector/SplatSimpleInjectorExtensions.cs +++ b/src/Splat.SimpleInjector/SplatSimpleInjectorExtensions.cs @@ -5,19 +5,18 @@ using SimpleInjector; -namespace Splat.SimpleInjector +namespace Splat.SimpleInjector; + +/// +/// Extension methods for the SimpleInjector adapter. +/// +public static class SplatSimpleInjectorExtensions { /// - /// Extension methods for the SimpleInjector adapter. + /// Initializes an instance of that overrides the default . /// - public static class SplatSimpleInjectorExtensions - { - /// - /// Initializes an instance of that overrides the default . - /// - /// Simple Injector container. - /// Initializer. - public static void UseSimpleInjectorDependencyResolver(this Container container, SimpleInjectorInitializer initializer) => - Locator.SetLocator(new SimpleInjectorDependencyResolver(container, initializer)); - } + /// Simple Injector container. + /// Initializer. + public static void UseSimpleInjectorDependencyResolver(this Container container, SimpleInjectorInitializer initializer) => + Locator.SetLocator(new SimpleInjectorDependencyResolver(container, initializer)); } diff --git a/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs b/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs index 39b93b65c..2b94496d1 100644 --- a/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs +++ b/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs @@ -7,15 +7,14 @@ using System.Linq.Expressions; using SimpleInjector; -namespace Splat.SimpleInjector +namespace Splat.SimpleInjector; + +internal class TransientSimpleInjectorRegistration : Registration { - internal class TransientSimpleInjectorRegistration : Registration + public TransientSimpleInjectorRegistration(Container container, Type implementationType, Func? instanceCreator = null) + : base(Lifestyle.Transient, container, implementationType, instanceCreator!) { - public TransientSimpleInjectorRegistration(Container container, Type implementationType, Func? instanceCreator = null) - : base(Lifestyle.Transient, container, implementationType, instanceCreator!) - { - } - - public override Expression BuildExpression() => BuildTransientExpression(); } + + 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 45d64972d..8315a230e 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt +++ b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt @@ -2,7 +2,7 @@ [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Android")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Uwp")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.Tests")] -[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName="")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")] namespace Splat { public class ActionLogger : Splat.ILogger diff --git a/src/Splat.Tests/API/ApiApprovalTests.cs b/src/Splat.Tests/API/ApiApprovalTests.cs index 341744ce2..3a64070c8 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.cs +++ b/src/Splat.Tests/API/ApiApprovalTests.cs @@ -10,22 +10,21 @@ using VerifyXunit; using Xunit; -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Tests to make sure that the API matches the approved ones. +/// +[ExcludeFromCodeCoverage] +[UsesVerify] +public class ApiApprovalTests { /// - /// Tests to make sure that the API matches the approved ones. + /// Tests to make sure the splat project is approved. /// - [ExcludeFromCodeCoverage] - [UsesVerify] - public class ApiApprovalTests - { - /// - /// Tests to make sure the splat project is approved. - /// - /// A task to monitor the usage. - [Fact] - public Task SplatProject() => typeof(AssemblyFinder).Assembly.CheckApproval(); - } + /// A task to monitor the usage. + [Fact] + public Task SplatProject() => typeof(AssemblyFinder).Assembly.CheckApproval(); } #endif diff --git a/src/Splat.Tests/ApiExtensions.cs b/src/Splat.Tests/ApiExtensions.cs index 8b0b2fd0b..4534422b5 100644 --- a/src/Splat.Tests/ApiExtensions.cs +++ b/src/Splat.Tests/ApiExtensions.cs @@ -12,30 +12,29 @@ #pragma warning disable SA1615 // Element return value should be documented -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// A helper for doing API approvals. +/// +public static class ApiExtensions { /// - /// A helper for doing API approvals. + /// Checks to make sure the API is approved. /// - public static class ApiExtensions + /// The assembly that is being checked. + /// The caller file path. + public static Task CheckApproval(this Assembly assembly, [CallerFilePath] string filePath = "") { - /// - /// Checks to make sure the API is approved. - /// - /// The assembly that is being checked. - /// The caller file path. - public static Task CheckApproval(this Assembly assembly, [CallerFilePath] string filePath = "") - { - var generatorOptions = new ApiGeneratorOptions { WhitelistedNamespacePrefixes = new[] { "Splat" } }; - var apiText = assembly.GeneratePublicApi(generatorOptions); - return Verifier.Verify(apiText, null, filePath) - .UniqueForRuntimeAndVersion() - .ScrubEmptyLines() - .ScrubLines(l => - l.StartsWith("[assembly: AssemblyVersion(", StringComparison.InvariantCulture) || - l.StartsWith("[assembly: AssemblyFileVersion(", StringComparison.InvariantCulture) || - l.StartsWith("[assembly: AssemblyInformationalVersion(", StringComparison.InvariantCulture) || - l.StartsWith("[assembly: System.Reflection.AssemblyMetadata(", StringComparison.InvariantCulture)); - } + var generatorOptions = new ApiGeneratorOptions { WhitelistedNamespacePrefixes = new[] { "Splat" } }; + var apiText = assembly.GeneratePublicApi(generatorOptions); + return Verifier.Verify(apiText, null, filePath) + .UniqueForRuntimeAndVersion() + .ScrubEmptyLines() + .ScrubLines(l => + l.StartsWith("[assembly: AssemblyVersion(", StringComparison.InvariantCulture) || + l.StartsWith("[assembly: AssemblyFileVersion(", StringComparison.InvariantCulture) || + l.StartsWith("[assembly: AssemblyInformationalVersion(", StringComparison.InvariantCulture) || + l.StartsWith("[assembly: System.Reflection.AssemblyMetadata(", StringComparison.InvariantCulture)); } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterFeatureUsageTrackingSessionTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterFeatureUsageTrackingSessionTests.cs index 2d7dfdb60..2f2fe55e2 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterFeatureUsageTrackingSessionTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterFeatureUsageTrackingSessionTests.cs @@ -3,36 +3,30 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; -using Xunit; +namespace Splat.Tests.ApplicationPerformanceMonitoring; -namespace Splat.Tests.ApplicationPerformanceMonitoring +/// +/// Unit Tests for App Center Feature Usage Tracking. +/// +public static class AppCenterFeatureUsageTrackingSessionTests { - /// - /// Unit Tests for App Center Feature Usage Tracking. - /// - public static class AppCenterFeatureUsageTrackingSessionTests + /// + public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests { - /// - public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests + /// + protected override AppCenterFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override AppCenterFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) - { - return new(featureName); - } + return new(featureName); } + } - /// - public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + /// + public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + { + /// + protected override AppCenterFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override AppCenterFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) - { - return new(featureName); - } + return new(featureName); } } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterViewTrackingTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterViewTrackingTests.cs index 0159cbcd8..226639558 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterViewTrackingTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/AppCenterViewTrackingTests.cs @@ -3,25 +3,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; +namespace Splat.Tests.ApplicationPerformanceMonitoring; -namespace Splat.Tests.ApplicationPerformanceMonitoring +/// +/// Unit Tests for App Center View Tracking. +/// +public static class AppCenterViewTrackingTests { - /// - /// Unit Tests for App Center View Tracking. - /// - public static class AppCenterViewTrackingTests + /// + public sealed class ConstructorMethod : BaseViewTrackingTests.ConstructorMethod { /// - public sealed class ConstructorMethod : BaseViewTrackingTests.ConstructorMethod + protected override AppCenterViewTracking GetViewTracking() { - /// - protected override AppCenterViewTracking GetViewTracking() - { - return new(); - } + return new(); } } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsFeatureUsageTrackingSessionTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsFeatureUsageTrackingSessionTests.cs index 109a9a88c..0da0f92d7 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsFeatureUsageTrackingSessionTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsFeatureUsageTrackingSessionTests.cs @@ -5,50 +5,47 @@ #if !WINDOWS_UWP -using System; -using System.Collections.Generic; -using System.Text; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Extensibility; + using Splat.ApplicationInsights; -namespace Splat.Tests.ApplicationPerformanceMonitoring +namespace Splat.Tests.ApplicationPerformanceMonitoring; + +/// +/// Unit Tests for Application Insights Feature Usage Tracking. +/// +public static class ApplicationInsightsFeatureUsageTrackingSessionTests { - /// - /// Unit Tests for Application Insights Feature Usage Tracking. - /// - public static class ApplicationInsightsFeatureUsageTrackingSessionTests + /// + public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests { - /// - public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests + /// + protected override ApplicationInsightsFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override ApplicationInsightsFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) + var telemetryConfiguration = new TelemetryConfiguration { - var telemetryConfiguration = new TelemetryConfiguration - { - DisableTelemetry = true - }; - var telemetryClient = new TelemetryClient(telemetryConfiguration); - - return new ApplicationInsightsFeatureUsageTrackingSession(featureName, telemetryClient); - } + DisableTelemetry = true, + }; + var telemetryClient = new TelemetryClient(telemetryConfiguration); + + return new ApplicationInsightsFeatureUsageTrackingSession(featureName, telemetryClient); } + } - /// - public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + /// + public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + { + /// + protected override ApplicationInsightsFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override ApplicationInsightsFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) + var telemetryConfiguration = new TelemetryConfiguration { - var telemetryConfiguration = new TelemetryConfiguration - { - DisableTelemetry = true - }; - var telemetryClient = new TelemetryClient(telemetryConfiguration); - - return new ApplicationInsightsFeatureUsageTrackingSession(featureName, telemetryClient); - } + DisableTelemetry = true, + }; + var telemetryClient = new TelemetryClient(telemetryConfiguration); + + return new ApplicationInsightsFeatureUsageTrackingSession(featureName, telemetryClient); } } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsViewTrackingTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsViewTrackingTests.cs index 1645a8c85..c9da7d311 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsViewTrackingTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/ApplicationInsightsViewTrackingTests.cs @@ -5,33 +5,29 @@ #if !WINDOWS_UWP -using System; -using System.Collections.Generic; -using System.Text; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Extensibility; -namespace Splat.Tests.ApplicationPerformanceMonitoring +namespace Splat.Tests.ApplicationPerformanceMonitoring; + +/// +/// Unit Tests for Application Insights Feature Usage Tracking. +/// +public static class ApplicationInsightsViewTrackingTests { - /// - /// Unit Tests for Application Insights Feature Usage Tracking. - /// - public static class ApplicationInsightsViewTrackingTests + /// + public sealed class ConstructorMethod : BaseViewTrackingTests.ConstructorMethod { /// - public sealed class ConstructorMethod : BaseViewTrackingTests.ConstructorMethod + protected override ApplicationInsightsViewTracking GetViewTracking() { - /// - protected override ApplicationInsightsViewTracking GetViewTracking() + var telemetryConfiguration = new TelemetryConfiguration { - var telemetryConfiguration = new TelemetryConfiguration - { - DisableTelemetry = true - }; - var telemetryClient = new TelemetryClient(telemetryConfiguration); + DisableTelemetry = true, + }; + var telemetryClient = new TelemetryClient(telemetryConfiguration); - return new ApplicationInsightsViewTracking(telemetryClient); - } + return new ApplicationInsightsViewTracking(telemetryClient); } } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseFeatureUsageTrackingTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseFeatureUsageTrackingTests.cs index 072601f75..c92eef273 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseFeatureUsageTrackingTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseFeatureUsageTrackingTests.cs @@ -4,84 +4,83 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Text; + using Splat.ApplicationPerformanceMonitoring; + using Xunit; -namespace Splat.Tests.ApplicationPerformanceMonitoring +namespace Splat.Tests.ApplicationPerformanceMonitoring; + +/// +/// Common Unit Tests for Feature Usage Tracking. +/// +public static class BaseFeatureUsageTrackingTests { /// - /// Common Unit Tests for Feature Usage Tracking. + /// Unit Tests for the constructor. /// - public static class BaseFeatureUsageTrackingTests + /// Type of Feature Usage Tracking Session Class to test. + public abstract class BaseConstructorTests + where TFeatureUsageTracking : IFeatureUsageTrackingSession { /// - /// Unit Tests for the constructor. + /// Test to make sure a root tracking session is set up correctly. /// - /// Type of Feature Usage Tracking Session Class to test. - public abstract class BaseConstructorTests - where TFeatureUsageTracking : IFeatureUsageTrackingSession + [Fact] + public void ReturnsInstance() { - /// - /// Test to make sure a root tracking session is set up correctly. - /// - [Fact] - public void ReturnsInstance() - { - var featureName = Guid.NewGuid().ToString(); - var instance = GetFeatureUsageTrackingSession(featureName); - Assert.NotNull(instance); - Assert.Equal(featureName, instance.FeatureName); - Assert.NotEqual(Guid.Empty, instance.FeatureReference); - Assert.Equal(Guid.Empty, instance.ParentReference); - } - - /// - /// Gets a Feature Usage Tracking Session. - /// - /// Name of the feature being tracked. - /// Feature Usage Tracking Session. - protected abstract TFeatureUsageTracking GetFeatureUsageTrackingSession(string featureName); + var featureName = Guid.NewGuid().ToString(); + var instance = GetFeatureUsageTrackingSession(featureName); + Assert.NotNull(instance); + Assert.Equal(featureName, instance.FeatureName); + Assert.NotEqual(Guid.Empty, instance.FeatureReference); + Assert.Equal(Guid.Empty, instance.ParentReference); } /// - /// Unit Tests for the sub-feature method. + /// Gets a Feature Usage Tracking Session. /// - /// Type of Feature Usage Tracking Session Class to test. - public abstract class BaseSubFeatureMethodTests - where TFeatureUsageTracking : IFeatureUsageTrackingSession - { - /// - /// Test to make sure a sub-feature tracking session is set up correctly. - /// - [Fact] - public void ReturnsInstance() - { - var featureName = Guid.NewGuid().ToString(); - var instance = GetFeatureUsageTrackingSession(featureName); - Assert.NotNull(instance); - Assert.Equal(featureName, instance.FeatureName); - Assert.NotEqual(Guid.Empty, instance.FeatureReference); - Assert.Equal(Guid.Empty, instance.ParentReference); + /// Name of the feature being tracked. + /// Feature Usage Tracking Session. + protected abstract TFeatureUsageTracking GetFeatureUsageTrackingSession(string featureName); + } - var subfeatureName = Guid.NewGuid().ToString(); - var subfeature = instance.SubFeature(subfeatureName); - Assert.NotNull(instance); + /// + /// Unit Tests for the sub-feature method. + /// + /// Type of Feature Usage Tracking Session Class to test. + public abstract class BaseSubFeatureMethodTests + where TFeatureUsageTracking : IFeatureUsageTrackingSession + { + /// + /// Test to make sure a sub-feature tracking session is set up correctly. + /// + [Fact] + public void ReturnsInstance() + { + var featureName = Guid.NewGuid().ToString(); + var instance = GetFeatureUsageTrackingSession(featureName); + Assert.NotNull(instance); + Assert.Equal(featureName, instance.FeatureName); + Assert.NotEqual(Guid.Empty, instance.FeatureReference); + Assert.Equal(Guid.Empty, instance.ParentReference); - var genericSubfeature = subfeature as IFeatureUsageTrackingSession; - Assert.NotNull(genericSubfeature); - Assert.Equal(subfeatureName, genericSubfeature?.FeatureName); - Assert.NotEqual(Guid.Empty, genericSubfeature?.FeatureReference); - Assert.Equal(instance.FeatureReference, genericSubfeature?.ParentReference); - } + var subfeatureName = Guid.NewGuid().ToString(); + var subfeature = instance.SubFeature(subfeatureName); + Assert.NotNull(instance); - /// - /// Gets a Feature Usage Tracking Session. - /// - /// Name of the feature being tracked. - /// Feature Usage Tracking Session. - protected abstract TFeatureUsageTracking GetFeatureUsageTrackingSession(string featureName); + var genericSubfeature = subfeature as IFeatureUsageTrackingSession; + Assert.NotNull(genericSubfeature); + Assert.Equal(subfeatureName, genericSubfeature?.FeatureName); + Assert.NotEqual(Guid.Empty, genericSubfeature?.FeatureReference); + Assert.Equal(instance.FeatureReference, genericSubfeature?.ParentReference); } + + /// + /// Gets a Feature Usage Tracking Session. + /// + /// Name of the feature being tracked. + /// Feature Usage Tracking Session. + protected abstract TFeatureUsageTracking GetFeatureUsageTrackingSession(string featureName); } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseViewTrackingTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseViewTrackingTests.cs index e1ff69431..a4f345535 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseViewTrackingTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/BaseViewTrackingTests.cs @@ -3,41 +3,38 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; using Splat.ApplicationPerformanceMonitoring; + using Xunit; -namespace Splat.Tests.ApplicationPerformanceMonitoring +namespace Splat.Tests.ApplicationPerformanceMonitoring; + +/// +/// Common unit tests for APM View Tracking. +/// +public static class BaseViewTrackingTests { /// - /// Common unit tests for APM View Tracking. + /// Unit Tests for the View Tracking Constructor. /// - public static class BaseViewTrackingTests + /// The type for the view tracking class to construcst. + public abstract class ConstructorMethod + where TViewTracking : IViewTracking { /// - /// Unit Tests for the View Tracking Constructor. + /// Test to make sure a view tracking session is set up correctly. /// - /// The type for the view tracking class to construcst. - public abstract class ConstructorMethod - where TViewTracking : IViewTracking + [Fact] + public void ReturnsInstance() { - /// - /// Test to make sure a view tracking session is set up correctly. - /// - [Fact] - public void ReturnsInstance() - { - var instance = GetViewTracking(); - Assert.NotNull(instance); - } - - /// - /// Gets a View Tracking Instance. - /// - /// View Tracking Instance. - protected abstract TViewTracking GetViewTracking(); + var instance = GetViewTracking(); + Assert.NotNull(instance); } + + /// + /// Gets a View Tracking Instance. + /// + /// View Tracking Instance. + protected abstract TViewTracking GetViewTracking(); } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs index 4878cc3c1..595ba41a4 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs @@ -4,146 +4,145 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Text; + using Splat.ApplicationPerformanceMonitoring; + using Xunit; -namespace Splat.Tests.ApplicationPerformanceMonitoring +namespace Splat.Tests.ApplicationPerformanceMonitoring; + +/// +/// Unit Tests for the IEnableFeatureUsageTracking Extensions. +/// +[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "Deliberate Usage")] +public static class EnableFeatureUsageTrackingExtensionsTests { /// - /// Unit Tests for the IEnableFeatureUsageTracking Extensions. + /// Dummy object for testing IEnableFeatureUsageTracking. + /// + public sealed class TestObjectThatSupportsFeatureUsageTracking : IEnableFeatureUsageTracking + { + } + + /// + /// Unit tests for the FeatureUsageTrackingExtensionMethod. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "Deliberate Usage")] - public static class EnableFeatureUsageTrackingExtensionsTests + public sealed class FeatureUsageTrackingSessionMethod { /// - /// Dummy object for testing IEnableFeatureUsageTracking. + /// Test to ensure a default feature usage tracking session is set up. /// - public sealed class TestObjectThatSupportsFeatureUsageTracking : IEnableFeatureUsageTracking + [Fact] + public void ReturnsInstance() { + var instance = new TestObjectThatSupportsFeatureUsageTracking(); + const string expected = "featureName"; + using (var result = instance.FeatureUsageTrackingSession(expected)) + { + Assert.NotNull(result); + Assert.IsType(result); + Assert.Equal(expected, result.FeatureName); + } } /// - /// Unit tests for the FeatureUsageTrackingExtensionMethod. + /// Test to ensure a default feature usage tracking session handles an exception. /// - public sealed class FeatureUsageTrackingSessionMethod + [Fact] + public void HandleOnException() { - /// - /// Test to ensure a default feature usage tracking session is set up. - /// - [Fact] - public void ReturnsInstance() + var instance = new TestObjectThatSupportsFeatureUsageTracking(); + using (var result = instance.FeatureUsageTrackingSession("featureName")) { - var instance = new TestObjectThatSupportsFeatureUsageTracking(); - const string expected = "featureName"; - using (var result = instance.FeatureUsageTrackingSession(expected)) - { - Assert.NotNull(result); - Assert.IsType(result); - Assert.Equal(expected, result.FeatureName); - } - } - - /// - /// Test to ensure a default feature usage tracking session handles an exception. - /// - [Fact] - public void HandleOnException() - { - var instance = new TestObjectThatSupportsFeatureUsageTracking(); - using (var result = instance.FeatureUsageTrackingSession("featureName")) - { - Assert.NotNull(result); - Assert.IsType(result); - result.OnException(new Exception("Test")); - } + Assert.NotNull(result); + Assert.IsType(result); + result.OnException(new Exception("Test")); } + } - /// - /// Test to make sure a sub-feature is returned. - /// - [Fact] - public void ReturnsSubFeatureInstance() + /// + /// Test to make sure a sub-feature is returned. + /// + [Fact] + public void ReturnsSubFeatureInstance() + { + var instance = new TestObjectThatSupportsFeatureUsageTracking(); + using (var result = instance.FeatureUsageTrackingSession("featureName")) { - var instance = new TestObjectThatSupportsFeatureUsageTracking(); - using (var result = instance.FeatureUsageTrackingSession("featureName")) + Assert.NotNull(result); + Assert.IsType(result); + const string expected = "Sub-feature Name"; + using (var subFeature = result.SubFeature(expected)) { - Assert.NotNull(result); - Assert.IsType(result); - const string expected = "Sub-feature Name"; - using (var subFeature = result.SubFeature(expected)) - { - Assert.NotNull(subFeature); - Assert.IsType(subFeature); - Assert.Equal(expected, subFeature.FeatureName); - } + Assert.NotNull(subFeature); + Assert.IsType(subFeature); + Assert.Equal(expected, subFeature.FeatureName); } } + } - /// - /// Test to make sure a sub-feature handles an Exception. - /// - [Fact] - public void SubFeatureHandlesOnException() + /// + /// Test to make sure a sub-feature handles an Exception. + /// + [Fact] + public void SubFeatureHandlesOnException() + { + var instance = new TestObjectThatSupportsFeatureUsageTracking(); + using (var result = instance.FeatureUsageTrackingSession("featureName")) { - var instance = new TestObjectThatSupportsFeatureUsageTracking(); - using (var result = instance.FeatureUsageTrackingSession("featureName")) + Assert.NotNull(result); + Assert.IsType(result); + using (var subFeature = result.SubFeature("Sub-feature Name")) { - Assert.NotNull(result); - Assert.IsType(result); - using (var subFeature = result.SubFeature("Sub-feature Name")) - { - Assert.NotNull(subFeature); - Assert.IsType(subFeature); - subFeature.OnException(new Exception("Sub-feature")); - } + Assert.NotNull(subFeature); + Assert.IsType(subFeature); + subFeature.OnException(new Exception("Sub-feature")); } } } + } + /// + /// Unit tests for the WithFeatureUsageTrackingSession Method. + /// + public sealed class WithFeatureUsageTrackingSessionMethod + { /// - /// Unit tests for the WithFeatureUsageTrackingSession Method. + /// Test to ensure a default feature usage tracking session is set up. /// - public sealed class WithFeatureUsageTrackingSessionMethod + [Fact] + public void HandlesAction() { - /// - /// Test to ensure a default feature usage tracking session is set up. - /// - [Fact] - public void HandlesAction() - { - var instance = new TestObjectThatSupportsFeatureUsageTracking(); - var handled = false; + var instance = new TestObjectThatSupportsFeatureUsageTracking(); + var handled = false; - instance.WithFeatureUsageTrackingSession( - "FeatureName", - _ => handled = true); + instance.WithFeatureUsageTrackingSession( + "FeatureName", + _ => handled = true); - Assert.True(handled); - } + Assert.True(handled); } + } + /// + /// Unit tests for the WithSubFeatureUsageTrackingSession Method. + /// + public sealed class WithSubFeatureUsageTrackingSessionMethod + { /// - /// Unit tests for the WithSubFeatureUsageTrackingSession Method. + /// Test to ensure a default feature usage tracking session is set up. /// - public sealed class WithSubFeatureUsageTrackingSessionMethod + [Fact] + public void HandlesAction() { - /// - /// Test to ensure a default feature usage tracking session is set up. - /// - [Fact] - public void HandlesAction() - { - var instance = new TestObjectThatSupportsFeatureUsageTracking(); - var handled = false; + var instance = new TestObjectThatSupportsFeatureUsageTracking(); + var handled = false; - instance.WithFeatureUsageTrackingSession( - "FeatureName", - session => session.WithSubFeatureUsageTrackingSession("SubFeature", _ => handled = true)); + instance.WithFeatureUsageTrackingSession( + "FeatureName", + session => session.WithSubFeatureUsageTrackingSession("SubFeature", _ => handled = true)); - Assert.True(handled); - } + Assert.True(handled); } } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/ExceptionlessFeatureUsageTrackingSessionTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/ExceptionlessFeatureUsageTrackingSessionTests.cs index 0bf248cbf..c6b52db44 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/ExceptionlessFeatureUsageTrackingSessionTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/ExceptionlessFeatureUsageTrackingSessionTests.cs @@ -4,35 +4,31 @@ // See the LICENSE file in the project root for full license information. #if !WINDOWS_UWP && !ANDROID -using System; -using System.Collections.Generic; -using System.Text; -namespace Splat.Tests.ApplicationPerformanceMonitoring +namespace Splat.Tests.ApplicationPerformanceMonitoring; + +/// +/// Unit Tests for Exceptionless Feature Usage Tracking. +/// +public static class ExceptionlessFeatureUsageTrackingSessionTests { - /// - /// Unit Tests for Exceptionless Feature Usage Tracking. - /// - public static class ExceptionlessFeatureUsageTrackingSessionTests + /// > + public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests { - /// > - public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests + /// + protected override ExceptionlessFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override ExceptionlessFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) - { - return new(featureName); - } + return new(featureName); } + } - /// > - public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + /// > + public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + { + /// + protected override ExceptionlessFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override ExceptionlessFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) - { - return new(featureName); - } + return new(featureName); } } } diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/RaygunFeatureUsageTrackingSessionTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/RaygunFeatureUsageTrackingSessionTests.cs index 09d47b8a4..30290af0c 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/RaygunFeatureUsageTrackingSessionTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/RaygunFeatureUsageTrackingSessionTests.cs @@ -3,53 +3,49 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; using Mindscape.Raygun4Net; -namespace Splat.Tests.ApplicationPerformanceMonitoring +namespace Splat.Tests.ApplicationPerformanceMonitoring; + +/// +/// Unit Tests for Raygun Feature Usage Tracking. +/// +public static class RaygunFeatureUsageTrackingSessionTests { - /// - /// Unit Tests for Raygun Feature Usage Tracking. - /// - public static class RaygunFeatureUsageTrackingSessionTests + private static RaygunFeatureUsageTrackingSession GetRaygunFeatureUsageTrackingSession(string featureName) { - private static RaygunFeatureUsageTrackingSession GetRaygunFeatureUsageTrackingSession(string featureName) + var apiKey = string.Empty; + var raygunSettings = new RaygunSettings { - var apiKey = string.Empty; - var raygunSettings = new RaygunSettings - { - ApiKey = apiKey - }; + ApiKey = apiKey, + }; #if NETSTANDARD2_0 - var raygunClient = new RaygunClient(raygunSettings); + var raygunClient = new RaygunClient(raygunSettings); #else - var raygunClient = new RaygunClient(apiKey); + var raygunClient = new RaygunClient(apiKey); #endif - return new RaygunFeatureUsageTrackingSession(featureName, raygunClient, raygunSettings); - } + return new RaygunFeatureUsageTrackingSession(featureName, raygunClient, raygunSettings); + } - /// > - public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests + /// > + public sealed class ConstructorTests : BaseFeatureUsageTrackingTests.BaseConstructorTests + { + /// + protected override RaygunFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override RaygunFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) - { - return GetRaygunFeatureUsageTrackingSession(featureName); - } + return GetRaygunFeatureUsageTrackingSession(featureName); } + } - /// > - public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + /// > + public sealed class SubFeatureMethodTests : BaseFeatureUsageTrackingTests.BaseSubFeatureMethodTests + { + /// + protected override RaygunFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) { - /// - protected override RaygunFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) - { - return GetRaygunFeatureUsageTrackingSession(featureName); - } + return GetRaygunFeatureUsageTrackingSession(featureName); } } } diff --git a/src/Splat.Tests/LocatorSerialRegisterTests.cs b/src/Splat.Tests/LocatorSerialRegisterTests.cs index fbc29d608..4a28cd43f 100644 --- a/src/Splat.Tests/LocatorSerialRegisterTests.cs +++ b/src/Splat.Tests/LocatorSerialRegisterTests.cs @@ -9,362 +9,361 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Tests to confirm that the locator is working. +/// +public class LocatorSerialRegisterTests { /// - /// Tests to confirm that the locator is working. + /// Tests if the registrations are not empty on no external registrations. /// - public class LocatorSerialRegisterTests + [Fact] + public void InitializeSplat_RegistrationsNotEmptyNoRegistrations() { - /// - /// Tests if the registrations are not empty on no external registrations. - /// - [Fact] - public void InitializeSplat_RegistrationsNotEmptyNoRegistrations() - { - // this is using the internal constructor - var testLocator = new InternalLocator(); - var logManager = testLocator.Current.GetService(typeof(ILogManager)); - var logger = testLocator.Current.GetService(typeof(ILogger)); - - Assert.NotNull(logManager); - Assert.NotNull(logger); - - Assert.IsType(logger); - Assert.IsType(logManager); - } - - /// - /// Tests that if we use a contract it returns null entries for that type. - /// - [Fact] - public void InitializeSplat_ContractRegistrationsNullNoRegistration() - { - var testLocator = new InternalLocator(); - var logManager = testLocator.Current.GetService(typeof(ILogManager), "test"); - var logger = testLocator.Current.GetService(typeof(ILogger), "test"); - - Assert.Null(logManager); - Assert.Null(logger); - } + // this is using the internal constructor + var testLocator = new InternalLocator(); + var logManager = testLocator.Current.GetService(typeof(ILogManager)); + var logger = testLocator.Current.GetService(typeof(ILogger)); - /// - /// Tests using the extension methods that the retrieving of the default InitializeSplat() still work. - /// - [Fact] - public void InitializeSplat_ExtensionMethodsNotNull() - { - var testLocator = new InternalLocator(); - var logManager = testLocator.Current.GetService(); - var logger = testLocator.Current.GetService(); + Assert.NotNull(logManager); + Assert.NotNull(logger); - Assert.NotNull(logManager); - Assert.NotNull(logger); + Assert.IsType(logger); + Assert.IsType(logManager); + } - Assert.IsType(logger); - Assert.IsType(logManager); - } + /// + /// Tests that if we use a contract it returns null entries for that type. + /// + [Fact] + public void InitializeSplat_ContractRegistrationsNullNoRegistration() + { + var testLocator = new InternalLocator(); + var logManager = testLocator.Current.GetService(typeof(ILogManager), "test"); + var logger = testLocator.Current.GetService(typeof(ILogger), "test"); - /// - /// Tests to make sure that the locator's fire the resolver changed notifications. - /// - [Fact] - public void WithoutSuppress_NotificationsHappen() - { - var testLocator = new InternalLocator(); - var originalLocator = testLocator.Internal; + Assert.Null(logManager); + Assert.Null(logger); + } - int numberNotifications = 0; - Action notificationAction = () => numberNotifications++; + /// + /// Tests using the extension methods that the retrieving of the default InitializeSplat() still work. + /// + [Fact] + public void InitializeSplat_ExtensionMethodsNotNull() + { + var testLocator = new InternalLocator(); + var logManager = testLocator.Current.GetService(); + var logger = testLocator.Current.GetService(); - testLocator.RegisterResolverCallbackChanged(notificationAction); + Assert.NotNull(logManager); + Assert.NotNull(logger); - testLocator.SetLocator(new ModernDependencyResolver()); - testLocator.SetLocator(new ModernDependencyResolver()); + Assert.IsType(logger); + Assert.IsType(logManager); + } - // 2 for the changes, 1 for the callback being immediately called. - Assert.Equal(3, numberNotifications); + /// + /// Tests to make sure that the locator's fire the resolver changed notifications. + /// + [Fact] + public void WithoutSuppress_NotificationsHappen() + { + var testLocator = new InternalLocator(); + var originalLocator = testLocator.Internal; - testLocator.SetLocator(originalLocator); - } + var numberNotifications = 0; + Action notificationAction = () => numberNotifications++; - /// - /// Tests to make sure that the locator's don't fire the resolver changed notifications if they are suppressed. - /// - [Fact] - public void WithSuppression_NotificationsDontHappen() - { - var testLocator = new InternalLocator(); - var originalLocator = testLocator.Internal; + testLocator.RegisterResolverCallbackChanged(notificationAction); - using (testLocator.SuppressResolverCallbackChangedNotifications()) - { - int numberNotifications = 0; - Action notificationAction = () => numberNotifications++; + testLocator.SetLocator(new ModernDependencyResolver()); + testLocator.SetLocator(new ModernDependencyResolver()); - testLocator.RegisterResolverCallbackChanged(notificationAction); + // 2 for the changes, 1 for the callback being immediately called. + Assert.Equal(3, numberNotifications); - testLocator.SetLocator(new ModernDependencyResolver()); - testLocator.SetLocator(new ModernDependencyResolver()); - - Assert.Equal(0, numberNotifications); + testLocator.SetLocator(originalLocator); + } - testLocator.SetLocator(originalLocator); - } - } + /// + /// Tests to make sure that the locator's don't fire the resolver changed notifications if they are suppressed. + /// + [Fact] + public void WithSuppression_NotificationsDontHappen() + { + var testLocator = new InternalLocator(); + var originalLocator = testLocator.Internal; - /// - /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). - /// - [Fact] - public void WithResolver_NotificationsDontHappen() + using (testLocator.SuppressResolverCallbackChangedNotifications()) { - int numberNotifications = 0; + var numberNotifications = 0; Action notificationAction = () => numberNotifications++; - var testLocator = new InternalLocator(); testLocator.RegisterResolverCallbackChanged(notificationAction); - using (testLocator.Internal.WithResolver()) - { - using (testLocator.Internal.WithResolver()) - { - } - } + testLocator.SetLocator(new ModernDependencyResolver()); + testLocator.SetLocator(new ModernDependencyResolver()); - // 1 due to the fact the callback is called when we register. - Assert.Equal(1, numberNotifications); + Assert.Equal(0, numberNotifications); + + testLocator.SetLocator(originalLocator); } + } - /// - /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). - /// - [Fact] - public void WithResolver_NotificationsNotSuppressedHappen() - { - int numberNotifications = 0; - Action notificationAction = () => numberNotifications++; + /// + /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). + /// + [Fact] + public void WithResolver_NotificationsDontHappen() + { + var numberNotifications = 0; + Action notificationAction = () => numberNotifications++; - Locator.RegisterResolverCallbackChanged(notificationAction); + var testLocator = new InternalLocator(); + testLocator.RegisterResolverCallbackChanged(notificationAction); - using (Locator.GetLocator().WithResolver(false)) + using (testLocator.Internal.WithResolver()) + { + using (testLocator.Internal.WithResolver()) { - using (Locator.GetLocator().WithResolver(false)) - { - } } - - // 1 due to the fact the callback is called when we register. - // 2 for, 1 for change to resolver, 1 for change back - // 2 for, 1 for change to resolver, 1 for change back - Assert.Equal(5, numberNotifications); } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterAll_WithValuesWorks() - { - var currentMutable = new ModernDependencyResolver(); + // 1 due to the fact the callback is called when we register. + Assert.Equal(1, numberNotifications); + } - var dummy1 = new DummyObjectClass1(); - var dummy2 = new DummyObjectClass2(); - var dummy3 = new DummyObjectClass3(); + /// + /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). + /// + [Fact] + public void WithResolver_NotificationsNotSuppressedHappen() + { + var numberNotifications = 0; + Action notificationAction = () => numberNotifications++; - var testContracts = new[] { string.Empty, "test" }; + Locator.RegisterResolverCallbackChanged(notificationAction); - foreach (var testContract in testContracts) + using (Locator.GetLocator().WithResolver(false)) + { + using (Locator.GetLocator().WithResolver(false)) { - currentMutable.RegisterConstantAnd(dummy1, testContract) - .RegisterConstantAnd(dummy2, testContract) - .RegisterConstant(dummy3, testContract); } + } - foreach (var testContract in testContracts) - { - var items = currentMutable.GetServices(testContract); + // 1 due to the fact the callback is called when we register. + // 2 for, 1 for change to resolver, 1 for change back + // 2 for, 1 for change to resolver, 1 for change back + Assert.Equal(5, numberNotifications); + } - items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterAll_WithValuesWorks() + { + var currentMutable = new ModernDependencyResolver(); - currentMutable.UnregisterAll(testContract); + var dummy1 = new DummyObjectClass1(); + var dummy2 = new DummyObjectClass2(); + var dummy3 = new DummyObjectClass3(); - items = currentMutable.GetServices(testContract); + var testContracts = new[] { string.Empty, "test" }; - items.Should().BeEmpty(); - } + foreach (var testContract in testContracts) + { + currentMutable.RegisterConstantAnd(dummy1, testContract) + .RegisterConstantAnd(dummy2, testContract) + .RegisterConstant(dummy3, testContract); } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values not registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterAll_NoValuesWorks() + foreach (var testContract in testContracts) { - var currentMutable = new ModernDependencyResolver(); + var items = currentMutable.GetServices(testContract); - var items = currentMutable.GetServices(); + items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); - items.Should().BeEmpty(); - - currentMutable.UnregisterAll(); + currentMutable.UnregisterAll(testContract); - items = currentMutable.GetServices(); + items = currentMutable.GetServices(testContract); items.Should().BeEmpty(); } + } - /// - /// Tests tomake sure that the unregister current functions correctly. - /// This is a test when there are values registered. - /// - [Fact] - public void ModernDependencyResolver_ConstantUnregisterCurrent_WithValuesWorks() - { - var dummy1 = new DummyObjectClass1(); - var dummy2 = new DummyObjectClass2(); - var dummy3 = new DummyObjectClass3(); + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values not registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterAll_NoValuesWorks() + { + var currentMutable = new ModernDependencyResolver(); - var currentMutable = new ModernDependencyResolver(); + var items = currentMutable.GetServices(); - var testContracts = new[] { string.Empty, "test" }; + items.Should().BeEmpty(); - foreach (var testContract in testContracts) - { - currentMutable.RegisterConstantAnd(dummy1, testContract) - .RegisterConstantAnd(dummy2, testContract) - .RegisterConstant(dummy3, testContract); - } + currentMutable.UnregisterAll(); - foreach (var testContract in testContracts) - { - var items = currentMutable.GetServices(testContract); + items = currentMutable.GetServices(); + + items.Should().BeEmpty(); + } - items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); + /// + /// Tests tomake sure that the unregister current functions correctly. + /// This is a test when there are values registered. + /// + [Fact] + public void ModernDependencyResolver_ConstantUnregisterCurrent_WithValuesWorks() + { + var dummy1 = new DummyObjectClass1(); + var dummy2 = new DummyObjectClass2(); + var dummy3 = new DummyObjectClass3(); - currentMutable.UnregisterCurrent(testContract); + var currentMutable = new ModernDependencyResolver(); - items = currentMutable.GetServices(testContract); + var testContracts = new[] { string.Empty, "test" }; - items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2 }); - } + foreach (var testContract in testContracts) + { + currentMutable.RegisterConstantAnd(dummy1, testContract) + .RegisterConstantAnd(dummy2, testContract) + .RegisterConstant(dummy3, testContract); } - /// - /// Tests tomake sure that the unregister current functions correctly. - /// This is a test when there are values registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterCurrent_WithValuesWorks() + foreach (var testContract in testContracts) { - var currentMutable = new ModernDependencyResolver(); + var items = currentMutable.GetServices(testContract); - var testContracts = new[] { string.Empty, "test" }; + items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); - foreach (var testContract in testContracts) - { - currentMutable.RegisterAnd(testContract) - .RegisterAnd(testContract) - .Register(testContract); - } + currentMutable.UnregisterCurrent(testContract); - foreach (var testContract in testContracts) - { - var items = currentMutable.GetServices(testContract); + items = currentMutable.GetServices(testContract); - items.Should().HaveCount(3); + items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2 }); + } + } - currentMutable.UnregisterCurrent(testContract); + /// + /// Tests tomake sure that the unregister current functions correctly. + /// This is a test when there are values registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterCurrent_WithValuesWorks() + { + var currentMutable = new ModernDependencyResolver(); - items = currentMutable.GetServices(testContract); + var testContracts = new[] { string.Empty, "test" }; - items.Should().HaveCount(2); - } + foreach (var testContract in testContracts) + { + currentMutable.RegisterAnd(testContract) + .RegisterAnd(testContract) + .Register(testContract); } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values not registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterCurrent_NoValuesWorks() + foreach (var testContract in testContracts) { - var currentMutable = new ModernDependencyResolver(); - var items = currentMutable.GetServices(); + var items = currentMutable.GetServices(testContract); - items.Should().BeEmpty(); + items.Should().HaveCount(3); - currentMutable.UnregisterCurrent(); + currentMutable.UnregisterCurrent(testContract); - items = currentMutable.GetServices(); + items = currentMutable.GetServices(testContract); - items.Should().BeEmpty(); + items.Should().HaveCount(2); } + } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values not registered. - /// - [Fact] - public void FuncDependencyResolver_UnregisterAll() - { - bool unregisterAllCalled = false; - Type? type = null; - string? contract = null; - - var currentMutable = new FuncDependencyResolver( - (funcType, funcContract) => Array.Empty(), - unregisterAll: (passedType, passedContract) => - { - unregisterAllCalled = true; - contract = passedContract; - type = passedType; - }); - - currentMutable.UnregisterAll(); - type.Should().Be(typeof(IDummyInterface)); - contract.Should().BeNull(); - unregisterAllCalled.Should().BeTrue(); - - unregisterAllCalled = false; - currentMutable.UnregisterAll("test"); - type.Should().Be(typeof(IEnableLogger)); - contract.Should().Be("test"); - unregisterAllCalled.Should().BeTrue(); - } + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values not registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterCurrent_NoValuesWorks() + { + var currentMutable = new ModernDependencyResolver(); + var items = currentMutable.GetServices(); - /// - /// Tests tomake sure that the unregister current functions correctly. - /// This is a test when there are values registered. - /// - [Fact] - public void FuncDependencyResolver_UnregisterCurrent() - { - bool unregisterAllCalled = false; - Type? type = null; - string? contract = null; - - var currentMutable = new FuncDependencyResolver( - (funcType, funcContract) => Array.Empty(), - unregisterCurrent: (passedType, passedContract) => - { - unregisterAllCalled = true; - contract = passedContract; - type = passedType; - }); - - currentMutable.UnregisterCurrent(); - type.Should().Be(typeof(IDummyInterface)); - contract.Should().BeNull(); - unregisterAllCalled.Should().BeTrue(); - - unregisterAllCalled = false; - currentMutable.UnregisterCurrent("test"); - type.Should().Be(typeof(IEnableLogger)); - contract.Should().Be("test"); - unregisterAllCalled.Should().BeTrue(); - } + items.Should().BeEmpty(); + + currentMutable.UnregisterCurrent(); + + items = currentMutable.GetServices(); + + items.Should().BeEmpty(); + } + + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values not registered. + /// + [Fact] + public void FuncDependencyResolver_UnregisterAll() + { + var unregisterAllCalled = false; + Type? type = null; + string? contract = null; + + var currentMutable = new FuncDependencyResolver( + (funcType, funcContract) => Array.Empty(), + unregisterAll: (passedType, passedContract) => + { + unregisterAllCalled = true; + contract = passedContract; + type = passedType; + }); + + currentMutable.UnregisterAll(); + type.Should().Be(typeof(IDummyInterface)); + contract.Should().BeNull(); + unregisterAllCalled.Should().BeTrue(); + + unregisterAllCalled = false; + currentMutable.UnregisterAll("test"); + type.Should().Be(typeof(IEnableLogger)); + contract.Should().Be("test"); + unregisterAllCalled.Should().BeTrue(); + } + + /// + /// Tests tomake sure that the unregister current functions correctly. + /// This is a test when there are values registered. + /// + [Fact] + public void FuncDependencyResolver_UnregisterCurrent() + { + var unregisterAllCalled = false; + Type? type = null; + string? contract = null; + + var currentMutable = new FuncDependencyResolver( + (funcType, funcContract) => Array.Empty(), + unregisterCurrent: (passedType, passedContract) => + { + unregisterAllCalled = true; + contract = passedContract; + type = passedType; + }); + + currentMutable.UnregisterCurrent(); + type.Should().Be(typeof(IDummyInterface)); + contract.Should().BeNull(); + unregisterAllCalled.Should().BeTrue(); + + unregisterAllCalled = false; + currentMutable.UnregisterCurrent("test"); + type.Should().Be(typeof(IEnableLogger)); + contract.Should().Be("test"); + unregisterAllCalled.Should().BeTrue(); } } diff --git a/src/Splat.Tests/LocatorTests.cs b/src/Splat.Tests/LocatorTests.cs index 6aab06be7..ceddbb224 100644 --- a/src/Splat.Tests/LocatorTests.cs +++ b/src/Splat.Tests/LocatorTests.cs @@ -10,443 +10,442 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Tests to confirm that the locator is working. +/// +public class LocatorTests { /// - /// Tests to confirm that the locator is working. + /// Shoulds the resolve nulls. /// - public class LocatorTests + [Fact] + public void Can_Register_And_Resolve_Null_Types() { - /// - /// Shoulds the resolve nulls. - /// - [Fact] - public void Can_Register_And_Resolve_Null_Types() - { - var container = new InternalLocator(); - - var foo = 5; - container.CurrentMutable.Register(() => foo, null); - - var bar = 4; - var contract = "foo"; - container.CurrentMutable.Register(() => bar, null, contract); - - Assert.True(container.CurrentMutable.HasRegistration(null)); - var value = container.Current.GetService(null); - Assert.Equal(foo, value); + var container = new InternalLocator(); - Assert.True(container.CurrentMutable.HasRegistration(null, contract)); - value = container.Current.GetService(null, contract); - Assert.Equal(bar, value); + var foo = 5; + container.CurrentMutable.Register(() => foo, null); - var values = container.Current.GetServices(null); - Assert.Equal(1, values.Count()); + var bar = 4; + var contract = "foo"; + container.CurrentMutable.Register(() => bar, null, contract); - container.CurrentMutable.UnregisterCurrent(null); - var valuesNC = container.Current.GetServices(null); - Assert.Equal(0, valuesNC.Count()); - var valuesC = container.Current.GetServices(null, contract); - Assert.Equal(1, valuesC.Count()); + Assert.True(container.CurrentMutable.HasRegistration(null)); + var value = container.Current.GetService(null); + Assert.Equal(foo, value); - container.CurrentMutable.UnregisterAll(null); - valuesNC = container.Current.GetServices(null); - Assert.Equal(0, valuesNC.Count()); + Assert.True(container.CurrentMutable.HasRegistration(null, contract)); + value = container.Current.GetService(null, contract); + Assert.Equal(bar, value); - container.CurrentMutable.UnregisterAll(null, contract); - valuesC = container.Current.GetServices(null, contract); - Assert.Equal(0, valuesC.Count()); - } - - /// - /// Tests if the registrations are not empty on no external registrations. - /// - [Fact] - public void InitializeSplat_RegistrationsNotEmptyNoRegistrations() - { - // this is using the internal constructor - var testLocator = new InternalLocator(); - var logManager = testLocator.Current.GetService(typeof(ILogManager)); - var logger = testLocator.Current.GetService(typeof(ILogger)); + var values = container.Current.GetServices(null); + Assert.Equal(1, values.Count()); - Assert.NotNull(logManager); - Assert.NotNull(logger); - - Assert.IsType(logger); - Assert.IsType(logManager); - } + container.CurrentMutable.UnregisterCurrent(null); + var valuesNC = container.Current.GetServices(null); + Assert.Equal(0, valuesNC.Count()); + var valuesC = container.Current.GetServices(null, contract); + Assert.Equal(1, valuesC.Count()); - /// - /// Tests that if we use a contract it returns null entries for that type. - /// - [Fact] - public void InitializeSplat_ContractRegistrationsNullNoRegistration() - { - var testLocator = new InternalLocator(); - var logManager = testLocator.Current.GetService(typeof(ILogManager), "test"); - var logger = testLocator.Current.GetService(typeof(ILogger), "test"); + container.CurrentMutable.UnregisterAll(null); + valuesNC = container.Current.GetServices(null); + Assert.Equal(0, valuesNC.Count()); - Assert.Null(logManager); - Assert.Null(logger); - } + container.CurrentMutable.UnregisterAll(null, contract); + valuesC = container.Current.GetServices(null, contract); + Assert.Equal(0, valuesC.Count()); + } - /// - /// Tests that if we use a contract it returns null entries for that type. - /// - [Fact] - public void InitializeSplat_ContractRegistrationsExtensionMethodsNullNoRegistration() - { - var testLocator = new InternalLocator(); - var logManager = testLocator.Current.GetService("test"); - var logger = testLocator.Current.GetService("test"); + /// + /// Tests if the registrations are not empty on no external registrations. + /// + [Fact] + public void InitializeSplat_RegistrationsNotEmptyNoRegistrations() + { + // this is using the internal constructor + var testLocator = new InternalLocator(); + var logManager = testLocator.Current.GetService(typeof(ILogManager)); + var logger = testLocator.Current.GetService(typeof(ILogger)); - Assert.Null(logManager); - Assert.Null(logger); - } + Assert.NotNull(logManager); + Assert.NotNull(logger); - /// - /// Tests using the extension methods that the retrieving of the default InitializeSplat() still work. - /// - [Fact] - public void InitializeSplat_ExtensionMethodsNotNull() - { - var testLocator = new InternalLocator(); - var logManager = testLocator.Current.GetService(); - var logger = testLocator.Current.GetService(); + Assert.IsType(logger); + Assert.IsType(logManager); + } - Assert.NotNull(logManager); - Assert.NotNull(logger); + /// + /// Tests that if we use a contract it returns null entries for that type. + /// + [Fact] + public void InitializeSplat_ContractRegistrationsNullNoRegistration() + { + var testLocator = new InternalLocator(); + var logManager = testLocator.Current.GetService(typeof(ILogManager), "test"); + var logger = testLocator.Current.GetService(typeof(ILogger), "test"); - Assert.IsType(logger); - Assert.IsType(logManager); - } + Assert.Null(logManager); + Assert.Null(logger); + } - /// - /// Tests to make sure that the locator's fire the resolver changed notifications. - /// - [Fact] - public void WithoutSuppress_NotificationsHappen() - { - var testLocator = new InternalLocator(); - var originalLocator = testLocator.Internal; + /// + /// Tests that if we use a contract it returns null entries for that type. + /// + [Fact] + public void InitializeSplat_ContractRegistrationsExtensionMethodsNullNoRegistration() + { + var testLocator = new InternalLocator(); + var logManager = testLocator.Current.GetService("test"); + var logger = testLocator.Current.GetService("test"); - int numberNotifications = 0; - Action notificationAction = () => numberNotifications++; + Assert.Null(logManager); + Assert.Null(logger); + } - testLocator.RegisterResolverCallbackChanged(notificationAction); + /// + /// Tests using the extension methods that the retrieving of the default InitializeSplat() still work. + /// + [Fact] + public void InitializeSplat_ExtensionMethodsNotNull() + { + var testLocator = new InternalLocator(); + var logManager = testLocator.Current.GetService(); + var logger = testLocator.Current.GetService(); - testLocator.SetLocator(new ModernDependencyResolver()); - testLocator.SetLocator(new ModernDependencyResolver()); + Assert.NotNull(logManager); + Assert.NotNull(logger); - // 2 for the changes, 1 for the callback being immediately called. - Assert.Equal(3, numberNotifications); + Assert.IsType(logger); + Assert.IsType(logManager); + } - testLocator.SetLocator(originalLocator); - } + /// + /// Tests to make sure that the locator's fire the resolver changed notifications. + /// + [Fact] + public void WithoutSuppress_NotificationsHappen() + { + var testLocator = new InternalLocator(); + var originalLocator = testLocator.Internal; - /// - /// Tests to make sure that the locator's don't fire the resolver changed notifications if they are suppressed. - /// - [Fact] - public void WithSuppression_NotificationsDontHappen() - { - var testLocator = new InternalLocator(); - var originalLocator = testLocator.Internal; + var numberNotifications = 0; + Action notificationAction = () => numberNotifications++; - using (testLocator.SuppressResolverCallbackChangedNotifications()) - { - int numberNotifications = 0; - Action notificationAction = () => numberNotifications++; + testLocator.RegisterResolverCallbackChanged(notificationAction); - testLocator.RegisterResolverCallbackChanged(notificationAction); + testLocator.SetLocator(new ModernDependencyResolver()); + testLocator.SetLocator(new ModernDependencyResolver()); - testLocator.SetLocator(new ModernDependencyResolver()); - testLocator.SetLocator(new ModernDependencyResolver()); + // 2 for the changes, 1 for the callback being immediately called. + Assert.Equal(3, numberNotifications); - Assert.Equal(0, numberNotifications); + testLocator.SetLocator(originalLocator); + } - testLocator.SetLocator(originalLocator); - } - } + /// + /// Tests to make sure that the locator's don't fire the resolver changed notifications if they are suppressed. + /// + [Fact] + public void WithSuppression_NotificationsDontHappen() + { + var testLocator = new InternalLocator(); + var originalLocator = testLocator.Internal; - /// - /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). - /// - [Fact] - public void WithResolver_NotificationsDontHappen() + using (testLocator.SuppressResolverCallbackChangedNotifications()) { - int numberNotifications = 0; + var numberNotifications = 0; Action notificationAction = () => numberNotifications++; - var testLocator = new InternalLocator(); testLocator.RegisterResolverCallbackChanged(notificationAction); - using (testLocator.Internal.WithResolver()) - { - using (testLocator.Internal.WithResolver()) - { - } - } + testLocator.SetLocator(new ModernDependencyResolver()); + testLocator.SetLocator(new ModernDependencyResolver()); + + Assert.Equal(0, numberNotifications); - // 1 due to the fact the callback is called when we register. - Assert.Equal(1, numberNotifications); + testLocator.SetLocator(originalLocator); } + } - /// - /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). - /// - [Fact] - public void WithResolver_NotificationsNotSuppressedHappen() - { - int numberNotifications = 0; - Action notificationAction = () => numberNotifications++; + /// + /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). + /// + [Fact] + public void WithResolver_NotificationsDontHappen() + { + var numberNotifications = 0; + Action notificationAction = () => numberNotifications++; - Locator.RegisterResolverCallbackChanged(notificationAction); + var testLocator = new InternalLocator(); + testLocator.RegisterResolverCallbackChanged(notificationAction); - using (Locator.GetLocator().WithResolver(false)) + using (testLocator.Internal.WithResolver()) + { + using (testLocator.Internal.WithResolver()) { - using (Locator.GetLocator().WithResolver(false)) - { - } } - - // 1 due to the fact the callback is called when we register. - // 2 for, 1 for change to resolver, 1 for change back - // 2 for, 1 for change to resolver, 1 for change back - Assert.Equal(5, numberNotifications); } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterAll_WithValuesWorks() - { - var currentMutable = new ModernDependencyResolver(); + // 1 due to the fact the callback is called when we register. + Assert.Equal(1, numberNotifications); + } - var dummy1 = new DummyObjectClass1(); - var dummy2 = new DummyObjectClass2(); - var dummy3 = new DummyObjectClass3(); + /// + /// Tests to make sure that the locator's don't fire the resolver changed notifications if we use WithResolver(). + /// + [Fact] + public void WithResolver_NotificationsNotSuppressedHappen() + { + var numberNotifications = 0; + Action notificationAction = () => numberNotifications++; - var testContracts = new[] { string.Empty, "test" }; + Locator.RegisterResolverCallbackChanged(notificationAction); - foreach (var testContract in testContracts) + using (Locator.GetLocator().WithResolver(false)) + { + using (Locator.GetLocator().WithResolver(false)) { - currentMutable.RegisterConstant(dummy1, testContract); - currentMutable.RegisterConstant(dummy2, testContract); - currentMutable.RegisterConstant(dummy3, testContract); } + } - foreach (var testContract in testContracts) - { - var items = currentMutable.GetServices(testContract); - - items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); + // 1 due to the fact the callback is called when we register. + // 2 for, 1 for change to resolver, 1 for change back + // 2 for, 1 for change to resolver, 1 for change back + Assert.Equal(5, numberNotifications); + } - currentMutable.UnregisterAll(testContract); + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterAll_WithValuesWorks() + { + var currentMutable = new ModernDependencyResolver(); - items = currentMutable.GetServices(testContract); + var dummy1 = new DummyObjectClass1(); + var dummy2 = new DummyObjectClass2(); + var dummy3 = new DummyObjectClass3(); - items.Should().BeEmpty(); - } - } + var testContracts = new[] { string.Empty, "test" }; - /// - /// Nullables the type. - /// - [Fact] - public void RegisterAndResolveANullableTypeWithValue() + foreach (var testContract in testContracts) { - Locator.CurrentMutable.Register(() => new()); - var doc = Locator.Current.GetService(); - doc.Should().BeOfType(); + currentMutable.RegisterConstant(dummy1, testContract); + currentMutable.RegisterConstant(dummy2, testContract); + currentMutable.RegisterConstant(dummy3, testContract); } - /// - /// Nullables the type. - /// - [Fact] - public void RegisterAndResolveANullableTypeWithNull() + foreach (var testContract in testContracts) { - Locator.CurrentMutable.Register(() => null); - var doc = Locator.Current.GetService(); - doc.Should().BeNull(); - } + var items = currentMutable.GetServices(testContract); - /// - /// Nullables the type. - /// - [Fact] - public void RegisterAndResolveANullableTypeWithValueLocatorDisposed() - { - var currentMutable = new ModernDependencyResolver(); - currentMutable.Register(() => new()); - currentMutable.Dispose(); - var doc = currentMutable.GetService(); - doc.Should().BeNull(); - } + items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); - /// - /// Nullables the type. - /// - [Fact] - public void RegisterAndResolveANullableTypeWithDefault() - { - Locator.CurrentMutable.Register(() => default); - var doc = Locator.Current.GetService(); - doc.Should().BeNull(); - } + currentMutable.UnregisterAll(testContract); - /// - /// Nullables the type. - /// - [Fact] - public void RegisterAndResolveANullableTypeWithNulledInstance() - { - DummyObjectClass1? dummy = null; - Locator.CurrentMutable.Register(() => dummy); - var doc = Locator.Current.GetService(); - doc.Should().BeNull(); + items = currentMutable.GetServices(testContract); + + items.Should().BeEmpty(); } + } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values not registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterAll_NoValuesWorks() - { - var currentMutable = new ModernDependencyResolver(); + /// + /// Nullables the type. + /// + [Fact] + public void RegisterAndResolveANullableTypeWithValue() + { + Locator.CurrentMutable.Register(() => new()); + var doc = Locator.Current.GetService(); + doc.Should().BeOfType(); + } - var items = currentMutable.GetServices(); + /// + /// Nullables the type. + /// + [Fact] + public void RegisterAndResolveANullableTypeWithNull() + { + Locator.CurrentMutable.Register(() => null); + var doc = Locator.Current.GetService(); + doc.Should().BeNull(); + } - items.Should().BeEmpty(); + /// + /// Nullables the type. + /// + [Fact] + public void RegisterAndResolveANullableTypeWithValueLocatorDisposed() + { + var currentMutable = new ModernDependencyResolver(); + currentMutable.Register(() => new()); + currentMutable.Dispose(); + var doc = currentMutable.GetService(); + doc.Should().BeNull(); + } - currentMutable.UnregisterAll(); + /// + /// Nullables the type. + /// + [Fact] + public void RegisterAndResolveANullableTypeWithDefault() + { + Locator.CurrentMutable.Register(() => default); + var doc = Locator.Current.GetService(); + doc.Should().BeNull(); + } - items = currentMutable.GetServices(); + /// + /// Nullables the type. + /// + [Fact] + public void RegisterAndResolveANullableTypeWithNulledInstance() + { + DummyObjectClass1? dummy = null; + Locator.CurrentMutable.Register(() => dummy); + var doc = Locator.Current.GetService(); + doc.Should().BeNull(); + } - items.Should().BeEmpty(); - } + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values not registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterAll_NoValuesWorks() + { + var currentMutable = new ModernDependencyResolver(); - /// - /// Tests tomake sure that the unregister current functions correctly. - /// This is a test when there are values registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterCurrent_WithValuesWorks() - { - var dummy1 = new DummyObjectClass1(); - var dummy2 = new DummyObjectClass2(); - var dummy3 = new DummyObjectClass3(); + var items = currentMutable.GetServices(); - var currentMutable = new ModernDependencyResolver(); + items.Should().BeEmpty(); - var testContracts = new[] { string.Empty, "test" }; + currentMutable.UnregisterAll(); - foreach (var testContract in testContracts) - { - currentMutable.RegisterConstant(dummy1, testContract); - currentMutable.RegisterConstant(dummy2, testContract); - currentMutable.RegisterConstant(dummy3, testContract); - } + items = currentMutable.GetServices(); - foreach (var testContract in testContracts) - { - var items = currentMutable.GetServices(testContract); + items.Should().BeEmpty(); + } - items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); + /// + /// Tests tomake sure that the unregister current functions correctly. + /// This is a test when there are values registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterCurrent_WithValuesWorks() + { + var dummy1 = new DummyObjectClass1(); + var dummy2 = new DummyObjectClass2(); + var dummy3 = new DummyObjectClass3(); - currentMutable.UnregisterCurrent(testContract); + var currentMutable = new ModernDependencyResolver(); - items = currentMutable.GetServices(testContract); + var testContracts = new[] { string.Empty, "test" }; - items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2 }); - } + foreach (var testContract in testContracts) + { + currentMutable.RegisterConstant(dummy1, testContract); + currentMutable.RegisterConstant(dummy2, testContract); + currentMutable.RegisterConstant(dummy3, testContract); } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values not registered. - /// - [Fact] - public void ModernDependencyResolver_UnregisterCurrent_NoValuesWorks() + foreach (var testContract in testContracts) { - var currentMutable = new ModernDependencyResolver(); - var items = currentMutable.GetServices(); + var items = currentMutable.GetServices(testContract); - items.Should().BeEmpty(); + items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2, dummy3 }); - currentMutable.UnregisterCurrent(); + currentMutable.UnregisterCurrent(testContract); - items = currentMutable.GetServices(); + items = currentMutable.GetServices(testContract); - items.Should().BeEmpty(); + items.Should().BeEquivalentTo(new IDummyInterface[] { dummy1, dummy2 }); } + } - /// - /// Tests to make sure that the unregister all functions correctly. - /// This is a test when there are values not registered. - /// - [Fact] - public void FuncDependencyResolver_UnregisterAll() - { - bool unregisterAllCalled = false; - Type? type = null; - string? contract = null; - - var currentMutable = new FuncDependencyResolver( - (funcType, funcContract) => Array.Empty(), - unregisterAll: (passedType, passedContract) => - { - unregisterAllCalled = true; - contract = passedContract!; - type = passedType; - }); - - currentMutable.UnregisterAll(); - type.Should().Be(typeof(IDummyInterface)); - contract.Should().BeNull(); - unregisterAllCalled.Should().BeTrue(); - - unregisterAllCalled = false; - currentMutable.UnregisterAll("test"); - type.Should().Be(typeof(IEnableLogger)); - contract.Should().Be("test"); - unregisterAllCalled.Should().BeTrue(); - } + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values not registered. + /// + [Fact] + public void ModernDependencyResolver_UnregisterCurrent_NoValuesWorks() + { + var currentMutable = new ModernDependencyResolver(); + var items = currentMutable.GetServices(); - /// - /// Tests tomake sure that the unregister current functions correctly. - /// This is a test when there are values registered. - /// - [Fact] - public void FuncDependencyResolver_UnregisterCurrent() - { - bool unregisterAllCalled = false; - Type? type = null; - string? contract = null; - - var currentMutable = new FuncDependencyResolver( - (funcType, funcContract) => Array.Empty(), - unregisterCurrent: (passedType, passedContract) => - { - unregisterAllCalled = true; - contract = passedContract!; - type = passedType; - }); - - currentMutable.UnregisterCurrent(); - type.Should().Be(typeof(IDummyInterface)); - contract.Should().BeNull(); - unregisterAllCalled.Should().BeTrue(); - - unregisterAllCalled = false; - currentMutable.UnregisterCurrent("test"); - type.Should().Be(typeof(IEnableLogger)); - contract.Should().Be("test"); - unregisterAllCalled.Should().BeTrue(); - } + items.Should().BeEmpty(); + + currentMutable.UnregisterCurrent(); + + items = currentMutable.GetServices(); + + items.Should().BeEmpty(); + } + + /// + /// Tests to make sure that the unregister all functions correctly. + /// This is a test when there are values not registered. + /// + [Fact] + public void FuncDependencyResolver_UnregisterAll() + { + var unregisterAllCalled = false; + Type? type = null; + string? contract = null; + + var currentMutable = new FuncDependencyResolver( + (funcType, funcContract) => Array.Empty(), + unregisterAll: (passedType, passedContract) => + { + unregisterAllCalled = true; + contract = passedContract!; + type = passedType; + }); + + currentMutable.UnregisterAll(); + type.Should().Be(typeof(IDummyInterface)); + contract.Should().BeNull(); + unregisterAllCalled.Should().BeTrue(); + + unregisterAllCalled = false; + currentMutable.UnregisterAll("test"); + type.Should().Be(typeof(IEnableLogger)); + contract.Should().Be("test"); + unregisterAllCalled.Should().BeTrue(); + } + + /// + /// Tests tomake sure that the unregister current functions correctly. + /// This is a test when there are values registered. + /// + [Fact] + public void FuncDependencyResolver_UnregisterCurrent() + { + var unregisterAllCalled = false; + Type? type = null; + string? contract = null; + + var currentMutable = new FuncDependencyResolver( + (funcType, funcContract) => Array.Empty(), + unregisterCurrent: (passedType, passedContract) => + { + unregisterAllCalled = true; + contract = passedContract!; + type = passedType; + }); + + currentMutable.UnregisterCurrent(); + type.Should().Be(typeof(IDummyInterface)); + contract.Should().BeNull(); + unregisterAllCalled.Should().BeTrue(); + + unregisterAllCalled = false; + currentMutable.UnregisterCurrent("test"); + type.Should().Be(typeof(IEnableLogger)); + contract.Should().Be("test"); + unregisterAllCalled.Should().BeTrue(); } } diff --git a/src/Splat.Tests/Logging/ActionLoggerTests.cs b/src/Splat.Tests/Logging/ActionLoggerTests.cs index d5569febc..26c6ccd90 100644 --- a/src/Splat.Tests/Logging/ActionLoggerTests.cs +++ b/src/Splat.Tests/Logging/ActionLoggerTests.cs @@ -7,338 +7,337 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests associated with the class. +/// +public class ActionLoggerTests { /// - /// Tests associated with the class. + /// Test to make sure the message writes. + /// + [Fact] + public void Write_Should_Emit_Message() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + + var logger = new ActionLogger( + (message, level) => + { + passedMessage = message; + passedLevel = level; + }, + null!, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Write("This is a test.", LogLevel.Debug); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Debug, passedLevel); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Emit_Message_And_Type() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Debug("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Debug, passedLevel); + Assert.Equal(typeof(DummyObjectClass1), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Emit_Message_And_Type_Provided() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Debug("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Debug, passedLevel); + Assert.Equal(typeof(DummyObjectClass2), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Info_With_Generic_Type_Should_Emit_Message_And_Type() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Info("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Info, passedLevel); + Assert.Equal(typeof(DummyObjectClass1), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Info_With_Generic_Type_Should_Emit_Message_And_Type_Provided() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Info("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Info, passedLevel); + Assert.Equal(typeof(DummyObjectClass2), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Emit_Message_And_Type() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Warn("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Warn, passedLevel); + Assert.Equal(typeof(DummyObjectClass1), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Emit_Message_And_Type_Provided() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Warn("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Warn, passedLevel); + Assert.Equal(typeof(DummyObjectClass2), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Emit_Message_And_Type() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Error("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Error, passedLevel); + Assert.Equal(typeof(DummyObjectClass1), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Emit_Message_And_Type_Provided() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Error("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Error, passedLevel); + Assert.Equal(typeof(DummyObjectClass2), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Fatal_With_Generic_Type_Should_Emit_Message_And_Type() + { + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Fatal("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Fatal, passedLevel); + Assert.Equal(typeof(DummyObjectClass1), passedType); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. /// - public class ActionLoggerTests + [Fact] + public void Fatal_With_Generic_Type_Should_Emit_Message_And_Type_Provided() { - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Write_Should_Emit_Message() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - - var logger = new ActionLogger( - (message, level) => - { - passedMessage = message; - passedLevel = level; - }, - null!, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Write("This is a test.", LogLevel.Debug); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Debug, passedLevel); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Emit_Message_And_Type() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Debug("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Debug, passedLevel); - Assert.Equal(typeof(DummyObjectClass1), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Emit_Message_And_Type_Provided() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Debug("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Debug, passedLevel); - Assert.Equal(typeof(DummyObjectClass2), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Emit_Message_And_Type() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Info("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Info, passedLevel); - Assert.Equal(typeof(DummyObjectClass1), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Emit_Message_And_Type_Provided() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Info("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Info, passedLevel); - Assert.Equal(typeof(DummyObjectClass2), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Emit_Message_And_Type() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Warn("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Warn, passedLevel); - Assert.Equal(typeof(DummyObjectClass1), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Emit_Message_And_Type_Provided() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Warn("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Warn, passedLevel); - Assert.Equal(typeof(DummyObjectClass2), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Emit_Message_And_Type() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Error("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Error, passedLevel); - Assert.Equal(typeof(DummyObjectClass1), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Emit_Message_And_Type_Provided() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Error("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Error, passedLevel); - Assert.Equal(typeof(DummyObjectClass2), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Emit_Message_And_Type() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Fatal("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Fatal, passedLevel); - Assert.Equal(typeof(DummyObjectClass1), passedType); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Emit_Message_And_Type_Provided() - { - string? passedMessage = null; - LogLevel? passedLevel = null; - Type? passedType = null; - - var logger = new ActionLogger( - null!, - (message, type, level) => - { - passedMessage = message; - passedType = type; - passedLevel = level; - }, - null!, - null!); - - var fullLogger = new WrappingFullLogger(logger); - - fullLogger.Fatal("This is a test."); - - Assert.Equal("This is a test.", passedMessage); - Assert.Equal(LogLevel.Fatal, passedLevel); - Assert.Equal(typeof(DummyObjectClass2), passedType); - } + string? passedMessage = null; + LogLevel? passedLevel = null; + Type? passedType = null; + + var logger = new ActionLogger( + null!, + (message, type, level) => + { + passedMessage = message; + passedType = type; + passedLevel = level; + }, + null!, + null!); + + var fullLogger = new WrappingFullLogger(logger); + + fullLogger.Fatal("This is a test."); + + Assert.Equal("This is a test.", passedMessage); + Assert.Equal(LogLevel.Fatal, passedLevel); + Assert.Equal(typeof(DummyObjectClass2), passedType); } } diff --git a/src/Splat.Tests/Logging/BaseTests/AllocateFreeErrorLoggerTestBase.cs b/src/Splat.Tests/Logging/BaseTests/AllocateFreeErrorLoggerTestBase.cs index bc6fe9689..0b532fa18 100644 --- a/src/Splat.Tests/Logging/BaseTests/AllocateFreeErrorLoggerTestBase.cs +++ b/src/Splat.Tests/Logging/BaseTests/AllocateFreeErrorLoggerTestBase.cs @@ -3,1008 +3,1006 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Linq; -using Splat.Tests.Mocks; + using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests the error based allocation free logging. +/// +/// The type of logger. +public abstract class AllocateFreeErrorLoggerTestBase : LoggerBase + where T : IAllocationFreeErrorLogger { /// - /// Tests the error based allocation free logging. - /// - /// The type of logger. - public abstract class AllocateFreeErrorLoggerTestBase : LoggerBase - where T : IAllocationFreeErrorLogger - { - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}", 1); - Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}", 1); - Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}", 1); - Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}", 1); - Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}", 1); - Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}, {1}", 1, 2); - Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalExceptionTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}", 1); + Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}", 1); + Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}", 1); + Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}", 1); + Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorExceptionTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}", 1); + Assert.Equal("1 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}, {1}", 1, 2); + Assert.Equal("1, 2 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalExceptionTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Fatal(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); } } diff --git a/src/Splat.Tests/Logging/BaseTests/AllocationFreeLoggerBaseTestBase.cs b/src/Splat.Tests/Logging/BaseTests/AllocationFreeLoggerBaseTestBase.cs index 298e07af7..28b869427 100644 --- a/src/Splat.Tests/Logging/BaseTests/AllocationFreeLoggerBaseTestBase.cs +++ b/src/Splat.Tests/Logging/BaseTests/AllocationFreeLoggerBaseTestBase.cs @@ -3,1008 +3,1006 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Diagnostics.CodeAnalysis; using System.Linq; + using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests that check the functionality of the class. +/// +/// The type of logger to test. +public abstract class AllocationFreeLoggerBaseTestBase : AllocateFreeErrorLoggerTestBase + where T : IAllocationFreeLogger { /// - /// Tests that check the functionality of the class. - /// - /// The type of logger to test. - public abstract class AllocationFreeLoggerBaseTestBase : AllocateFreeErrorLoggerTestBase - where T : IAllocationFreeLogger - { - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}", 1); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug("{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}", 1, 2); - Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug("{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug("{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void DebugSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void DebugSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void DebugSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes eight arguments. - /// - [Fact] - public void DebugEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes eighth arguments. - /// - [Fact] - public void DebugEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void DebugNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void DebugNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void DebugTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void DebugTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}", 1); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Info("{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}", 1, 2); - Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Info("{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Info("{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void InfoSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void InfoSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void InfoSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes eight arguments. - /// - [Fact] - public void InfoEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes eight arguments. - /// - [Fact] - public void InfoEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void InfoNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void InfoNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void InfoTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void InfoTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}", 1); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Warn("{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}", 1, 2); - Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Warn("{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Warn("{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void WarnSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void WarnSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void WarnSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes eighth arguments. - /// - [Fact] - public void WarnEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes eighth arguments. - /// - [Fact] - public void WarnEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void WarnNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void WarnNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void WarnTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void WarnTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}", 1); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorOneArgumentMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error("{0}", 1); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}", 1, 2); - Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error("{0}, {1}", 1, 2); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error("{0}, {1}, {2}", 1, 2, 3); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorFourArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void ErrorSixArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void ErrorSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void ErrorSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes eighth arguments. - /// - [Fact] - public void ErrorEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes eighth arguments. - /// - [Fact] - public void ErrorEightArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void ErrorNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void ErrorNineArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void ErrorTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void ErrorTenArgumentsMethod_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Empty(target.Logs); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalOneArgumentMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}", 1); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalTwoArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}", 1, 2); - Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalThreeArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}", 1, 2, 3); - Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalFourArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}, {3}", 1, 2, 3, 4); - Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalFiveArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); - Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes three arguments. - /// - [Fact] - public void FatalSixArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); - Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes seven arguments. - /// - [Fact] - public void FatalSevenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); - Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes eighth arguments. - /// - [Fact] - public void FatalEightArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes nine arguments. - /// - [Fact] - public void FatalNineArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests the inner logger writes ten arguments. - /// - [Fact] - public void FatalTenArgumentsMethod_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}", 1); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug("{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}", 1, 2); + Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug("{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug("{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void DebugSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void DebugSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void DebugSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes eight arguments. + /// + [Fact] + public void DebugEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes eighth arguments. + /// + [Fact] + public void DebugEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void DebugNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void DebugNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void DebugTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void DebugTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Debug("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}", 1); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Info("{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}", 1, 2); + Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Info("{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Info("{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void InfoSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void InfoSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void InfoSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes eight arguments. + /// + [Fact] + public void InfoEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes eight arguments. + /// + [Fact] + public void InfoEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void InfoNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void InfoNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void InfoTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void InfoTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}", 1); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Warn("{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}", 1, 2); + Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Warn("{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Warn("{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void WarnSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void WarnSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void WarnSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes eighth arguments. + /// + [Fact] + public void WarnEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes eighth arguments. + /// + [Fact] + public void WarnEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void WarnNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void WarnNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void WarnTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void WarnTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Warn("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}", 1); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorOneArgumentMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error("{0}", 1); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}", 1, 2); + Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorTwoArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error("{0}, {1}", 1, 2); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorThreeArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error("{0}, {1}, {2}", 1, 2, 3); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorFourArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Info("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorFiveArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Info("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void ErrorSixArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Info("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void ErrorSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void ErrorSevenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes eighth arguments. + /// + [Fact] + public void ErrorEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes eighth arguments. + /// + [Fact] + public void ErrorEightArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void ErrorNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void ErrorNineArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void ErrorTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void ErrorTenArgumentsMethod_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Empty(target.Logs); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalOneArgumentMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}", 1); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalTwoArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}", 1, 2); + Assert.Equal("1, 2", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalThreeArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}", 1, 2, 3); + Assert.Equal("1, 2, 3", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalFourArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}, {3}", 1, 2, 3, 4); + Assert.Equal("1, 2, 3, 4", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalFiveArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5); + Assert.Equal("1, 2, 3, 4, 5", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes three arguments. + /// + [Fact] + public void FatalSixArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6); + Assert.Equal("1, 2, 3, 4, 5, 6", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes seven arguments. + /// + [Fact] + public void FatalSevenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}", 1, 2, 3, 4, 5, 6, 7); + Assert.Equal("1, 2, 3, 4, 5, 6, 7", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes eighth arguments. + /// + [Fact] + public void FatalEightArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", 1, 2, 3, 4, 5, 6, 7, 8); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes nine arguments. + /// + [Fact] + public void FatalNineArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", 1, 2, 3, 4, 5, 6, 7, 8, 9); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests the inner logger writes ten arguments. + /// + [Fact] + public void FatalTenArgumentsMethod_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Fatal("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + Assert.Equal("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); } } diff --git a/src/Splat.Tests/Logging/BaseTests/FullLoggerTestBase.cs b/src/Splat.Tests/Logging/BaseTests/FullLoggerTestBase.cs index 7e9127a68..68e767faa 100644 --- a/src/Splat.Tests/Logging/BaseTests/FullLoggerTestBase.cs +++ b/src/Splat.Tests/Logging/BaseTests/FullLoggerTestBase.cs @@ -3,522 +3,522 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Globalization; using System.Linq; + using Splat.Tests.Mocks; + using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// A base class for testing full loggers that are available. +/// +public abstract class FullLoggerTestBase : AllocationFreeLoggerBaseTestBase { /// - /// A base class for testing full loggers that are available. - /// - public abstract class FullLoggerTestBase : AllocationFreeLoggerBaseTestBase - { - /// - /// Test to make sure the debug emits nothing when not enabled. - /// - [Fact] - public void Debug_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Debug( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the debug emits something when enabled. - /// - [Fact] - public void Debug_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Debug( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Info emits nothing when not enabled. - /// - [Fact] - public void Info_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Info( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the Info emits something when enabled. - /// - [Fact] - public void Info_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Info( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Warn emits nothing when not enabled. - /// - [Fact] - public void Warn_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Warn( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the Warn emits something when enabled. - /// - [Fact] - public void Warn_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Warn( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Error emits nothing when not enabled. - /// - [Fact] - public void Error_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Error( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the Error emits something when enabled. - /// - [Fact] - public void Error_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Error( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Fatal emits something when enabled. - /// - [Fact] - public void Fatal_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Fatal( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Debug("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Write_Message_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Debug("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Info("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Write_Message_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Info("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Warn("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Write_Message_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Warn("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Error("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Write_Message_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Error("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Fatal("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Write_Message_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Fatal("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the debug emits something when enabled. - /// - [Fact] - public void Debug_Enabled_FormatProvider_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Debug(CultureInfo.InvariantCulture, "This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Debug_Message_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Debug("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Debug_Object_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Debug(new DummyObjectClass1()); - - Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the debug emits something when enabled. - /// - [Fact] - public void Info_Enabled_FormatProvider_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Info); - - logger.Info(CultureInfo.InvariantCulture, "This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Info_Object_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Info); - - logger.Info(new DummyObjectClass1()); - - Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Info_Message_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Info); - - logger.Info("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the debug emits something when enabled. - /// - [Fact] - public void Warn_Enabled_FormatProvider_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Warn); - - logger.Warn(CultureInfo.InvariantCulture, "This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Warn_Message_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Warn); - - logger.Warn("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Warn_Object_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Warn); - - logger.Warn(new DummyObjectClass1()); - - Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the debug emits something when enabled. - /// - [Fact] - public void Error_Enabled_FormatProvider_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Error); - - logger.Error(CultureInfo.InvariantCulture, "This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Error_Message_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Error); - - logger.Error("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Error_Object_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Error); - - logger.Error(new DummyObjectClass1()); - - Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the debug emits something when enabled. - /// - [Fact] - public void Fatal_Enabled_FormatProvider_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - - logger.Fatal(CultureInfo.InvariantCulture, "This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Fatal_Object_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - - logger.Fatal(new DummyObjectClass1()); - - Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure that when enabled debug emits values. - /// - [Fact] - public void Fatal_Message_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - - logger.Fatal("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } + /// Test to make sure the debug emits nothing when not enabled. + /// + [Fact] + public void Debug_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Debug( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the debug emits something when enabled. + /// + [Fact] + public void Debug_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Debug( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Info emits nothing when not enabled. + /// + [Fact] + public void Info_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Info( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the Info emits something when enabled. + /// + [Fact] + public void Info_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Info( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Warn emits nothing when not enabled. + /// + [Fact] + public void Warn_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Warn( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the Warn emits something when enabled. + /// + [Fact] + public void Warn_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Warn( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Error emits nothing when not enabled. + /// + [Fact] + public void Error_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Error( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the Error emits something when enabled. + /// + [Fact] + public void Error_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Error( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Fatal emits something when enabled. + /// + [Fact] + public void Fatal_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Fatal( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Debug("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Write_Message_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Debug("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Info_With_Generic_Type_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Info("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Info_With_Generic_Type_Should_Write_Message_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Info("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Warn("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Write_Message_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Warn("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Error("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Write_Message_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Error("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Fatal_With_Generic_Type_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Fatal("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message is passed to the logger. + /// + [Fact] + public void Fatal_With_Generic_Type_Should_Write_Message_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Fatal("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the debug emits something when enabled. + /// + [Fact] + public void Debug_Enabled_FormatProvider_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Debug(CultureInfo.InvariantCulture, "This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Debug_Message_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Debug("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Debug_Object_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Debug(new DummyObjectClass1()); + + Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the debug emits something when enabled. + /// + [Fact] + public void Info_Enabled_FormatProvider_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Info); + + logger.Info(CultureInfo.InvariantCulture, "This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Info_Object_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Info); + + logger.Info(new DummyObjectClass1()); + + Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Info_Message_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Info); + + logger.Info("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the debug emits something when enabled. + /// + [Fact] + public void Warn_Enabled_FormatProvider_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Warn); + + logger.Warn(CultureInfo.InvariantCulture, "This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Warn_Message_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Warn); + + logger.Warn("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Warn_Object_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Warn); + + logger.Warn(new DummyObjectClass1()); + + Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the debug emits something when enabled. + /// + [Fact] + public void Error_Enabled_FormatProvider_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Error); + + logger.Error(CultureInfo.InvariantCulture, "This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Error_Message_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Error); + + logger.Error("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Error_Object_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Error); + + logger.Error(new DummyObjectClass1()); + + Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the debug emits something when enabled. + /// + [Fact] + public void Fatal_Enabled_FormatProvider_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + + logger.Fatal(CultureInfo.InvariantCulture, "This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Fatal_Object_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + + logger.Fatal(new DummyObjectClass1()); + + Assert.Equal(typeof(DummyObjectClass1).ToString(), target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure that when enabled debug emits values. + /// + [Fact] + public void Fatal_Message_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + + logger.Fatal("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); } } diff --git a/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs b/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs index b839d05e4..928d0f09d 100644 --- a/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs +++ b/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs @@ -7,437 +7,436 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Contains common tests associated with all loggers. +/// +/// The type of logger. +public abstract class LoggerBase + where T : ILogger { /// - /// Contains common tests associated with all loggers. - /// - /// The type of logger. - public abstract class LoggerBase - where T : ILogger - { - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Logger_Level_Debug_Should_Be_correct() - { - var (logger, _) = GetLogger(LogLevel.Debug); - - Assert.Equal(LogLevel.Debug, logger.Level); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Logger_Level_Info_Should_Be_correct() - { - var (logger, _) = GetLogger(LogLevel.Info); - - Assert.Equal(LogLevel.Info, logger.Level); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Logger_Level_Warn_Should_Be_correct() - { - var (logger, _) = GetLogger(LogLevel.Warn); - - Assert.Equal(LogLevel.Warn, logger.Level); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Logger_Level_Error_Should_Be_correct() - { - var (logger, _) = GetLogger(LogLevel.Error); - - Assert.Equal(LogLevel.Error, logger.Level); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Logger_Level_Fatal_Should_Be_correct() - { - var (logger, _) = GetLogger(LogLevel.Fatal); - - Assert.Equal(LogLevel.Fatal, logger.Level); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Write_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Write("This is a test.", LogLevel.Debug); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Info_Write_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - - logger.Write("This is a test.", LogLevel.Info); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Warn_Write_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - - logger.Write("This is a test.", LogLevel.Warn); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Error_Write_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Error); - - logger.Write("This is a test.", LogLevel.Error); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Fatal_Write_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - - logger.Write("This is a test.", LogLevel.Fatal); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void DebugException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Write(FormatHelper.Exception, "1", LogLevel.Debug); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void DebugException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Write(FormatHelper.Exception, "1", LogLevel.Debug); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void InfoException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Write(FormatHelper.Exception, "1", LogLevel.Info); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void InfoException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Write(FormatHelper.Exception, "1", LogLevel.Info); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void WarnException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Write(FormatHelper.Exception, "1", LogLevel.Warn); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void WarnException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Write(FormatHelper.Exception, "1", LogLevel.Warn); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void ErrorException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Write(FormatHelper.Exception, "1", LogLevel.Error); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void ErrorException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Write(FormatHelper.Exception, "1", LogLevel.Error); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void FatalException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Write(FormatHelper.Exception, "1", LogLevel.Fatal); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void DebugType_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Debug); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void DebugType_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Debug); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void InfoType_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Info); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void InfoType_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Info); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void WarnType_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Warn); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void WarnType_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Warn); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void ErrorType_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Error); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void ErrorType_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Error); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void FatalType_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Write("1", typeof(DummyObjectClass1), LogLevel.Fatal); - Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void DebugTypeException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Debug); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Debug); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void DebugTypeException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Debug); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void InfoTypeException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Info); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Info); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void InfoTypeException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Info); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void WarnTypeException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Warn); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Warn); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void WarnTypeException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Warn); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void ErrorTypeException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Error); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Error); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void ErrorTypeException_Should_Not_Write_If_Higher_Level() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Error); - Assert.Empty(target.Logs); - } - - /// - /// Tests that the inner logger writes correctly. - /// - [Fact] - public void FatalTypeException_Should_Write_Message() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Fatal); - Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Gets the logger to test. - /// - /// The minimum log level. - /// The logger. - protected abstract (T logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel); + /// Test to make sure the message writes. + /// + [Fact] + public void Logger_Level_Debug_Should_Be_correct() + { + var (logger, _) = GetLogger(LogLevel.Debug); + + Assert.Equal(LogLevel.Debug, logger.Level); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Logger_Level_Info_Should_Be_correct() + { + var (logger, _) = GetLogger(LogLevel.Info); + + Assert.Equal(LogLevel.Info, logger.Level); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Logger_Level_Warn_Should_Be_correct() + { + var (logger, _) = GetLogger(LogLevel.Warn); + + Assert.Equal(LogLevel.Warn, logger.Level); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Logger_Level_Error_Should_Be_correct() + { + var (logger, _) = GetLogger(LogLevel.Error); + + Assert.Equal(LogLevel.Error, logger.Level); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Logger_Level_Fatal_Should_Be_correct() + { + var (logger, _) = GetLogger(LogLevel.Fatal); + + Assert.Equal(LogLevel.Fatal, logger.Level); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Write_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Write("This is a test.", LogLevel.Debug); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Info_Write_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + + logger.Write("This is a test.", LogLevel.Info); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Warn_Write_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + + logger.Write("This is a test.", LogLevel.Warn); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Error_Write_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Error); + + logger.Write("This is a test.", LogLevel.Error); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Fatal_Write_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + + logger.Write("This is a test.", LogLevel.Fatal); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void DebugException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Write(FormatHelper.Exception, "1", LogLevel.Debug); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void DebugException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Write(FormatHelper.Exception, "1", LogLevel.Debug); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void InfoException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Write(FormatHelper.Exception, "1", LogLevel.Info); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void InfoException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Write(FormatHelper.Exception, "1", LogLevel.Info); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void WarnException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Write(FormatHelper.Exception, "1", LogLevel.Warn); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void WarnException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Write(FormatHelper.Exception, "1", LogLevel.Warn); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void ErrorException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Write(FormatHelper.Exception, "1", LogLevel.Error); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void ErrorException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Write(FormatHelper.Exception, "1", LogLevel.Error); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void FatalException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Write(FormatHelper.Exception, "1", LogLevel.Fatal); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void DebugType_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Debug); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void DebugType_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Debug); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void InfoType_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Info); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void InfoType_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Info); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void WarnType_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Warn); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void WarnType_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Warn); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void ErrorType_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Error); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void ErrorType_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Error); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void FatalType_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Write("1", typeof(DummyObjectClass1), LogLevel.Fatal); + Assert.Equal("1", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void DebugTypeException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Debug); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Debug); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void DebugTypeException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Debug); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void InfoTypeException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Info); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Info); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void InfoTypeException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Info); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void WarnTypeException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Warn); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Warn); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void WarnTypeException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Warn); + Assert.Empty(target.Logs); } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void ErrorTypeException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Error); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Error); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void ErrorTypeException_Should_Not_Write_If_Higher_Level() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Error); + Assert.Empty(target.Logs); + } + + /// + /// Tests that the inner logger writes correctly. + /// + [Fact] + public void FatalTypeException_Should_Write_Message() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + logger.Write(FormatHelper.Exception, "1", typeof(DummyObjectClass1), LogLevel.Fatal); + Assert.Equal($"1 {FormatHelper.Exception}", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Gets the logger to test. + /// + /// The minimum log level. + /// The logger. + protected abstract (T logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel); } diff --git a/src/Splat.Tests/Logging/BaseTests/WrappingFullLoggerTestBase.cs b/src/Splat.Tests/Logging/BaseTests/WrappingFullLoggerTestBase.cs index cb0ab0393..5210403d4 100644 --- a/src/Splat.Tests/Logging/BaseTests/WrappingFullLoggerTestBase.cs +++ b/src/Splat.Tests/Logging/BaseTests/WrappingFullLoggerTestBase.cs @@ -7,334 +7,333 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests for the wrapping full logger. +/// +public abstract class WrappingFullLoggerTestBase : AllocationFreeLoggerBaseTestBase { /// - /// Tests for the wrapping full logger. + /// Test to make sure the debug emits nothing when not enabled. + /// + [Fact] + public void Debug_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Warn( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the debug emits something when enabled. + /// + [Fact] + public void Debug_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Debug( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Info emits nothing when not enabled. + /// + [Fact] + public void Info_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Info( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the Info emits something when enabled. + /// + [Fact] + public void Info_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Info( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Warn emits nothing when not enabled. + /// + [Fact] + public void Warn_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Warn( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the Warn emits something when enabled. + /// + [Fact] + public void Warn_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Warn( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Error emits nothing when not enabled. + /// + [Fact] + public void Error_Disabled_Should_Not_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Error( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Empty(target.Logs); + Assert.False(invoked); + } + + /// + /// Test to make sure the Error emits something when enabled. + /// + [Fact] + public void Error_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Debug); + var invoked = false; + + logger.Error( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the Fatal emits something when enabled. + /// + [Fact] + public void Fatal_Enabled_Should_Emit() + { + var (logger, target) = GetLogger(LogLevel.Fatal); + var invoked = false; + + logger.Fatal( + () => + { + invoked = true; + return "This is a test."; + }); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + Assert.True(invoked); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Write_Message_And_Type() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Debug("This is a test."); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the type parameter is passed to the logger. + /// + [Fact] + public void Write_Should_Write_Message_And_Type() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Write("This is a test.", LogLevel.Debug); + + Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Debug("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Info_With_Generic_Type_Should_Write_Message_And_Type() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Info("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. /// - public abstract class WrappingFullLoggerTestBase : AllocationFreeLoggerBaseTestBase + [Fact] + public void Info_With_Generic_Type_Should_Write_Message_And_Type_Provided() { - /// - /// Test to make sure the debug emits nothing when not enabled. - /// - [Fact] - public void Debug_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Warn( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the debug emits something when enabled. - /// - [Fact] - public void Debug_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Debug( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Info emits nothing when not enabled. - /// - [Fact] - public void Info_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Info( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the Info emits something when enabled. - /// - [Fact] - public void Info_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Info( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Warn emits nothing when not enabled. - /// - [Fact] - public void Warn_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Warn( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the Warn emits something when enabled. - /// - [Fact] - public void Warn_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Warn( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Error emits nothing when not enabled. - /// - [Fact] - public void Error_Disabled_Should_Not_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Error( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Empty(target.Logs); - Assert.False(invoked); - } - - /// - /// Test to make sure the Error emits something when enabled. - /// - [Fact] - public void Error_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Debug); - bool invoked = false; - - logger.Error( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the Fatal emits something when enabled. - /// - [Fact] - public void Fatal_Enabled_Should_Emit() - { - var (logger, target) = GetLogger(LogLevel.Fatal); - bool invoked = false; - - logger.Fatal( - () => - { - invoked = true; - return "This is a test."; - }); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - Assert.True(invoked); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Write_Message_And_Type() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Debug("This is a test."); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the type parameter is passed to the logger. - /// - [Fact] - public void Write_Should_Write_Message_And_Type() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Write("This is a test.", LogLevel.Debug); - - Assert.Equal("This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Debug("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Write_Message_And_Type() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Info("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Info("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Write_Message_And_Type() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Warn("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Warn("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Write_Message_And_Type() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Error("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Error("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Write_Message_And_Type() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Fatal("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var (logger, target) = GetLogger(LogLevel.Debug); - - logger.Fatal("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); - } + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Info("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Write_Message_And_Type() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Warn("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Warn("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Write_Message_And_Type() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Error("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Error("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Fatal_With_Generic_Type_Should_Write_Message_And_Type() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Fatal("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Fatal_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var (logger, target) = GetLogger(LogLevel.Debug); + + logger.Fatal("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim()); } } diff --git a/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs b/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs index 60e27a175..163f6e318 100644 --- a/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs +++ b/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs @@ -10,69 +10,68 @@ using Splat.NLog; using Splat.Tests.Mocks; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests that verify the class. +/// +public class NLogLoggerTests : FullLoggerTestBase { - /// - /// Tests that verify the class. - /// - 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 }, - { global::NLog.LogLevel.Warn, LogLevel.Warn }, - { global::NLog.LogLevel.Fatal, LogLevel.Fatal }, - { global::NLog.LogLevel.Info, LogLevel.Info }, - }; + { global::NLog.LogLevel.Debug, LogLevel.Debug }, + { global::NLog.LogLevel.Error, LogLevel.Error }, + { global::NLog.LogLevel.Warn, LogLevel.Warn }, + { global::NLog.LogLevel.Fatal, LogLevel.Fatal }, + { global::NLog.LogLevel.Info, LogLevel.Info }, + }; - private static readonly Dictionary _splat2NLog = new() - { - { LogLevel.Debug, global::NLog.LogLevel.Debug }, - { LogLevel.Error, global::NLog.LogLevel.Error }, - { LogLevel.Warn, global::NLog.LogLevel.Warn }, - { LogLevel.Fatal, global::NLog.LogLevel.Fatal }, - { LogLevel.Info, global::NLog.LogLevel.Info }, - }; + private static readonly Dictionary _splat2NLog = new() + { + { LogLevel.Debug, global::NLog.LogLevel.Debug }, + { LogLevel.Error, global::NLog.LogLevel.Error }, + { LogLevel.Warn, global::NLog.LogLevel.Warn }, + { LogLevel.Fatal, global::NLog.LogLevel.Fatal }, + { LogLevel.Info, global::NLog.LogLevel.Info }, + }; + + /// + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) + { + var configuration = new LoggingConfiguration(); - /// - protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) + var errorTarget = new MemoryTargetWrapper { - var configuration = new LoggingConfiguration(); + Layout = "${message} ${exception:format=tostring}", + }; - var errorTarget = new MemoryTargetWrapper - { - Layout = "${message} ${exception:format=tostring}" - }; + configuration.AddTarget(errorTarget); + var errorLoggingRule = new LoggingRule("*", _splat2NLog[minimumLogLevel], errorTarget); + configuration.LoggingRules.Add(errorLoggingRule); - configuration.AddTarget(errorTarget); - var errorLoggingRule = new LoggingRule("*", _splat2NLog[minimumLogLevel], errorTarget); - configuration.LoggingRules.Add(errorLoggingRule); + LogManager.Configuration = configuration; - LogManager.Configuration = configuration; + return (new NLogLogger(LogManager.GetCurrentClassLogger()), errorTarget); + } - return (new NLogLogger(LogManager.GetCurrentClassLogger()), errorTarget); - } + private class MemoryTargetWrapper : TargetWithLayout, IMockLogTarget + { + private readonly List<(LogLevel, string)> _logs = new(); - private class MemoryTargetWrapper : TargetWithLayout, IMockLogTarget + public MemoryTargetWrapper() { - private readonly List<(LogLevel, string)> _logs = new(); - - public MemoryTargetWrapper() - { - Name = "test wrapper"; - } + Name = "test wrapper"; + } - public ICollection<(LogLevel logLevel, string message)> Logs => _logs; + public ICollection<(LogLevel logLevel, string message)> Logs => _logs; - /// - /// 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))); - } + /// + /// 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))); } } } diff --git a/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs b/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs index 729498be6..5726902bb 100644 --- a/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs +++ b/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs @@ -17,136 +17,135 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests that verify the class. +/// +public class SerilogLoggerTests : FullLoggerTestBase { + private static readonly char[] NewLine = Environment.NewLine.ToCharArray(); + /// - /// Tests that verify the class. + /// Gets a list of mappings of Serilog levels and equivalent Splat log levels. /// - public class SerilogLoggerTests : FullLoggerTestBase + private static readonly Dictionary _mappingsToSerilog = new() { - private static readonly char[] NewLine = Environment.NewLine.ToCharArray(); + { LogLevel.Debug, LogEventLevel.Debug }, + { LogLevel.Info, LogEventLevel.Information }, + { LogLevel.Warn, LogEventLevel.Warning }, + { LogLevel.Error, LogEventLevel.Error }, + { LogLevel.Fatal, LogEventLevel.Fatal }, + }; - /// - /// Gets a list of mappings of Serilog levels and equivalent Splat log levels. - /// - private static readonly Dictionary _mappingsToSerilog = new() - { - { LogLevel.Debug, LogEventLevel.Debug }, - { LogLevel.Info, LogEventLevel.Information }, - { LogLevel.Warn, LogEventLevel.Warning }, - { LogLevel.Error, LogEventLevel.Error }, - { LogLevel.Fatal, LogEventLevel.Fatal } - }; - - /// - /// Gets a list of mappings of Serilog levels and equivalent Splat log levels. - /// - private static readonly Dictionary _mappingsToSplat = new() - { - { LogEventLevel.Debug, LogLevel.Debug }, - { LogEventLevel.Information, LogLevel.Info }, - { LogEventLevel.Warning, LogLevel.Warn }, - { LogEventLevel.Error, LogLevel.Error }, - { LogEventLevel.Fatal, LogLevel.Fatal } - }; - - /// - /// Test to make sure the calling `UseSerilogWithWrappingFullLogger` logs. - /// - [Fact] - public void Configuring_With_Static_Log_Should_Write_Message() + /// + /// Gets a list of mappings of Serilog levels and equivalent Splat log levels. + /// + private static readonly Dictionary _mappingsToSplat = new() + { + { LogEventLevel.Debug, LogLevel.Debug }, + { LogEventLevel.Information, LogLevel.Info }, + { LogEventLevel.Warning, LogLevel.Warn }, + { LogEventLevel.Error, LogLevel.Error }, + { LogEventLevel.Fatal, LogLevel.Fatal }, + }; + + /// + /// Test to make sure the calling `UseSerilogWithWrappingFullLogger` logs. + /// + [Fact] + public void Configuring_With_Static_Log_Should_Write_Message() + { + var originalLocator = Locator.InternalLocator; + try { - var originalLocator = Locator.InternalLocator; - try - { - Locator.InternalLocator = new InternalLocator(); - var (seriLogger, target) = CreateSerilogger(LogLevel.Debug); - Log.Logger = seriLogger; + Locator.InternalLocator = new InternalLocator(); + var (seriLogger, target) = CreateSerilogger(LogLevel.Debug); + Log.Logger = seriLogger; - Locator.CurrentMutable.UseSerilogFullLogger(); + Locator.CurrentMutable.UseSerilogFullLogger(); - Assert.Equal(0, target.Logs.Count); + Assert.Equal(0, target.Logs.Count); - IEnableLogger logger = null!; - logger.Log().Debug("This is a test."); + IEnableLogger logger = null!; + 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()); - } - finally - { - Locator.InternalLocator = originalLocator; - } + Assert.Equal(1, target.Logs.Count); + Assert.Equal("This is a test.", target.Logs.Last().message!.Trim(NewLine).Trim()); } + finally + { + Locator.InternalLocator = originalLocator; + } + } - /// - /// Test to make calling `UseSerilogWithWrappingFullLogger(Serilog.ILogger)` logs. - /// - [Fact] - public void Configuring_With_PreConfigured_Log_Should_Write_Message() + /// + /// Test to make calling `UseSerilogWithWrappingFullLogger(Serilog.ILogger)` logs. + /// + [Fact] + public void Configuring_With_PreConfigured_Log_Should_Write_Message() + { + var originalLocator = Locator.InternalLocator; + try { - var originalLocator = Locator.InternalLocator; - try - { - Locator.InternalLocator = new InternalLocator(); - var (seriLogger, target) = CreateSerilogger(LogLevel.Debug); - Locator.CurrentMutable.UseSerilogFullLogger(seriLogger); + Locator.InternalLocator = new InternalLocator(); + var (seriLogger, target) = CreateSerilogger(LogLevel.Debug); + Locator.CurrentMutable.UseSerilogFullLogger(seriLogger); - Assert.Equal(0, target.Logs.Count); + Assert.Equal(0, target.Logs.Count); - IEnableLogger logger = null!; + IEnableLogger logger = null!; - logger.Log().Debug("This is a test."); + 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()); - } - finally - { - Locator.InternalLocator = originalLocator; - } + Assert.Equal(1, target.Logs.Count); + Assert.Equal("This is a test.", target.Logs.Last().message!.Trim(NewLine).Trim()); } - - /// - protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) + finally { - var (log, messages) = CreateSerilogger(minimumLogLevel); - return (new SerilogFullLogger(log), messages); + Locator.InternalLocator = originalLocator; } + } - private static (Logger logger, IMockLogTarget mockTarget) CreateSerilogger(LogLevel minimumLogLevel) - { - var messages = new LogTarget(); - - var log = new LoggerConfiguration() - .Enrich - .WithExceptionDetails() - .MinimumLevel - .Is(_mappingsToSerilog[minimumLogLevel]) - .WriteTo - .Sink(messages) - .CreateLogger(); - - return (log, messages); - } + /// + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) + { + var (log, messages) = CreateSerilogger(minimumLogLevel); + return (new SerilogFullLogger(log), messages); + } - private class LogTarget : ILogEventSink, IMockLogTarget - { - private static readonly MessageTemplateTextFormatter _formatter = new("{Message} {Exception}", CultureInfo.InvariantCulture); - private readonly List<(LogLevel logLevel, string message)> _logs = new(); + private static (Logger logger, IMockLogTarget mockTarget) CreateSerilogger(LogLevel minimumLogLevel) + { + var messages = new LogTarget(); + + var log = new LoggerConfiguration() + .Enrich + .WithExceptionDetails() + .MinimumLevel + .Is(_mappingsToSerilog[minimumLogLevel]) + .WriteTo + .Sink(messages) + .CreateLogger(); + + return (log, messages); + } - public ICollection<(LogLevel logLevel, string message)> Logs => _logs; + private class LogTarget : ILogEventSink, IMockLogTarget + { + private static readonly MessageTemplateTextFormatter _formatter = new("{Message} {Exception}", CultureInfo.InvariantCulture); + private readonly List<(LogLevel logLevel, string message)> _logs = new(); + + public ICollection<(LogLevel logLevel, string message)> Logs => _logs; - public void Emit(LogEvent logEvent) + public void Emit(LogEvent logEvent) + { + using (var buffer = new StringWriter()) { - using (var buffer = new StringWriter()) - { - var logLevel = _mappingsToSplat[logEvent.Level]; - _formatter.Format(logEvent, buffer); - var message = buffer.ToString(); - - _logs.Add((logLevel, message)); - } + var logLevel = _mappingsToSplat[logEvent.Level]; + _formatter.Format(logEvent, buffer); + var message = buffer.ToString(); + + _logs.Add((logLevel, message)); } } } diff --git a/src/Splat.Tests/Logging/Helpers/FormatHelper.cs b/src/Splat.Tests/Logging/Helpers/FormatHelper.cs index e6a3990a3..81772a7cd 100644 --- a/src/Splat.Tests/Logging/Helpers/FormatHelper.cs +++ b/src/Splat.Tests/Logging/Helpers/FormatHelper.cs @@ -5,22 +5,21 @@ using System; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Contains help with formatting. +/// +[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "Deliberate Usage")] +public static class FormatHelper { /// - /// Contains help with formatting. + /// A constant for the new lines. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "Deliberate Usage")] - public static class FormatHelper - { - /// - /// A constant for the new lines. - /// - internal static readonly char[] NewLine = Environment.NewLine.ToCharArray(); + internal static readonly char[] NewLine = Environment.NewLine.ToCharArray(); - /// - /// Gets an exception for testing. - /// - internal static Exception Exception => new(); - } + /// + /// Gets an exception for testing. + /// + internal static Exception Exception => new(); } diff --git a/src/Splat.Tests/Logging/StaticLoggerTests.cs b/src/Splat.Tests/Logging/StaticLoggerTests.cs index b212f9927..b00654585 100644 --- a/src/Splat.Tests/Logging/StaticLoggerTests.cs +++ b/src/Splat.Tests/Logging/StaticLoggerTests.cs @@ -5,459 +5,458 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Unit Tests for the Static Logging wrapper implementation. +/// +[ExcludeFromCodeCoverage] +public sealed class StaticLoggerTests { + private static char[] NewLine => Environment.NewLine.ToCharArray(); + + /// + /// Unit tests focusing on the debug logging in the static logger. + /// + public class DebugStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() + { + return LogLevel.Debug; + } + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() + { + return (logger, message) => logger.Debug(message); + } + + /// + protected override Action GetMethodToWriteMessage() + { + return (logger, s) => logger.Debug(s); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() + { + return (logger, formatProvider, message, arg1) => logger.Debug(formatProvider, message, arg1); + } + + /// + protected override Action GetMethodToWriteExceptionAndMessage() + { + return (logger, exception, message) => logger.Debug(exception, message); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2) => logger.Debug(formatProvider, message, arg1, arg2); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Debug(formatProvider, message, arg1, arg2, arg3); + } + } + + /// + /// Unit tests focusing on the info logging in the static logger. + /// + public class InfoStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() + { + return LogLevel.Info; + } + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() + { + return (logger, message) => logger.Info(message); + } + + /// + protected override Action GetMethodToWriteMessage() + { + return (logger, s) => logger.Info(s); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() + { + return (logger, formatProvider, message, arg1) => logger.Info(formatProvider, message, arg1); + } + + /// + protected override Action GetMethodToWriteExceptionAndMessage() + { + return (logger, exception, message) => logger.Info(exception, message); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2) => logger.Info(formatProvider, message, arg1, arg2); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Info(formatProvider, message, arg1, arg2, arg3); + } + } + + /// + /// Unit tests focusing on the warning logging in the static logger. + /// + public class WarningStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() + { + return LogLevel.Warn; + } + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() + { + return (logger, message) => logger.Warn(message); + } + + /// + protected override Action GetMethodToWriteMessage() + { + return (logger, s) => logger.Warn(s); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() + { + return (logger, formatProvider, message, arg1) => logger.Warn(formatProvider, message, arg1); + } + + /// + protected override Action GetMethodToWriteExceptionAndMessage() + { + return (logger, exception, message) => logger.Warn(exception, message); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2) => logger.Warn(formatProvider, message, arg1, arg2); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Warn(formatProvider, message, arg1, arg2, arg3); + } + } + /// - /// Unit Tests for the Static Logging wrapper implementation. + /// Unit tests focusing on the error logging in the static logger. /// - [ExcludeFromCodeCoverage] - public sealed class StaticLoggerTests + public class ErrorStaticLoggerTests : BaseStaticLoggerTests { - private static char[] NewLine => Environment.NewLine.ToCharArray(); + /// + protected override LogLevel GetLogLevel() + { + return LogLevel.Error; + } + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() + { + return (logger, message) => logger.Error(message); + } + + /// + protected override Action GetMethodToWriteMessage() + { + return (logger, s) => logger.Error(s); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() + { + return (logger, formatProvider, message, arg1) => logger.Error(formatProvider, message, arg1); + } + /// + protected override Action GetMethodToWriteExceptionAndMessage() + { + return (logger, exception, message) => logger.Error(exception, message); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2) => logger.Error(formatProvider, message, arg1, arg2); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Error(formatProvider, message, arg1, arg2, arg3); + } + } + + /// + /// Unit tests focusing on the fatal logging in the static logger. + /// + public class FatalStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() + { + return LogLevel.Fatal; + } + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() + { + return (logger, message) => logger.Fatal(message); + } + + /// + protected override Action GetMethodToWriteMessage() + { + return (logger, s) => logger.Fatal(s); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() + { + return (logger, formatProvider, message, arg1) => logger.Fatal(formatProvider, message, arg1); + } + + /// + protected override Action GetMethodToWriteExceptionAndMessage() + { + return (logger, exception, message) => logger.Fatal(exception, message); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2) => logger.Fatal(formatProvider, message, arg1, arg2); + } + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() + { + return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Fatal(formatProvider, message, arg1, arg2, arg3); + } + } + + /// + /// Base tests for the static logger. + /// + public abstract class BaseStaticLoggerTests + { /// - /// Unit tests focusing on the debug logging in the static logger. + /// Test to make sure the generic type parameter is passed to the logger. /// - public class DebugStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() - { - return LogLevel.Debug; - } - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() - { - return (logger, message) => logger.Debug(message); - } - - /// - protected override Action GetMethodToWriteMessage() - { - return (logger, s) => logger.Debug(s); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() - { - return (logger, formatProvider, message, arg1) => logger.Debug(formatProvider, message, arg1); - } - - /// - protected override Action GetMethodToWriteExceptionAndMessage() - { - return (logger, exception, message) => logger.Debug(exception, message); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2) => logger.Debug(formatProvider, message, arg1, arg2); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Debug(formatProvider, message, arg1, arg2, arg3); - } + [Fact] + public void Method_With_Generic_Type_Should_Write_Message_And_Type() + { + var textLogger = new TextLogger { Level = GetLogLevel() }; + var logger = GetLogger(textLogger); + + GetMethodWithGenericTypeShouldWriteMessageAndType()(logger, "This is a test."); + + Assert.Equal($"This is a test. ({nameof(GetMethodWithGenericTypeShouldWriteMessageAndType)})", textLogger.Logs.Last().message.Trim(NewLine).Trim()); } /// - /// Unit tests focusing on the info logging in the static logger. + /// Test to make sure the generic type parameter is passed to the logger. /// - public class InfoStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() - { - return LogLevel.Info; - } - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() - { - return (logger, message) => logger.Info(message); - } - - /// - protected override Action GetMethodToWriteMessage() - { - return (logger, s) => logger.Info(s); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() - { - return (logger, formatProvider, message, arg1) => logger.Info(formatProvider, message, arg1); - } - - /// - protected override Action GetMethodToWriteExceptionAndMessage() - { - return (logger, exception, message) => logger.Info(exception, message); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2) => logger.Info(formatProvider, message, arg1, arg2); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Info(formatProvider, message, arg1, arg2, arg3); - } + [Fact] + public void Method_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var textLogger = new TextLogger { Level = GetLogLevel() }; + var logger = GetLogger(textLogger); + + GetMethodWithGenericTypeShouldWriteMessageAndType()(logger, "This is a test."); + + Assert.Equal($"This is a test. ({nameof(GetMethodWithGenericTypeShouldWriteMessageAndType)})", textLogger.Logs.Last().message.Trim(NewLine).Trim()); } /// - /// Unit tests focusing on the warning logging in the static logger. + /// Test to ensure debug writes. /// - public class WarningStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() - { - return LogLevel.Warn; - } - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() - { - return (logger, message) => logger.Warn(message); - } - - /// - protected override Action GetMethodToWriteMessage() - { - return (logger, s) => logger.Warn(s); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() - { - return (logger, formatProvider, message, arg1) => logger.Warn(formatProvider, message, arg1); - } - - /// - protected override Action GetMethodToWriteExceptionAndMessage() - { - return (logger, exception, message) => logger.Warn(exception, message); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2) => logger.Warn(formatProvider, message, arg1, arg2); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Warn(formatProvider, message, arg1, arg2, arg3); - } + [Fact] + public void Method_Writes_Message() + { + Test_Write_Message(logger => GetMethodToWriteMessage()(logger, "Message")); } /// - /// Unit tests focusing on the error logging in the static logger. + /// Test to ensure invariant culture formatted string writes. /// - public class ErrorStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() - { - return LogLevel.Error; - } - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() - { - return (logger, message) => logger.Error(message); - } - - /// - protected override Action GetMethodToWriteMessage() - { - return (logger, s) => logger.Error(s); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() - { - return (logger, formatProvider, message, arg1) => logger.Error(formatProvider, message, arg1); - } - - /// - protected override Action GetMethodToWriteExceptionAndMessage() - { - return (logger, exception, message) => logger.Error(exception, message); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2) => logger.Error(formatProvider, message, arg1, arg2); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Error(formatProvider, message, arg1, arg2, arg3); - } + [Fact] + public void Method_Writes_Message_InvariantCulture() + { + Test_Write_Message(logger => GetMethodToWriteMessageWithInvariantCulture()(logger, CultureInfo.InvariantCulture, "{0}", "Message")); } /// - /// Unit tests focusing on the fatal logging in the static logger. + /// Test to ensure invariant culture formatted string writes. /// - public class FatalStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() - { - return LogLevel.Fatal; - } - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() - { - return (logger, message) => logger.Fatal(message); - } - - /// - protected override Action GetMethodToWriteMessage() - { - return (logger, s) => logger.Fatal(s); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() - { - return (logger, formatProvider, message, arg1) => logger.Fatal(formatProvider, message, arg1); - } - - /// - protected override Action GetMethodToWriteExceptionAndMessage() - { - return (logger, exception, message) => logger.Fatal(exception, message); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2) => logger.Fatal(formatProvider, message, arg1, arg2); - } - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() - { - return (logger, formatProvider, message, arg1, arg2, arg3) => logger.Fatal(formatProvider, message, arg1, arg2, arg3); - } + [Fact] + public void Method_Writes_Message_InvariantCulture_With_Generic_Two_Args() + { + Test_Write_Message(logger => GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs()(logger, CultureInfo.InvariantCulture, "{0}", "Message", 1)); + } + + /// + /// Test to ensure invariant culture formatted string writes. + /// + [Fact] + public void Method_Writes_Message_InvariantCulture_With_Generic_Three_Args() + { + Test_Write_Message(logger => GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs()(logger, CultureInfo.InvariantCulture, "{0}", "Message", 1, 2.3f)); + } + + /// + /// Test to ensure debug writes. + /// + [Fact] + public void Method_Writes_Exception_And_Message() + { + var staticLogger = GetLogger(GetLogLevel()); + GetMethodToWriteExceptionAndMessage()(staticLogger, new ArgumentException("TEST"), "Message"); + } + + /// + /// Test to ensure writes method works. + /// + [Fact] + public void Direct_Write_At_Level_Message() + { + var staticLogger = GetLogger(GetLogLevel()); + staticLogger.Write("Message", GetLogLevel()); } /// - /// Base tests for the static logger. + /// Test to ensure writes method works. /// - public abstract class BaseStaticLoggerTests - { - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Method_With_Generic_Type_Should_Write_Message_And_Type() - { - var textLogger = new TextLogger { Level = GetLogLevel() }; - var logger = GetLogger(textLogger); - - GetMethodWithGenericTypeShouldWriteMessageAndType()(logger, "This is a test."); - - Assert.Equal($"This is a test. ({nameof(GetMethodWithGenericTypeShouldWriteMessageAndType)})", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Method_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var textLogger = new TextLogger { Level = GetLogLevel() }; - var logger = GetLogger(textLogger); - - GetMethodWithGenericTypeShouldWriteMessageAndType()(logger, "This is a test."); - - Assert.Equal($"This is a test. ({nameof(GetMethodWithGenericTypeShouldWriteMessageAndType)})", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to ensure debug writes. - /// - [Fact] - public void Method_Writes_Message() - { - Test_Write_Message(logger => GetMethodToWriteMessage()(logger, "Message")); - } - - /// - /// Test to ensure invariant culture formatted string writes. - /// - [Fact] - public void Method_Writes_Message_InvariantCulture() - { - Test_Write_Message(logger => GetMethodToWriteMessageWithInvariantCulture()(logger, CultureInfo.InvariantCulture, "{0}", "Message")); - } - - /// - /// Test to ensure invariant culture formatted string writes. - /// - [Fact] - public void Method_Writes_Message_InvariantCulture_With_Generic_Two_Args() - { - Test_Write_Message(logger => GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs()(logger, CultureInfo.InvariantCulture, "{0}", "Message", 1)); - } - - /// - /// Test to ensure invariant culture formatted string writes. - /// - [Fact] - public void Method_Writes_Message_InvariantCulture_With_Generic_Three_Args() - { - Test_Write_Message(logger => GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs()(logger, CultureInfo.InvariantCulture, "{0}", "Message", 1, 2.3f)); - } - - /// - /// Test to ensure debug writes. - /// - [Fact] - public void Method_Writes_Exception_And_Message() - { - var staticLogger = GetLogger(GetLogLevel()); - GetMethodToWriteExceptionAndMessage()(staticLogger, new ArgumentException("TEST"), "Message"); - } - - /// - /// Test to ensure writes method works. - /// - [Fact] - public void Direct_Write_At_Level_Message() - { - var staticLogger = GetLogger(GetLogLevel()); - staticLogger.Write("Message", GetLogLevel()); - } - - /// - /// Test to ensure writes method works. - /// - [Fact] - public void Direct_Write_At_Level_Message_And_Type() - { - var staticLogger = GetLogger(GetLogLevel()); - staticLogger.Write("Message", typeof(DummyObjectClass1), GetLogLevel()); - } - - /// - /// Test to ensure writes method works. - /// - [Fact] - public void Direct_Write_At_Level_Message_And_Exception() - { - var staticLogger = GetLogger(GetLogLevel()); - var exception = new InvalidOperationException("bleh"); - staticLogger.Write(exception, "Message", GetLogLevel()); - } - - /// - /// Test to ensure writes method works. - /// - [Fact] - public void Direct_Write_At_Level_Message_Exception_And_Type() - { - var staticLogger = GetLogger(GetLogLevel()); - var exception = new InvalidOperationException("bleh"); - staticLogger.Write(exception, "Message", typeof(DummyObjectClass1), GetLogLevel()); - } - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Logger_Level_AtBoundary_Should_Be_correct() - { - var level = GetLogLevel(); - var logger = GetLogger(level); - - Assert.Equal(level, logger.Level); - } - - /// - /// Gets the logger action for Write with a generic type. - /// - /// The generic type to log. - /// Action to call. - protected abstract Action GetMethodWithGenericTypeShouldWriteMessageAndType(); - - /// - /// Gets the logger action for Writing a string message. - /// - /// Action to call. - protected abstract Action GetMethodToWriteMessage(); - - /// - /// Gets the logger action for Writing a string message. - /// - /// Action to call. - protected abstract Action GetMethodToWriteMessageWithInvariantCulture(); - - /// - /// Gets the logger action for Writing a string message. - /// - /// Action to call. - protected abstract Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs(); - - /// - /// Gets the logger action for Writing a string message. - /// - /// Action to call. - protected abstract Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs(); - - /// - /// Gets the logger action for Writing an exception and string message. - /// - /// Action to call. - protected abstract Action GetMethodToWriteExceptionAndMessage(); - - /// - /// Gets the log level boundary for the test. - /// - /// Log Level. - protected abstract Splat.LogLevel GetLogLevel(); - - private static StaticFullLogger GetLogger(TextLogger textLogger) => new(new WrappingFullLogger(textLogger)); - - private static StaticFullLogger GetLogger(LogLevel logLevel) - { - var textLogger = new TextLogger(); - textLogger.Level = logLevel; - - var wrappingFullLogger = new WrappingFullLogger(textLogger); - return new StaticFullLogger(wrappingFullLogger); - } - - private static void Test_Write_Message(Action testMethodFunc) - { - var textLogger = new TextLogger(); - Assert.Equal(0, textLogger.Logs.Count); - var staticLogger = GetLogger(textLogger); - - testMethodFunc(staticLogger); - Assert.Equal(1, textLogger.Logs.Count); - var line = textLogger.Logs.First(); - - var startOfCallerMemberSuffix = line.message.IndexOf("(", StringComparison.Ordinal); - Assert.True(startOfCallerMemberSuffix > 0); - - var endOfCallerMemberSuffix = line.message.IndexOf(")", startOfCallerMemberSuffix, StringComparison.Ordinal); - Assert.True(endOfCallerMemberSuffix > startOfCallerMemberSuffix + 1); - } + [Fact] + public void Direct_Write_At_Level_Message_And_Type() + { + var staticLogger = GetLogger(GetLogLevel()); + staticLogger.Write("Message", typeof(DummyObjectClass1), GetLogLevel()); + } + + /// + /// Test to ensure writes method works. + /// + [Fact] + public void Direct_Write_At_Level_Message_And_Exception() + { + var staticLogger = GetLogger(GetLogLevel()); + var exception = new InvalidOperationException("bleh"); + staticLogger.Write(exception, "Message", GetLogLevel()); + } + + /// + /// Test to ensure writes method works. + /// + [Fact] + public void Direct_Write_At_Level_Message_Exception_And_Type() + { + var staticLogger = GetLogger(GetLogLevel()); + var exception = new InvalidOperationException("bleh"); + staticLogger.Write(exception, "Message", typeof(DummyObjectClass1), GetLogLevel()); + } + + /// + /// Test to make sure the message writes. + /// + [Fact] + public void Logger_Level_AtBoundary_Should_Be_correct() + { + var level = GetLogLevel(); + var logger = GetLogger(level); + + Assert.Equal(level, logger.Level); + } + + /// + /// Gets the logger action for Write with a generic type. + /// + /// The generic type to log. + /// Action to call. + protected abstract Action GetMethodWithGenericTypeShouldWriteMessageAndType(); + + /// + /// Gets the logger action for Writing a string message. + /// + /// Action to call. + protected abstract Action GetMethodToWriteMessage(); + + /// + /// Gets the logger action for Writing a string message. + /// + /// Action to call. + protected abstract Action GetMethodToWriteMessageWithInvariantCulture(); + + /// + /// Gets the logger action for Writing a string message. + /// + /// Action to call. + protected abstract Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs(); + + /// + /// Gets the logger action for Writing a string message. + /// + /// Action to call. + protected abstract Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs(); + + /// + /// Gets the logger action for Writing an exception and string message. + /// + /// Action to call. + protected abstract Action GetMethodToWriteExceptionAndMessage(); + + /// + /// Gets the log level boundary for the test. + /// + /// Log Level. + protected abstract Splat.LogLevel GetLogLevel(); + + private static StaticFullLogger GetLogger(TextLogger textLogger) => new(new WrappingFullLogger(textLogger)); + + private static StaticFullLogger GetLogger(LogLevel logLevel) + { + var textLogger = new TextLogger(); + textLogger.Level = logLevel; + + var wrappingFullLogger = new WrappingFullLogger(textLogger); + return new StaticFullLogger(wrappingFullLogger); + } + + private static void Test_Write_Message(Action testMethodFunc) + { + var textLogger = new TextLogger(); + Assert.Equal(0, textLogger.Logs.Count); + var staticLogger = GetLogger(textLogger); + + testMethodFunc(staticLogger); + Assert.Equal(1, textLogger.Logs.Count); + var line = textLogger.Logs.First(); + + var startOfCallerMemberSuffix = line.message.IndexOf("(", StringComparison.Ordinal); + Assert.True(startOfCallerMemberSuffix > 0); + + var endOfCallerMemberSuffix = line.message.IndexOf(")", startOfCallerMemberSuffix, StringComparison.Ordinal); + Assert.True(endOfCallerMemberSuffix > startOfCallerMemberSuffix + 1); } } } diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs index 5c56a0358..4eb477179 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs @@ -4,45 +4,42 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Reflection; using System.Text; + using Splat.Tests.Mocks; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests that verify the class. +/// +public class ConsoleLoggerTests : FullLoggerTestBase { - /// - /// Tests that verify the class. - /// - public class ConsoleLoggerTests : FullLoggerTestBase + /// + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) { - /// - protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) - { - var outputWriter = new ConsoleWriter(); - Console.SetOut(outputWriter); - return (new WrappingFullLogger(new WrappingLogLevelLogger(new ConsoleLogger { Level = minimumLogLevel, ExceptionMessageFormat = "{0} {1}" })), outputWriter); - } + var outputWriter = new ConsoleWriter(); + Console.SetOut(outputWriter); + return (new WrappingFullLogger(new WrappingLogLevelLogger(new ConsoleLogger { Level = minimumLogLevel, ExceptionMessageFormat = "{0} {1}" })), outputWriter); + } - private class ConsoleWriter : TextWriter, IMockLogTarget - { - private readonly List<(LogLevel logLevel, string message)> _logs = new(); + private class ConsoleWriter : TextWriter, IMockLogTarget + { + private readonly List<(LogLevel logLevel, string message)> _logs = new(); - public override Encoding Encoding => Encoding.UTF8; + public override Encoding Encoding => Encoding.UTF8; - public ICollection<(LogLevel logLevel, string message)> Logs => _logs; + public ICollection<(LogLevel logLevel, string message)> Logs => _logs; - public override void WriteLine(string? value) - { - 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)); - base.WriteLine(value); - } + public override void WriteLine(string? value) + { + 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)); + base.WriteLine(value); } } } diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs index dc0e30f67..3fb6dab72 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/ExceptionlessLoggerTests.cs @@ -7,89 +7,88 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; + using Exceptionless; using Exceptionless.Models; using Exceptionless.Plugins; + using Splat.Exceptionless; using Splat.Tests.Mocks; -namespace Splat.Tests.Logging.WrappingFullLoggers +namespace Splat.Tests.Logging.WrappingFullLoggers; + +/// +/// Unit tests for the Exceptionless Logger. +/// +public class ExceptionlessLoggerTests : FullLoggerTestBase { - /// - /// Unit tests for the Exceptionless Logger. - /// - public class ExceptionlessLoggerTests : FullLoggerTestBase + private static readonly Dictionary _exceptionless2Splat = new() { - private static readonly Dictionary _exceptionless2Splat = new() - { - { global::Exceptionless.Logging.LogLevel.Debug, LogLevel.Debug }, - { global::Exceptionless.Logging.LogLevel.Info, LogLevel.Info }, - { global::Exceptionless.Logging.LogLevel.Warn, LogLevel.Warn }, - { global::Exceptionless.Logging.LogLevel.Error, LogLevel.Error }, - { global::Exceptionless.Logging.LogLevel.Fatal, LogLevel.Fatal }, - }; - - private static readonly Dictionary _splat2Exceptionless = new() - { - { LogLevel.Debug, global::Exceptionless.Logging.LogLevel.Debug }, - { LogLevel.Info, global::Exceptionless.Logging.LogLevel.Info }, - { LogLevel.Warn, global::Exceptionless.Logging.LogLevel.Warn }, - { LogLevel.Error, global::Exceptionless.Logging.LogLevel.Error }, - { LogLevel.Fatal, global::Exceptionless.Logging.LogLevel.Fatal }, - }; - - /// - protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) - { - var logTarget = new InMemoryExceptionlessLogTarget(); + { global::Exceptionless.Logging.LogLevel.Debug, LogLevel.Debug }, + { global::Exceptionless.Logging.LogLevel.Info, LogLevel.Info }, + { global::Exceptionless.Logging.LogLevel.Warn, LogLevel.Warn }, + { global::Exceptionless.Logging.LogLevel.Error, LogLevel.Error }, + { global::Exceptionless.Logging.LogLevel.Fatal, LogLevel.Fatal }, + }; + + private static readonly Dictionary _splat2Exceptionless = new() + { + { LogLevel.Debug, global::Exceptionless.Logging.LogLevel.Debug }, + { LogLevel.Info, global::Exceptionless.Logging.LogLevel.Info }, + { LogLevel.Warn, global::Exceptionless.Logging.LogLevel.Warn }, + { LogLevel.Error, global::Exceptionless.Logging.LogLevel.Error }, + { LogLevel.Fatal, global::Exceptionless.Logging.LogLevel.Fatal }, + }; + + /// + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) + { + var logTarget = new InMemoryExceptionlessLogTarget(); - var exceptionlessClient = new ExceptionlessClient(); - exceptionlessClient.Configuration.ApiKey = "someapikey"; + var exceptionlessClient = new ExceptionlessClient(); + exceptionlessClient.Configuration.ApiKey = "someapikey"; - var exceptionlessMinLogLevel = _splat2Exceptionless[minimumLogLevel]; - exceptionlessClient.Configuration.UseInMemoryLogger(exceptionlessMinLogLevel); - exceptionlessClient.Configuration.SetDefaultMinLogLevel(exceptionlessMinLogLevel); - exceptionlessClient.Configuration.AddPlugin("Use Mock Log Target Interceptor", context => PluginAction(context, logTarget)); - var inner = new ExceptionlessSplatLogger(typeof(ExceptionlessLoggerTests), exceptionlessClient); - return (new WrappingFullLogger(inner), logTarget); - } + var exceptionlessMinLogLevel = _splat2Exceptionless[minimumLogLevel]; + exceptionlessClient.Configuration.UseInMemoryLogger(exceptionlessMinLogLevel); + exceptionlessClient.Configuration.SetDefaultMinLogLevel(exceptionlessMinLogLevel); + exceptionlessClient.Configuration.AddPlugin("Use Mock Log Target Interceptor", context => PluginAction(context, logTarget)); + var inner = new ExceptionlessSplatLogger(typeof(ExceptionlessLoggerTests), exceptionlessClient); + return (new WrappingFullLogger(inner), logTarget); + } - private static LogLevel GetSplatLogLevel(global::Exceptionless.Logging.LogLevel logLevel) - { - return _exceptionless2Splat[logLevel]; - } + private static LogLevel GetSplatLogLevel(global::Exceptionless.Logging.LogLevel logLevel) + { + return _exceptionless2Splat[logLevel]; + } - private static void PluginAction(EventPluginContext obj, InMemoryExceptionlessLogTarget logTarget) + private static void PluginAction(EventPluginContext obj, InMemoryExceptionlessLogTarget logTarget) + { + obj.Cancel = true; + if (!obj.Event.Type.Equals(Event.KnownTypes.Log, StringComparison.Ordinal)) { - obj.Cancel = true; - if (!obj.Event.Type.Equals(Event.KnownTypes.Log, StringComparison.Ordinal)) - { - return; - } + return; + } - var level = obj.Event.Data.GetValueOrDefault(Event.KnownDataKeys.Level) as string; + var level = obj.Event.Data.GetValueOrDefault(Event.KnownDataKeys.Level) as string; - var logLevel = global::Exceptionless.Logging.LogLevel.FromString(level!); + var logLevel = global::Exceptionless.Logging.LogLevel.FromString(level!); - var splatLogLevel = GetSplatLogLevel(logLevel); - var exception = obj.ContextData.HasException() ? obj.ContextData.GetException() : null; + var splatLogLevel = GetSplatLogLevel(logLevel); + var exception = obj.ContextData.HasException() ? obj.ContextData.GetException() : null; - var exceptionMessageSuffix = exception is not null ? $" {exception}" : string.Empty; - (LogLevel logLevel, string message) tuple = (splatLogLevel, $"{obj.Event.Message}{exceptionMessageSuffix}"); - logTarget.Logs.Add(tuple); - } + var exceptionMessageSuffix = exception is not null ? $" {exception}" : string.Empty; + (LogLevel logLevel, string message) tuple = (splatLogLevel, $"{obj.Event.Message}{exceptionMessageSuffix}"); + logTarget.Logs.Add(tuple); + } - private class InMemoryExceptionlessLogTarget : IMockLogTarget + private class InMemoryExceptionlessLogTarget : IMockLogTarget + { + public InMemoryExceptionlessLogTarget() { - public InMemoryExceptionlessLogTarget() - { - Logs = new List<(LogLevel logLevel, string message)>(); - } - - public ICollection<(LogLevel logLevel, string message)> Logs { get; } + Logs = new List<(LogLevel logLevel, string message)>(); } + + public ICollection<(LogLevel logLevel, string message)> Logs { get; } } } diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs index 84feaba19..74b6a6de0 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs @@ -4,10 +4,8 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Reflection; using log4net; using log4net.Core; @@ -17,98 +15,97 @@ using Splat.Log4Net; using Splat.Tests.Mocks; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests that verify the class. +/// +public class Log4NetLoggerTests : FullLoggerTestBase { - /// - /// Tests that verify the class. - /// - public class Log4NetLoggerTests : FullLoggerTestBase + private static readonly Dictionary _log4Net2Splat = new() { - private static readonly Dictionary _log4Net2Splat = new() - { - { Level.Debug, LogLevel.Debug }, - { Level.Info, LogLevel.Info }, - { Level.Warn, LogLevel.Warn }, - { Level.Error, LogLevel.Error }, - { Level.Fatal, LogLevel.Fatal }, - }; - - private static readonly Dictionary _splat2log4net = new() - { - { LogLevel.Debug, Level.Debug }, - { LogLevel.Info, Level.Info }, - { LogLevel.Warn, Level.Warn }, - { LogLevel.Error, Level.Error }, - { LogLevel.Fatal, Level.Fatal }, - }; + { Level.Debug, LogLevel.Debug }, + { Level.Info, LogLevel.Info }, + { Level.Warn, LogLevel.Warn }, + { Level.Error, LogLevel.Error }, + { Level.Fatal, LogLevel.Fatal }, + }; + + private static readonly Dictionary _splat2log4net = new() + { + { LogLevel.Debug, Level.Debug }, + { LogLevel.Info, Level.Info }, + { LogLevel.Warn, Level.Warn }, + { LogLevel.Error, Level.Error }, + { LogLevel.Fatal, Level.Fatal }, + }; + + /// + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) + { + var logger = LogManager.GetLogger(Guid.NewGuid().ToString()); - /// - protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) - { - var logger = LogManager.GetLogger(Guid.NewGuid().ToString()); + var hierarchyLogger = (log4net.Repository.Hierarchy.Logger)logger.Logger; + hierarchyLogger.Level = _splat2log4net[minimumLogLevel]; - var hierarchyLogger = (log4net.Repository.Hierarchy.Logger)logger.Logger; - hierarchyLogger.Level = _splat2log4net[minimumLogLevel]; + return (new WrappingFullLogger(new Log4NetLogger(logger)), CreateRepository(minimumLogLevel)); + } - return (new WrappingFullLogger(new Log4NetLogger(logger)), CreateRepository(minimumLogLevel)); - } + private MemoryTargetWrapper CreateRepository(LogLevel minimumLogLevel) + { + Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(GetType().Assembly); - private MemoryTargetWrapper CreateRepository(LogLevel minimumLogLevel) + PatternLayout patternLayout = new() { - Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(GetType().Assembly); - - PatternLayout patternLayout = new() - { - ConversionPattern = "%m %exception" - }; - patternLayout.ActivateOptions(); + ConversionPattern = "%m %exception", + }; + patternLayout.ActivateOptions(); - var memoryAppender = new global::log4net.Appender.MemoryAppender + var memoryAppender = new global::log4net.Appender.MemoryAppender + { + Threshold = _splat2log4net[minimumLogLevel], + Layout = new PatternLayout { - Threshold = _splat2log4net[minimumLogLevel], - Layout = new PatternLayout - { - ConversionPattern = "%m %exception" - }, - }; + ConversionPattern = "%m %exception", + }, + }; - memoryAppender.ActivateOptions(); - var memoryWrapper = new MemoryTargetWrapper(memoryAppender); - memoryWrapper.MemoryTarget.ActivateOptions(); - hierarchy.Root.AddAppender(memoryWrapper.MemoryTarget); + memoryAppender.ActivateOptions(); + var memoryWrapper = new MemoryTargetWrapper(memoryAppender); + memoryWrapper.MemoryTarget.ActivateOptions(); + hierarchy.Root.AddAppender(memoryWrapper.MemoryTarget); - hierarchy.Root.Level = _splat2log4net[minimumLogLevel]; - hierarchy.Configured = true; + hierarchy.Root.Level = _splat2log4net[minimumLogLevel]; + hierarchy.Configured = true; - return memoryWrapper; - } + return memoryWrapper; + } - private class MemoryTargetWrapper : IMockLogTarget + private class MemoryTargetWrapper : IMockLogTarget + { + public MemoryTargetWrapper(global::log4net.Appender.MemoryAppender memoryTarget) { - public MemoryTargetWrapper(global::log4net.Appender.MemoryAppender memoryTarget) - { - MemoryTarget = memoryTarget; - } + MemoryTarget = memoryTarget; + } - public global::log4net.Appender.MemoryAppender MemoryTarget { get; } + public global::log4net.Appender.MemoryAppender MemoryTarget { get; } - public ICollection<(LogLevel logLevel, string message)> Logs + public ICollection<(LogLevel logLevel, string message)> Logs + { + get { - get + MemoryTarget.Flush(0); + return MemoryTarget.GetEvents().Select(x => { - MemoryTarget.Flush(0); - return MemoryTarget.GetEvents().Select(x => - { - var currentLevel = _log4Net2Splat[x.Level]; + var currentLevel = _log4Net2Splat[x.Level]; - if (x.ExceptionObject is not null) - { - return (currentLevel, $"{x.MessageObject} {x.ExceptionObject}"); - } + if (x.ExceptionObject is not null) + { + return (currentLevel, $"{x.MessageObject} {x.ExceptionObject}"); + } - return (currentLevel, x.MessageObject.ToString()!); - }).ToList(); - } + return (currentLevel, x.MessageObject.ToString()!); + }).ToList(); } } } diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs index b7f3f5696..7f34a464d 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs @@ -9,80 +9,79 @@ using Splat.Microsoft.Extensions.Logging; using Splat.Tests.Mocks; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests that verify the class. +/// +public class MicrosoftExtensionsLoggingLoggerTests : FullLoggerTestBase { - /// - /// Tests that verify the class. - /// - public class MicrosoftExtensionsLoggingLoggerTests : FullLoggerTestBase + private static readonly Dictionary _splat2MSLog = new() { - private static readonly Dictionary _splat2MSLog = new() - { - { LogLevel.Debug, global::Microsoft.Extensions.Logging.LogLevel.Debug }, - { LogLevel.Info, global::Microsoft.Extensions.Logging.LogLevel.Information }, - { LogLevel.Warn, global::Microsoft.Extensions.Logging.LogLevel.Warning }, - { LogLevel.Error, global::Microsoft.Extensions.Logging.LogLevel.Error }, - { LogLevel.Fatal, global::Microsoft.Extensions.Logging.LogLevel.Critical } - }; + { LogLevel.Debug, global::Microsoft.Extensions.Logging.LogLevel.Debug }, + { LogLevel.Info, global::Microsoft.Extensions.Logging.LogLevel.Information }, + { LogLevel.Warn, global::Microsoft.Extensions.Logging.LogLevel.Warning }, + { LogLevel.Error, global::Microsoft.Extensions.Logging.LogLevel.Error }, + { LogLevel.Fatal, global::Microsoft.Extensions.Logging.LogLevel.Critical }, + }; - private static readonly Dictionary _MSLog2Splat = new() - { - { global::Microsoft.Extensions.Logging.LogLevel.Debug, LogLevel.Debug }, - { global::Microsoft.Extensions.Logging.LogLevel.Information, LogLevel.Info }, - { global::Microsoft.Extensions.Logging.LogLevel.Warning, LogLevel.Warn }, - { global::Microsoft.Extensions.Logging.LogLevel.Error, LogLevel.Error }, - { global::Microsoft.Extensions.Logging.LogLevel.Critical, LogLevel.Fatal } - }; + private static readonly Dictionary _MSLog2Splat = new() + { + { global::Microsoft.Extensions.Logging.LogLevel.Debug, LogLevel.Debug }, + { global::Microsoft.Extensions.Logging.LogLevel.Information, LogLevel.Info }, + { global::Microsoft.Extensions.Logging.LogLevel.Warning, LogLevel.Warn }, + { global::Microsoft.Extensions.Logging.LogLevel.Error, LogLevel.Error }, + { global::Microsoft.Extensions.Logging.LogLevel.Critical, LogLevel.Fatal }, + }; - /// - protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) - { - var mockLogger = new MockActualMicrosoftExtensionsLoggingLogger(_splat2MSLog[minimumLogLevel]); + /// + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) + { + var mockLogger = new MockActualMicrosoftExtensionsLoggingLogger(_splat2MSLog[minimumLogLevel]); - return (new WrappingFullLogger(new MicrosoftExtensionsLoggingLogger(mockLogger)), mockLogger); - } + return (new WrappingFullLogger(new MicrosoftExtensionsLoggingLogger(mockLogger)), mockLogger); + } - /// - /// Mock Logger for Testing Microsoft.Extensions.Logging. - /// - private sealed class MockActualMicrosoftExtensionsLoggingLogger : global::Microsoft.Extensions.Logging.ILogger, IMockLogTarget - { - private readonly List<(LogLevel, string)> _logs = new(); - private readonly global::Microsoft.Extensions.Logging.LogLevel _logLevel; + /// + /// Mock Logger for Testing Microsoft.Extensions.Logging. + /// + private sealed class MockActualMicrosoftExtensionsLoggingLogger : global::Microsoft.Extensions.Logging.ILogger, IMockLogTarget + { + private readonly List<(LogLevel, string)> _logs = new(); + private readonly global::Microsoft.Extensions.Logging.LogLevel _logLevel; - public MockActualMicrosoftExtensionsLoggingLogger(global::Microsoft.Extensions.Logging.LogLevel logLevel) - { - _logLevel = logLevel; - } + public MockActualMicrosoftExtensionsLoggingLogger(global::Microsoft.Extensions.Logging.LogLevel logLevel) + { + _logLevel = logLevel; + } - public ICollection<(LogLevel logLevel, string message)> Logs => _logs; + public ICollection<(LogLevel logLevel, string message)> Logs => _logs; - /// - public void Log( - global::Microsoft.Extensions.Logging.LogLevel logLevel, - EventId eventId, - TState state, - Exception? exception, - Func formatter) + /// + public void Log( + global::Microsoft.Extensions.Logging.LogLevel logLevel, + EventId eventId, + TState state, + Exception? exception, + Func formatter) + { + if (IsEnabled(logLevel)) { - if (IsEnabled(logLevel)) - { - _logs.Add((_MSLog2Splat[logLevel], $"{state} {exception}")); - } + _logs.Add((_MSLog2Splat[logLevel], $"{state} {exception}")); } + } - /// - public bool IsEnabled(global::Microsoft.Extensions.Logging.LogLevel logLevel) - { - return logLevel >= _logLevel; - } + /// + public bool IsEnabled(global::Microsoft.Extensions.Logging.LogLevel logLevel) + { + return logLevel >= _logLevel; + } - /// - public IDisposable BeginScope(TState state) - where TState : notnull - { - return ActionDisposable.Empty; - } + /// + public IDisposable BeginScope(TState state) + where TState : notnull + { + return ActionDisposable.Empty; } } } diff --git a/src/Splat.Tests/Logging/WrappingPrefixLoggerTests.cs b/src/Splat.Tests/Logging/WrappingPrefixLoggerTests.cs index 910d04a6a..69f10bf30 100644 --- a/src/Splat.Tests/Logging/WrappingPrefixLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingPrefixLoggerTests.cs @@ -8,181 +8,180 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests.Logging +namespace Splat.Tests.Logging; + +/// +/// Tests the class. +/// +public class WrappingPrefixLoggerTests { + private static char[] NewLine => Environment.NewLine.ToCharArray(); + /// - /// Tests the class. + /// Test to make sure the message writes. /// - public class WrappingPrefixLoggerTests + [Fact] + public void Write_Should_Write_Message() { - private static char[] NewLine => Environment.NewLine.ToCharArray(); - - /// - /// Test to make sure the message writes. - /// - [Fact] - public void Write_Should_Write_Message() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Write("This is a test.", LogLevel.Debug); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the type parameter is passed to the logger. - /// - [Fact] - public void Write_Should_Write_Message_And_Type() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Write("This is a test.", typeof(DummyObjectClass1), LogLevel.Debug); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Write_Message_And_Type() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Debug("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Debug_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Debug("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Write_Message_And_Type() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Info("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Info_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Info("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Write_Message_And_Type() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Warn("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Warn("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Write_Message_And_Type() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Error("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Error_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Error("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Write_Message_And_Type() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Fatal("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } - - /// - /// Test to make sure the generic type parameter is passed to the logger. - /// - [Fact] - public void Fatal_With_Generic_Type_Should_Write_Message_And_Type_Provided() - { - var textLogger = new TextLogger(); - var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); - - logger.Fatal("This is a test."); - - Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); - } + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Write("This is a test.", LogLevel.Debug); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the type parameter is passed to the logger. + /// + [Fact] + public void Write_Should_Write_Message_And_Type() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Write("This is a test.", typeof(DummyObjectClass1), LogLevel.Debug); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Write_Message_And_Type() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Debug("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Debug_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Debug("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Info_With_Generic_Type_Should_Write_Message_And_Type() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Info("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Info_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Info("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Write_Message_And_Type() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Warn("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Warn("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Write_Message_And_Type() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Error("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Error_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Error("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Fatal_With_Generic_Type_Should_Write_Message_And_Type() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Fatal("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); + } + + /// + /// Test to make sure the generic type parameter is passed to the logger. + /// + [Fact] + public void Fatal_With_Generic_Type_Should_Write_Message_And_Type_Provided() + { + var textLogger = new TextLogger(); + var logger = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1))); + + logger.Fatal("This is a test."); + + Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim()); } } diff --git a/src/Splat.Tests/MemoizingMRUCacheTests.cs b/src/Splat.Tests/MemoizingMRUCacheTests.cs index 712eedac6..f75dacc8c 100644 --- a/src/Splat.Tests/MemoizingMRUCacheTests.cs +++ b/src/Splat.Tests/MemoizingMRUCacheTests.cs @@ -8,226 +8,225 @@ using Splat.Tests.Mocks; using Xunit; -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Unit Tests for the Memoizing MRU Cache. +/// +public class MemoizingMRUCacheTests { /// - /// Unit Tests for the Memoizing MRU Cache. + /// Checks to ensure an Argument Null Exception is thrown. /// - public class MemoizingMRUCacheTests + [Fact] + public void ThrowsArgumentNullException() { - /// - /// Checks to ensure an Argument Null Exception is thrown. - /// - [Fact] - public void ThrowsArgumentNullException() - { - var instance = GetTestInstance(); - Assert.Throws(() => instance.Get(null!)); - } + var instance = GetTestInstance(); + Assert.Throws(() => instance.Get(null!)); + } - /// - /// Checks to ensure a value is returned. - /// - [Fact] - public void ReturnsValue() - { - var instance = GetTestInstance(); - var result = instance.Get("Test1"); - Assert.NotNull(result); - } + /// + /// Checks to ensure a value is returned. + /// + [Fact] + public void ReturnsValue() + { + var instance = GetTestInstance(); + var result = instance.Get("Test1"); + Assert.NotNull(result); + } - /// - /// Checks to ensure a value is returned for 2 duplicate calls. - /// - [Fact] - public void GetReturnsSameValue() - { - var instance = GetTestInstance(); - var result1 = instance.Get("Test1"); - Assert.NotNull(result1); - var result2 = instance.Get("Test1"); - Assert.NotNull(result2); - Assert.Same(result1, result2); - } + /// + /// Checks to ensure a value is returned for 2 duplicate calls. + /// + [Fact] + public void GetReturnsSameValue() + { + var instance = GetTestInstance(); + var result1 = instance.Get("Test1"); + Assert.NotNull(result1); + var result2 = instance.Get("Test1"); + Assert.NotNull(result2); + Assert.Same(result1, result2); + } - /// - /// Checks to ensure 2 different values are returned for 2 different calls. - /// - [Fact] - public void GetReturnsDifferentValues() - { - var instance = GetTestInstance(); - var result1 = instance.Get("Test1"); - Assert.NotNull(result1); - var result2 = instance.Get("Test2"); - Assert.NotNull(result2); - Assert.NotSame(result1, result2); - } + /// + /// Checks to ensure 2 different values are returned for 2 different calls. + /// + [Fact] + public void GetReturnsDifferentValues() + { + var instance = GetTestInstance(); + var result1 = instance.Get("Test1"); + Assert.NotNull(result1); + var result2 = instance.Get("Test2"); + Assert.NotNull(result2); + Assert.NotSame(result1, result2); + } - /// - /// Checks to ensure a value is returned for 2 duplicate calls. - /// - [Fact] - public void TryGetReturnsSameValue() - { - var instance = GetTestInstance(); - var result1 = instance.Get("Test1"); - Assert.NotNull(result1); - instance.TryGet("Test1", out var result2); - Assert.NotNull(result2); - Assert.Same(result1, result2); - } + /// + /// Checks to ensure a value is returned for 2 duplicate calls. + /// + [Fact] + public void TryGetReturnsSameValue() + { + var instance = GetTestInstance(); + var result1 = instance.Get("Test1"); + Assert.NotNull(result1); + instance.TryGet("Test1", out var result2); + Assert.NotNull(result2); + Assert.Same(result1, result2); + } - /// - /// Checks to ensure 2 different values are returned for 2 different calls. - /// - [Fact] - public void TryGetReturnsDifferentValues() - { - var instance = GetTestInstance(); - var p1 = instance.Get("Test1"); - var p2 = instance.Get("Test2"); + /// + /// Checks to ensure 2 different values are returned for 2 different calls. + /// + [Fact] + public void TryGetReturnsDifferentValues() + { + var instance = GetTestInstance(); + var p1 = instance.Get("Test1"); + var p2 = instance.Get("Test2"); - var result1 = instance.Get("Test1"); - Assert.NotNull(result1); + var result1 = instance.Get("Test1"); + Assert.NotNull(result1); - var result2 = instance.Get("Test2"); - Assert.NotNull(result2); + var result2 = instance.Get("Test2"); + Assert.NotNull(result2); - Assert.NotSame(result1, result2); - Assert.Same(p1, result1); - Assert.Same(p2, result2); - } + Assert.NotSame(result1, result2); + Assert.Same(p1, result1); + Assert.Same(p2, result2); + } - /// - /// Crude test for checking thread safety when using Get. - /// - [Fact] - public void ThreadSafeRetrievalTest() - { - var instance = GetTestInstance(); + /// + /// Crude test for checking thread safety when using Get. + /// + [Fact] + public void ThreadSafeRetrievalTest() + { + var instance = GetTestInstance(); - var tests = Enumerable.Range(0, 100); + var tests = Enumerable.Range(0, 100); - var results = tests.AsParallel().Select(_ => instance.Get("Test1")).ToList(); + var results = tests.AsParallel().Select(_ => instance.Get("Test1")).ToList(); - var first = results.First(); + var first = results.First(); - foreach (var dummyObjectClass1 in results) - { - Assert.Same(first, dummyObjectClass1); - } + foreach (var dummyObjectClass1 in results) + { + Assert.Same(first, dummyObjectClass1); } + } - /// - /// Crude test for checking thread safety when using Get and TryGet. - /// - [Fact] - public void ThreadSafeRetrievalTestWithGetAndTryGet() - { - var instance = GetTestInstance(); + /// + /// Crude test for checking thread safety when using Get and TryGet. + /// + [Fact] + public void ThreadSafeRetrievalTestWithGetAndTryGet() + { + var instance = GetTestInstance(); - var tests = Enumerable.Range(0, 100); + var tests = Enumerable.Range(0, 100); - var results = tests.AsParallel().Select(i => + var results = tests.AsParallel().Select(i => + { + if (i % 2 == 0) { - if (i % 2 == 0) - { - return instance.Get("Test1"); - } + return instance.Get("Test1"); + } - instance.TryGet("Test1", out var result); - return result; - }).ToList(); + instance.TryGet("Test1", out var result); + return result; + }).ToList(); - var first = results.First(x => x is not null); + var first = results.First(x => x is not null); - foreach (var dummyObjectClass1 in results) + foreach (var dummyObjectClass1 in results) + { + if (dummyObjectClass1 is not null) { - if (dummyObjectClass1 is not null) - { - Assert.Same(first, dummyObjectClass1); - } + Assert.Same(first, dummyObjectClass1); } } + } - /// - /// Check that invalidate plays nicely. - /// - [Fact] - public void GetsResultsFromCacheValuesWhenInvalidateAndGetAreUsed() - { - var instance = GetTestInstance(); - - var tests = Enumerable.Range(0, 100); + /// + /// Check that invalidate plays nicely. + /// + [Fact] + public void GetsResultsFromCacheValuesWhenInvalidateAndGetAreUsed() + { + var instance = GetTestInstance(); - var results = tests.AsParallel().Select(i => - { - instance.Invalidate("Test1"); - instance.Get("Test1"); + var tests = Enumerable.Range(0, 100); - return instance.CachedValues(); - }).ToList(); + var results = tests.AsParallel().Select(i => + { + instance.Invalidate("Test1"); + instance.Get("Test1"); - // This is actually a crude test of a misuse case. - // There's no guarantee what comes out is entirely different for every task\thread. - // Just make sure it doesn't throw an exception. - Assert.NotNull(results); - } + return instance.CachedValues(); + }).ToList(); - /// - /// Check that invalidate plays nicely. - /// - [Fact] - public void GetsResultsWhenInvalidateAndGetAreUsed() - { - var instance = GetTestInstance(); + // This is actually a crude test of a misuse case. + // There's no guarantee what comes out is entirely different for every task\thread. + // Just make sure it doesn't throw an exception. + Assert.NotNull(results); + } - var tests = Enumerable.Range(0, 100); + /// + /// Check that invalidate plays nicely. + /// + [Fact] + public void GetsResultsWhenInvalidateAndGetAreUsed() + { + var instance = GetTestInstance(); - var results = tests.AsParallel().Select(i => - { - instance.Invalidate("Test1"); - var result = instance.Get("Test1"); - - // this is here just simply to test cache values plays nicely as well. - var cachedValues = instance.CachedValues(); - return result; - }).ToList(); - - // This is actually a crude test of a misuse case. - // There's no guarantee what comes out is entirely different for every task\thread. - // Just make sure it doesn't throw an exception. - Assert.NotNull(results); - } + var tests = Enumerable.Range(0, 100); - /// - /// Check that invalidate all plays nicely. - /// - [Fact] - public void GetsResultsWhenInvalidateAllAndGetAreUsed() + var results = tests.AsParallel().Select(i => { - var instance = GetTestInstance(); + instance.Invalidate("Test1"); + var result = instance.Get("Test1"); - var tests = Enumerable.Range(0, 100); + // this is here just simply to test cache values plays nicely as well. + var cachedValues = instance.CachedValues(); + return result; + }).ToList(); - var results = tests.AsParallel().Select(i => - { - instance.InvalidateAll(); - return instance.Get("Test1"); - }).ToList(); + // This is actually a crude test of a misuse case. + // There's no guarantee what comes out is entirely different for every task\thread. + // Just make sure it doesn't throw an exception. + Assert.NotNull(results); + } - // This is actually a crude test of a misuse case. - // There's no guarantee what comes out is entirely different for every task\thread. - // Just make sure it doesn't throw an exception. - Assert.NotNull(results); - } + /// + /// Check that invalidate all plays nicely. + /// + [Fact] + public void GetsResultsWhenInvalidateAllAndGetAreUsed() + { + var instance = GetTestInstance(); - private static MemoizingMRUCache GetTestInstance() + var tests = Enumerable.Range(0, 100); + + var results = tests.AsParallel().Select(i => { - return new( - (param, o) => new DummyObjectClass1(), - 256); - } + instance.InvalidateAll(); + return instance.Get("Test1"); + }).ToList(); + + // This is actually a crude test of a misuse case. + // There's no guarantee what comes out is entirely different for every task\thread. + // Just make sure it doesn't throw an exception. + Assert.NotNull(results); + } + + private static MemoizingMRUCache GetTestInstance() + { + return new( + (param, o) => new DummyObjectClass1(), + 256); } } diff --git a/src/Splat.Tests/Mocks/IMockLogTarget.cs b/src/Splat.Tests/Mocks/IMockLogTarget.cs index ebb27cd5c..f224b0391 100644 --- a/src/Splat.Tests/Mocks/IMockLogTarget.cs +++ b/src/Splat.Tests/Mocks/IMockLogTarget.cs @@ -5,16 +5,15 @@ using System.Collections.Generic; -namespace Splat.Tests.Mocks +namespace Splat.Tests.Mocks; + +/// +/// A target with our desired logs. +/// +public interface IMockLogTarget { /// - /// A target with our desired logs. + /// Gets the logs that have been sent. /// - public interface IMockLogTarget - { - /// - /// Gets the logs that have been sent. - /// - ICollection<(LogLevel logLevel, string message)> Logs { get; } - } + ICollection<(LogLevel logLevel, string message)> Logs { get; } } diff --git a/src/Splat.Tests/Mocks/TextLogger.cs b/src/Splat.Tests/Mocks/TextLogger.cs index cb8567bcf..131d4efbf 100644 --- a/src/Splat.Tests/Mocks/TextLogger.cs +++ b/src/Splat.Tests/Mocks/TextLogger.cs @@ -7,46 +7,45 @@ using System.Collections.Generic; using System.IO; -namespace Splat.Tests.Mocks +namespace Splat.Tests.Mocks; + +/// +/// A implementation of for testing. +/// +/// +public class TextLogger : ILogger, IMockLogTarget { - /// - /// A implementation of for testing. - /// - /// - public class TextLogger : ILogger, IMockLogTarget + private readonly List _types = new(); + private readonly List<(LogLevel, string)> _logs = new(); + + /// + public ICollection<(LogLevel logLevel, string message)> Logs => _logs; + + /// + public LogLevel Level { get; set; } + + /// + public void Write(string message, LogLevel logLevel) + { + _logs.Add((logLevel, message)); + } + + /// + public void Write(Exception exception, string message, LogLevel logLevel) + { + Write($"{message} {exception}", logLevel); + } + + /// + public void Write(string message, Type type, LogLevel logLevel) + { + _logs.Add((logLevel, message)); + _types.Add(type); + } + + /// + public void Write(Exception exception, string message, Type type, LogLevel logLevel) { - private readonly List _types = new(); - private readonly List<(LogLevel, string)> _logs = new(); - - /// - public ICollection<(LogLevel logLevel, string message)> Logs => _logs; - - /// - public LogLevel Level { get; set; } - - /// - public void Write(string message, LogLevel logLevel) - { - _logs.Add((logLevel, message)); - } - - /// - public void Write(Exception exception, string message, LogLevel logLevel) - { - Write($"{message} {exception}", logLevel); - } - - /// - public void Write(string message, Type type, LogLevel logLevel) - { - _logs.Add((logLevel, message)); - _types.Add(type); - } - - /// - public void Write(Exception exception, string message, Type type, LogLevel logLevel) - { - Write($"{message} {exception}", type, logLevel); - } + Write($"{message} {exception}", type, logLevel); } } diff --git a/src/Splat.Tests/ModeDetection/ModeTests.cs b/src/Splat.Tests/ModeDetection/ModeTests.cs index 34b611176..9ef89b50c 100644 --- a/src/Splat.Tests/ModeDetection/ModeTests.cs +++ b/src/Splat.Tests/ModeDetection/ModeTests.cs @@ -1,43 +1,42 @@ using Splat.ModeDetection; using Xunit; -namespace Splat.Tests.ModeDetection +namespace Splat.Tests.ModeDetection; + +/// +/// Unit tests for the class. +/// +public class ModeTests { /// - /// Unit tests for the class. + /// Tests the mode. /// - public class ModeTests + [Fact] + public void RunModeTest() { - /// - /// Tests the mode. - /// - [Fact] - public void RunModeTest() - { - // Arrange - ModeDetector.OverrideModeDetector(Mode.Run); + // Arrange + ModeDetector.OverrideModeDetector(Mode.Run); - // Act - var inUnitTestRunner = ModeDetector.InUnitTestRunner(); + // Act + var inUnitTestRunner = ModeDetector.InUnitTestRunner(); - // Assert - Assert.False(inUnitTestRunner); - } + // Assert + Assert.False(inUnitTestRunner); + } - /// - /// Tests the mode. - /// - [Fact] - public void TestModeTest() - { - // Arrange - ModeDetector.OverrideModeDetector(Mode.Test); + /// + /// Tests the mode. + /// + [Fact] + public void TestModeTest() + { + // Arrange + ModeDetector.OverrideModeDetector(Mode.Test); - // Act - var inUnitTestRunner = ModeDetector.InUnitTestRunner(); + // Act + var inUnitTestRunner = ModeDetector.InUnitTestRunner(); - // Assert - Assert.True(inUnitTestRunner); - } + // Assert + Assert.True(inUnitTestRunner); } } diff --git a/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs b/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs index d9acf3526..144f15b6f 100644 --- a/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs +++ b/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs @@ -4,231 +4,228 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Text; + using Splat.Common.Test; using Splat.NLog; + using Xunit; -namespace Splat.Tests.ServiceLocation +namespace Splat.Tests.ServiceLocation; + +/// +/// Common tests for Dependency Resolver interaction with Splat. +/// +/// The dependency resolver to test. +public abstract class BaseDependencyResolverTests + where T : IDependencyResolver { /// - /// Common tests for Dependency Resolver interaction with Splat. + /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. /// - /// The dependency resolver to test. - public abstract class BaseDependencyResolverTests - where T : IDependencyResolver + [Fact] + public virtual void UnregisterCurrent_Doesnt_Throw_When_List_Empty() { - /// - /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. - /// - [Fact] - public virtual void UnregisterCurrent_Doesnt_Throw_When_List_Empty() - { - var resolver = GetDependencyResolver(); - var type = typeof(ILogManager); - resolver.Register(() => new DefaultLogManager(), type); - resolver.Register(() => new DefaultLogManager(), type, "named"); - resolver.UnregisterCurrent(type); - resolver.UnregisterCurrent(type); - } - - /// - /// Test to ensure UnregisterCurrent removes last entry. - /// - [Fact] - public virtual void UnregisterCurrent_Remove_Last() - { - var resolver = GetDependencyResolver(); - var type = typeof(ILogManager); - resolver.Register(() => new DefaultLogManager(), type); - resolver.Register(() => new FuncLogManager(_ => new WrappingFullLogger(new DebugLogger())), type); - resolver.Register(() => new DefaultLogManager(), type, "named"); - - var service = resolver.GetService(type); - Assert.IsType(service); + var resolver = GetDependencyResolver(); + var type = typeof(ILogManager); + resolver.Register(() => new DefaultLogManager(), type); + resolver.Register(() => new DefaultLogManager(), type, "named"); + resolver.UnregisterCurrent(type); + resolver.UnregisterCurrent(type); + } - resolver.UnregisterCurrent(type); + /// + /// Test to ensure UnregisterCurrent removes last entry. + /// + [Fact] + public virtual void UnregisterCurrent_Remove_Last() + { + var resolver = GetDependencyResolver(); + var type = typeof(ILogManager); + resolver.Register(() => new DefaultLogManager(), type); + resolver.Register(() => new FuncLogManager(_ => new WrappingFullLogger(new DebugLogger())), type); + resolver.Register(() => new DefaultLogManager(), type, "named"); - service = resolver.GetService(type); - Assert.IsType(service); - } + var service = resolver.GetService(type); + Assert.IsType(service); - /// - /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. - /// - [Fact] - public virtual void UnregisterCurrentByName_Doesnt_Throw_When_List_Empty() - { - var resolver = GetDependencyResolver(); - var type = typeof(ILogManager); - var contract = "named"; - resolver.Register(() => new DefaultLogManager(), type); - resolver.Register(() => new DefaultLogManager(), type, contract); - resolver.UnregisterCurrent(type, contract); - resolver.UnregisterCurrent(type, contract); - } + resolver.UnregisterCurrent(type); - /// - /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. - /// - [Fact] - public virtual void UnregisterAll_UnregisterCurrent_Doesnt_Throw_When_List_Empty() - { - var resolver = GetDependencyResolver(); - var type = typeof(ILogManager); - resolver.Register(() => new DefaultLogManager(), type); - resolver.Register(() => new DefaultLogManager(), type, "named"); - resolver.UnregisterAll(type); - resolver.UnregisterCurrent(type); - } + service = resolver.GetService(type); + Assert.IsType(service); + } - /// - /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. - /// - [Fact] - public virtual void UnregisterAllByContract_UnregisterCurrent_Doesnt_Throw_When_List_Empty() - { - var resolver = GetDependencyResolver(); - var type = typeof(ILogManager); - var contract = "named"; - resolver.Register(() => new DefaultLogManager(), type); - resolver.Register(() => new DefaultLogManager(), type, contract); - resolver.UnregisterAll(type, contract); - resolver.UnregisterCurrent(type, contract); - } + /// + /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. + /// + [Fact] + public virtual void UnregisterCurrentByName_Doesnt_Throw_When_List_Empty() + { + var resolver = GetDependencyResolver(); + var type = typeof(ILogManager); + var contract = "named"; + resolver.Register(() => new DefaultLogManager(), type); + resolver.Register(() => new DefaultLogManager(), type, contract); + resolver.UnregisterCurrent(type, contract); + resolver.UnregisterCurrent(type, contract); + } - /// - /// Ensures never returns null. - /// - [Fact] - public void GetServices_Should_Never_Return_Null() - { - var resolver = GetDependencyResolver(); + /// + /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. + /// + [Fact] + public virtual void UnregisterAll_UnregisterCurrent_Doesnt_Throw_When_List_Empty() + { + var resolver = GetDependencyResolver(); + var type = typeof(ILogManager); + resolver.Register(() => new DefaultLogManager(), type); + resolver.Register(() => new DefaultLogManager(), type, "named"); + resolver.UnregisterAll(type); + resolver.UnregisterCurrent(type); + } - Assert.NotNull(resolver.GetServices()); - Assert.NotNull(resolver.GetServices("Landscape")); - } + /// + /// Test to ensure Unregister doesn't cause an IndexOutOfRangeException. + /// + [Fact] + public virtual void UnregisterAllByContract_UnregisterCurrent_Doesnt_Throw_When_List_Empty() + { + var resolver = GetDependencyResolver(); + var type = typeof(ILogManager); + var contract = "named"; + resolver.Register(() => new DefaultLogManager(), type); + resolver.Register(() => new DefaultLogManager(), type, contract); + resolver.UnregisterAll(type, contract); + resolver.UnregisterCurrent(type, contract); + } - /// - /// Tests for ensuring hasregistration behaves when using contracts. - /// - [Fact] - public virtual void HasRegistration() - { - var type = typeof(string); - const string contractOne = "ContractOne"; - const string contractTwo = "ContractTwo"; - var resolver = GetDependencyResolver(); - - Assert.False(resolver.HasRegistration(type)); - Assert.False(resolver.HasRegistration(type, contractOne)); - Assert.False(resolver.HasRegistration(type, contractTwo)); - - resolver.Register(() => "unnamed", type); - Assert.True(resolver.HasRegistration(type)); - Assert.False(resolver.HasRegistration(type, contractOne)); - Assert.False(resolver.HasRegistration(type, contractTwo)); - resolver.UnregisterAll(type); - - resolver.Register(() => contractOne, type, contractOne); - Assert.False(resolver.HasRegistration(type)); - Assert.True(resolver.HasRegistration(type, contractOne)); - Assert.False(resolver.HasRegistration(type, contractTwo)); - resolver.UnregisterAll(type, contractOne); - - resolver.Register(() => contractTwo, type, contractTwo); - Assert.False(resolver.HasRegistration(type)); - Assert.False(resolver.HasRegistration(type, contractOne)); - Assert.True(resolver.HasRegistration(type, contractTwo)); - } + /// + /// Ensures never returns null. + /// + [Fact] + public void GetServices_Should_Never_Return_Null() + { + var resolver = GetDependencyResolver(); - /// - /// Tests to ensure NLog registers correctly with different service locators. - /// Based on issue reported in #553. - /// - [Fact] - public void ILogManager_Resolvable() - { - var resolver = GetDependencyResolver(); + Assert.NotNull(resolver.GetServices()); + Assert.NotNull(resolver.GetServices("Landscape")); + } - // NOTE:MicrosoftDependencyResolver test for this funtionality is in DependencyResolverTests - if (resolver.GetType().Name != "MicrosoftDependencyResolver") - { - // Setup NLog for Logging (doesn't matter if I actually configure NLog or not) - resolver.UseNLogWithWrappingFullLogger(); - Locator.SetLocator(resolver); - Locator.CurrentMutable.InitializeSplat(); + /// + /// Tests for ensuring hasregistration behaves when using contracts. + /// + [Fact] + public virtual void HasRegistration() + { + var type = typeof(string); + const string contractOne = "ContractOne"; + const string contractTwo = "ContractTwo"; + var resolver = GetDependencyResolver(); + + Assert.False(resolver.HasRegistration(type)); + Assert.False(resolver.HasRegistration(type, contractOne)); + Assert.False(resolver.HasRegistration(type, contractTwo)); + + resolver.Register(() => "unnamed", type); + Assert.True(resolver.HasRegistration(type)); + Assert.False(resolver.HasRegistration(type, contractOne)); + Assert.False(resolver.HasRegistration(type, contractTwo)); + resolver.UnregisterAll(type); + + resolver.Register(() => contractOne, type, contractOne); + Assert.False(resolver.HasRegistration(type)); + Assert.True(resolver.HasRegistration(type, contractOne)); + Assert.False(resolver.HasRegistration(type, contractTwo)); + resolver.UnregisterAll(type, contractOne); + + resolver.Register(() => contractTwo, type, contractTwo); + Assert.False(resolver.HasRegistration(type)); + Assert.False(resolver.HasRegistration(type, contractOne)); + Assert.True(resolver.HasRegistration(type, contractTwo)); + } - // Get the ILogManager instance - var lm = Locator.Current.GetService(); - Assert.NotNull(lm); + /// + /// Tests to ensure NLog registers correctly with different service locators. + /// Based on issue reported in #553. + /// + [Fact] + public void ILogManager_Resolvable() + { + var resolver = GetDependencyResolver(); - // now suceeds for AutoFac, Ninject and Splat -#pragma warning disable CS8604 // Possible null reference argument. - var mgr = lm.GetLogger(); -#pragma warning restore CS8604 // Possible null reference argument. - Assert.NotNull(mgr); - } + // NOTE:MicrosoftDependencyResolver test for this funtionality is in DependencyResolverTests + if (resolver.GetType().Name != "MicrosoftDependencyResolver") + { + // Setup NLog for Logging (doesn't matter if I actually configure NLog or not) + resolver.UseNLogWithWrappingFullLogger(); + Locator.SetLocator(resolver); + Locator.CurrentMutable.InitializeSplat(); + + // Get the ILogManager instance + var lm = Locator.Current.GetService(); + Assert.NotNull(lm); + + // now suceeds for AutoFac, Ninject and Splat + var mgr = lm.GetLogger(); + Assert.NotNull(mgr); } + } - /// - /// Nulls the resolver tests. - /// - [Fact] - public void NullResolverTests() - { - IReadonlyDependencyResolver? resolver = default; - IMutableDependencyResolver? resolver1 = default; - IDependencyResolver? resolver2 = default; + /// + /// Nulls the resolver tests. + /// + [Fact] + public void NullResolverTests() + { + IReadonlyDependencyResolver? resolver = default; + IMutableDependencyResolver? resolver1 = default; + IDependencyResolver? resolver2 = default; #pragma warning disable CS8604 // Possible null reference argument. - Assert.Throws(() => resolver.GetService()); - Assert.Throws(() => resolver.GetServices()); - Assert.Throws(() => resolver1.ServiceRegistrationCallback(typeof(ILogManager), (IDisposable d) => { d.Dispose(); })); - Assert.Throws(() => resolver2.WithResolver().Dispose()); - Assert.Throws(() => resolver1.Register(() => new DefaultLogManager())); - Assert.Throws(() => resolver1.RegisterConstant(new DefaultLogManager())); - Assert.Throws(() => resolver1.RegisterLazySingleton(() => new DefaultLogManager(), typeof(ILogManager))); - Assert.Throws(() => resolver1.RegisterLazySingletonAnd(() => new DefaultLogManager(), typeof(ILogManager))); - Assert.Throws(() => resolver1.RegisterLazySingleton(() => new DefaultLogManager())); - Assert.Throws(() => resolver1.RegisterLazySingletonAnd("eight")); - Assert.Throws(() => resolver1.RegisterLazySingletonAnd(() => new DefaultLogManager(), "seven")); - Assert.Throws(() => resolver1.UnregisterCurrent()); - Assert.Throws(() => resolver1.UnregisterAll()); - Assert.Throws(() => resolver1.RegisterAnd()); - Assert.Throws(() => resolver1.RegisterAnd(() => new DefaultLogManager())); - Assert.Throws(() => resolver1.RegisterAnd(() => new ViewModelOne())); - Assert.Throws(() => resolver1.Register()); - Assert.Throws(() => resolver1.RegisterConstantAnd(new ViewModelOne())); - Assert.Throws(() => resolver1.RegisterConstantAnd(new ViewModelOne(), typeof(ViewModelOne))); - Assert.Throws(() => resolver1.RegisterConstantAnd()); + Assert.Throws(() => resolver.GetService()); + Assert.Throws(() => resolver.GetServices()); + Assert.Throws(() => resolver1.ServiceRegistrationCallback(typeof(ILogManager), (IDisposable d) => { d.Dispose(); })); + Assert.Throws(() => resolver2.WithResolver().Dispose()); + Assert.Throws(() => resolver1.Register(() => new DefaultLogManager())); + Assert.Throws(() => resolver1.RegisterConstant(new DefaultLogManager())); + Assert.Throws(() => resolver1.RegisterLazySingleton(() => new DefaultLogManager(), typeof(ILogManager))); + Assert.Throws(() => resolver1.RegisterLazySingletonAnd(() => new DefaultLogManager(), typeof(ILogManager))); + Assert.Throws(() => resolver1.RegisterLazySingleton(() => new DefaultLogManager())); + Assert.Throws(() => resolver1.RegisterLazySingletonAnd("eight")); + Assert.Throws(() => resolver1.RegisterLazySingletonAnd(() => new DefaultLogManager(), "seven")); + Assert.Throws(() => resolver1.UnregisterCurrent()); + Assert.Throws(() => resolver1.UnregisterAll()); + Assert.Throws(() => resolver1.RegisterAnd()); + Assert.Throws(() => resolver1.RegisterAnd(() => new DefaultLogManager())); + Assert.Throws(() => resolver1.RegisterAnd(() => new ViewModelOne())); + Assert.Throws(() => resolver1.Register()); + Assert.Throws(() => resolver1.RegisterConstantAnd(new ViewModelOne())); + Assert.Throws(() => resolver1.RegisterConstantAnd(new ViewModelOne(), typeof(ViewModelOne))); + Assert.Throws(() => resolver1.RegisterConstantAnd()); #pragma warning restore CS8604 // Possible null reference argument. - } - - /// - /// Registers the and tests. - /// - [Fact] - public void RegisterAndTests() - { - var resolver = GetDependencyResolver(); - Assert.Throws(() => resolver.RegisterAnd(default!)); - resolver.RegisterAnd("one") - .RegisterAnd("two") - .RegisterAnd(() => new DefaultLogManager(), "three") - .RegisterAnd(() => new ViewModelOne(), "four") - .RegisterConstantAnd("five") - .RegisterConstantAnd(new ViewModelOne(), typeof(ViewModelOne), "six") - .RegisterLazySingletonAnd(() => new DefaultLogManager(), typeof(ILogManager), "seven") - .RegisterLazySingletonAnd("eight") - .RegisterLazySingletonAnd(() => new DefaultLogManager(), "seven") - .Register(); - } + } - /// - /// Gets an instance of a dependency resolver to test. - /// - /// Dependency Resolver. - protected abstract T GetDependencyResolver(); + /// + /// Registers the and tests. + /// + [Fact] + public void RegisterAndTests() + { + var resolver = GetDependencyResolver(); + Assert.Throws(() => resolver.RegisterAnd(default!)); + resolver.RegisterAnd("one") + .RegisterAnd("two") + .RegisterAnd(() => new DefaultLogManager(), "three") + .RegisterAnd(() => new ViewModelOne(), "four") + .RegisterConstantAnd("five") + .RegisterConstantAnd(new ViewModelOne(), typeof(ViewModelOne), "six") + .RegisterLazySingletonAnd(() => new DefaultLogManager(), typeof(ILogManager), "seven") + .RegisterLazySingletonAnd("eight") + .RegisterLazySingletonAnd(() => new DefaultLogManager(), "seven") + .Register(); } + + /// + /// Gets an instance of a dependency resolver to test. + /// + /// Dependency Resolver. + protected abstract T GetDependencyResolver(); } diff --git a/src/Splat.Tests/ServiceLocation/ModernDependencyResolverTests.cs b/src/Splat.Tests/ServiceLocation/ModernDependencyResolverTests.cs index 47aad018c..8444e7bc6 100644 --- a/src/Splat.Tests/ServiceLocation/ModernDependencyResolverTests.cs +++ b/src/Splat.Tests/ServiceLocation/ModernDependencyResolverTests.cs @@ -3,19 +3,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; -using Xunit; +namespace Splat.Tests.ServiceLocation; -namespace Splat.Tests.ServiceLocation +/// +/// Unit Tests for the Modern Dependency Resolver. +/// +public sealed class ModernDependencyResolverTests : BaseDependencyResolverTests { - /// - /// Unit Tests for the Modern Dependency Resolver. - /// - public sealed class ModernDependencyResolverTests : BaseDependencyResolverTests - { - /// - protected override ModernDependencyResolver GetDependencyResolver() => new(); - } + /// + protected override ModernDependencyResolver GetDependencyResolver() => new(); } diff --git a/src/Splat.Tests/TargetFrameworkExtensionsTests.cs b/src/Splat.Tests/TargetFrameworkExtensionsTests.cs index 3d720490c..2faf67cd1 100644 --- a/src/Splat.Tests/TargetFrameworkExtensionsTests.cs +++ b/src/Splat.Tests/TargetFrameworkExtensionsTests.cs @@ -3,171 +3,168 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; -using System.Reflection; -using System.Text; + using Xunit; -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Unit Tests for Target Framework Extensions. +/// +public class TargetFrameworkExtensionsTests { /// - /// Unit Tests for Target Framework Extensions. + /// Gets the test source data for Framework names. /// - public class TargetFrameworkExtensionsTests + public static IEnumerable FrameworkNamesTestSource { get; } = new[] { - /// - /// Gets the test source data for Framework names. - /// - public static IEnumerable FrameworkNamesTestSource { get; } = new[] - { - new object[] - { - ".NETCoreApp,Version=v2.2", - "netcoreapp2.2", - }, - new object[] - { - ".NETCoreApp,Version=v2.1", - "netcoreapp2.1", - }, - new object[] - { - ".NETCoreApp,Version=v2.0", - "netcoreapp2.0", - }, - new object[] - { - ".NETCoreApp,Version=v1.1", - "netcoreapp1.1", - }, - new object[] - { - ".NETCoreApp,Version=v1.0", - "netcoreapp1.0", - }, - new object[] - { - ".NETStandard,Version=v2.0", - "netstandard2.0", - }, - new object[] - { - ".NETStandard,Version=v1.6", - "netstandard1.6", - }, - new object[] - { - ".NETStandard,Version=v1.5", - "netstandard1.5", - }, - new object[] - { - ".NETStandard,Version=v1.4", - "netstandard1.4", - }, - new object[] - { - ".NETStandard,Version=v1.3", - "netstandard1.3", - }, - new object[] - { - ".NETStandard,Version=v1.2", - "netstandard1.2", - }, - new object[] - { - ".NETStandard,Version=v1.1", - "netstandard1.1", - }, - new object[] - { - ".NETStandard,Version=v1.0", - "netstandard1.0", - }, - new object[] - { - ".NETFramework,Version=v4.7.2", - "net472", - }, - new object[] - { - ".NETFramework,Version=v4.7.1", - "net471", - }, - new object[] - { - ".NETFramework,Version=v4.7", - "net47", - }, - new object[] - { - ".NETFramework,Version=v4.6.2", - "net462", - }, - new object[] - { - ".NETFramework,Version=v4.6.1", - "net461", - }, - new object[] - { - ".NETFramework,Version=v4.6", - "net46", - }, - new object[] - { - ".NETFramework,Version=v4.5.2", - "net452", - }, - new object[] - { - ".NETFramework,Version=v4.5.1", - "net451", - }, - new object[] - { - ".NETFramework,Version=v4.5", - "net45", - }, - new object[] - { - ".NETFramework,Version=v4.0.3", - "net403", - }, - new object[] - { - ".NETFramework,Version=v4.0", - "net40", - }, - new object[] - { - ".NETFramework,Version=v3.5", - "net35", - }, - new object[] - { - ".NETFramework,Version=v2.0", - "net20", - }, - new object[] - { - ".NETFramework,Version=v1.1", - "net11", - } - }; + new object[] + { + ".NETCoreApp,Version=v2.2", + "netcoreapp2.2", + }, + new object[] + { + ".NETCoreApp,Version=v2.1", + "netcoreapp2.1", + }, + new object[] + { + ".NETCoreApp,Version=v2.0", + "netcoreapp2.0", + }, + new object[] + { + ".NETCoreApp,Version=v1.1", + "netcoreapp1.1", + }, + new object[] + { + ".NETCoreApp,Version=v1.0", + "netcoreapp1.0", + }, + new object[] + { + ".NETStandard,Version=v2.0", + "netstandard2.0", + }, + new object[] + { + ".NETStandard,Version=v1.6", + "netstandard1.6", + }, + new object[] + { + ".NETStandard,Version=v1.5", + "netstandard1.5", + }, + new object[] + { + ".NETStandard,Version=v1.4", + "netstandard1.4", + }, + new object[] + { + ".NETStandard,Version=v1.3", + "netstandard1.3", + }, + new object[] + { + ".NETStandard,Version=v1.2", + "netstandard1.2", + }, + new object[] + { + ".NETStandard,Version=v1.1", + "netstandard1.1", + }, + new object[] + { + ".NETStandard,Version=v1.0", + "netstandard1.0", + }, + new object[] + { + ".NETFramework,Version=v4.7.2", + "net472", + }, + new object[] + { + ".NETFramework,Version=v4.7.1", + "net471", + }, + new object[] + { + ".NETFramework,Version=v4.7", + "net47", + }, + new object[] + { + ".NETFramework,Version=v4.6.2", + "net462", + }, + new object[] + { + ".NETFramework,Version=v4.6.1", + "net461", + }, + new object[] + { + ".NETFramework,Version=v4.6", + "net46", + }, + new object[] + { + ".NETFramework,Version=v4.5.2", + "net452", + }, + new object[] + { + ".NETFramework,Version=v4.5.1", + "net451", + }, + new object[] + { + ".NETFramework,Version=v4.5", + "net45", + }, + new object[] + { + ".NETFramework,Version=v4.0.3", + "net403", + }, + new object[] + { + ".NETFramework,Version=v4.0", + "net40", + }, + new object[] + { + ".NETFramework,Version=v3.5", + "net35", + }, + new object[] + { + ".NETFramework,Version=v2.0", + "net20", + }, + new object[] + { + ".NETFramework,Version=v1.1", + "net11", + }, + }; - /// - /// Checks to ensure the framework name is returned. - /// - /// The framework name. - /// The expected result. - [Theory] - [MemberData(nameof(FrameworkNamesTestSource))] - public void ReturnsName(string frameworkName, string expected) - { - Assert.Equal(expected, TargetFrameworkExtensions.GetTargetFrameworkName(frameworkName)); - } + /// + /// Checks to ensure the framework name is returned. + /// + /// The framework name. + /// The expected result. + [Theory] + [MemberData(nameof(FrameworkNamesTestSource))] + public void ReturnsName(string frameworkName, string expected) + { + Assert.Equal(expected, TargetFrameworkExtensions.GetTargetFrameworkName(frameworkName)); } } diff --git a/src/Splat.Tests/XUnitHelpers.cs b/src/Splat.Tests/XUnitHelpers.cs index 1d99ec80d..8f5deffb4 100644 --- a/src/Splat.Tests/XUnitHelpers.cs +++ b/src/Splat.Tests/XUnitHelpers.cs @@ -5,30 +5,28 @@ using System; using System.Collections.Generic; -using System.Text; -namespace Splat.Tests +namespace Splat.Tests; + +/// +/// Helpers for XUnit. +/// +public static class XUnitHelpers { /// - /// Helpers for XUnit. + /// Gets Theory Permutations for all the values in an enum. /// - public static class XUnitHelpers + /// The type of enum. + /// An XUnit theory data source. + public static IEnumerable GetEnumAsTestTheory() { - /// - /// Gets Theory Permutations for all the values in an enum. - /// - /// The type of enum. - /// An XUnit theory data source. - public static IEnumerable GetEnumAsTestTheory() + var values = Enum.GetValues(typeof(TEnum)); + var results = new List(values.Length); + foreach (var value in values) { - var values = Enum.GetValues(typeof(TEnum)); - var results = new List(values.Length); - foreach (var value in values) - { - results.Add(new[] { value! }); - } - - return results; + results.Add(new[] { value! }); } + + return results; } } diff --git a/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingManager.cs b/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingManager.cs index 427d4c5fc..b70ad2e23 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingManager.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingManager.cs @@ -3,19 +3,18 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.ApplicationPerformanceMonitoring +namespace Splat.ApplicationPerformanceMonitoring; + +/// +/// Default implementation of the Feature Usage Tracking Manager. +/// +public sealed class DefaultFeatureUsageTrackingManager : FuncFeatureUsageTrackingManager { /// - /// Default implementation of the Feature Usage Tracking Manager. + /// Initializes a new instance of the class. /// - public sealed class DefaultFeatureUsageTrackingManager : FuncFeatureUsageTrackingManager + public DefaultFeatureUsageTrackingManager() + : base(featureName => new DefaultFeatureUsageTrackingSession(featureName)) { - /// - /// Initializes a new instance of the class. - /// - public DefaultFeatureUsageTrackingManager() - : base(featureName => new DefaultFeatureUsageTrackingSession(featureName)) - { - } } } diff --git a/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingSession.cs b/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingSession.cs index e5ff10aaa..7f018f403 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingSession.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/DefaultFeatureUsageTrackingSession.cs @@ -5,75 +5,74 @@ using System; -namespace Splat.ApplicationPerformanceMonitoring +namespace Splat.ApplicationPerformanceMonitoring; + +/// +/// Default Feature Usage Tracking Session. Used for output when a dev chooses not to override. +/// +public sealed class DefaultFeatureUsageTrackingSession : IFeatureUsageTrackingSession, IEnableLogger { /// - /// Default Feature Usage Tracking Session. Used for output when a dev chooses not to override. + /// Initializes a new instance of the class. /// - public sealed class DefaultFeatureUsageTrackingSession : IFeatureUsageTrackingSession, IEnableLogger + /// The name of the feature. + public DefaultFeatureUsageTrackingSession(string featureName) + : this(featureName, Guid.Empty) + { + } + + internal DefaultFeatureUsageTrackingSession(string featureName, Guid parentReference) { - /// - /// Initializes a new instance of the class. - /// - /// The name of the feature. - public DefaultFeatureUsageTrackingSession(string featureName) - : this(featureName, Guid.Empty) + if (string.IsNullOrWhiteSpace(featureName)) { + throw new ArgumentNullException(nameof(featureName)); } - internal DefaultFeatureUsageTrackingSession(string featureName, Guid parentReference) - { - if (string.IsNullOrWhiteSpace(featureName)) - { - throw new ArgumentNullException(nameof(featureName)); - } + ParentReference = parentReference; + FeatureName = featureName; + FeatureReference = Guid.NewGuid(); - ParentReference = parentReference; - FeatureName = featureName; - FeatureReference = Guid.NewGuid(); + this.Log().Info(GetSessionStartLogMessage); + } - this.Log().Info(GetSessionStartLogMessage); - } + /// + public Guid ParentReference { get; } - /// - public Guid ParentReference { get; } + /// + public Guid FeatureReference { get; } - /// - public Guid FeatureReference { get; } + /// + public string FeatureName { get; } - /// - public string FeatureName { get; } + /// + public IFeatureUsageTrackingSession SubFeature(string description) + { + return new DefaultFeatureUsageTrackingSession(description, FeatureReference); + } - /// - public IFeatureUsageTrackingSession SubFeature(string description) - { - return new DefaultFeatureUsageTrackingSession(description, FeatureReference); - } + /// + public void OnException(Exception exception) + { + this.Log().InfoException( + () => "Feature Usage Tracking Exception", + exception); + } - /// - public void OnException(Exception exception) - { - this.Log().InfoException( - () => "Feature Usage Tracking Exception", - exception); - } + /// + public void Dispose() + { + this.Log().Info(() => $"Feature Finish: {FeatureReference}"); + } - /// - public void Dispose() + private string GetSessionStartLogMessage() + { + var message = + $"Feature Start. Reference={FeatureReference}{(ParentReference != Guid.Empty ? $", Parent Reference={ParentReference}" : null)}"; + if (ParentReference != Guid.Empty) { - this.Log().Info(() => $"Feature Finish: {FeatureReference}"); + message += $", Parent Reference={ParentReference}"; } - private string GetSessionStartLogMessage() - { - var message = - $"Feature Start. Reference={FeatureReference}{(ParentReference != Guid.Empty ? $", Parent Reference={ParentReference}" : null)}"; - if (ParentReference != Guid.Empty) - { - message += $", Parent Reference={ParentReference}"; - } - - return message; - } + return message; } } diff --git a/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs b/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs index a77c616d9..04c574d82 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs @@ -5,95 +5,94 @@ using System; -namespace Splat.ApplicationPerformanceMonitoring +namespace Splat.ApplicationPerformanceMonitoring; + +/// +/// Extensions for the IEnableFeatureUsageTracking interface. This is a similar design to IEnableLogger, to allow +/// easy use and extension of classes such as ViewModels. +/// +public static class EnableFeatureUsageTrackingExtensions { /// - /// Extensions for the IEnableFeatureUsageTracking interface. This is a similar design to IEnableLogger, to allow - /// easy use and extension of classes such as ViewModels. + /// Gets a Feature Usage Tracking Sessions. /// - public static class EnableFeatureUsageTrackingExtensions + /// instance of class that uses IEnableFeatureUsageTracking. + /// Name of the feature. + /// Feature Usage Tracking Session. + public static IFeatureUsageTrackingSession FeatureUsageTrackingSession( + this IEnableFeatureUsageTracking instance, + string featureName) { - /// - /// Gets a Feature Usage Tracking Sessions. - /// - /// instance of class that uses IEnableFeatureUsageTracking. - /// Name of the feature. - /// Feature Usage Tracking Session. - public static IFeatureUsageTrackingSession FeatureUsageTrackingSession( - this IEnableFeatureUsageTracking instance, - string featureName) + var featureUsageTrackingSession = Locator.Current.GetService(); + if (featureUsageTrackingSession is null) { - var featureUsageTrackingSession = Locator.Current.GetService(); - if (featureUsageTrackingSession is null) - { - throw new InvalidOperationException("Feature Usage Tracking Manager is null. This should never happen, your dependency resolver is broken"); - } + throw new InvalidOperationException("Feature Usage Tracking Manager is null. This should never happen, your dependency resolver is broken"); + } + + return featureUsageTrackingSession.GetFeatureUsageTrackingSession(featureName); + } - return featureUsageTrackingSession.GetFeatureUsageTrackingSession(featureName); + /// + /// Helper for wrapping an action with a Feature Usage Tracking Session. + /// + /// instance of class that uses IEnableFeatureUsageTracking. + /// Name of the feature. + /// Action to carry out. + public static void WithFeatureUsageTrackingSession( + this IEnableFeatureUsageTracking instance, + string featureName, + Action action) + { + if (action is null) + { + throw new ArgumentNullException(nameof(action)); } - /// - /// Helper for wrapping an action with a Feature Usage Tracking Session. - /// - /// instance of class that uses IEnableFeatureUsageTracking. - /// Name of the feature. - /// Action to carry out. - public static void WithFeatureUsageTrackingSession( - this IEnableFeatureUsageTracking instance, - string featureName, - Action action) + using (var session = instance.FeatureUsageTrackingSession(featureName)) { - if (action is null) + try { - throw new ArgumentNullException(nameof(action)); + action(session); } - - using (var session = instance.FeatureUsageTrackingSession(featureName)) + catch (Exception exception) { - try - { - action(session); - } - catch (Exception exception) - { - session.OnException(exception); - throw; - } + session.OnException(exception); + throw; } } + } - /// - /// Helper for wrapping an action with a SubFeature Usage Tracking Session. - /// - /// instance of class that uses IEnableFeatureUsageTracking. - /// Name of the feature. - /// Action to carry out. - public static void WithSubFeatureUsageTrackingSession( - this IFeatureUsageTrackingSession instance, - string featureName, - Action action) + /// + /// Helper for wrapping an action with a SubFeature Usage Tracking Session. + /// + /// instance of class that uses IEnableFeatureUsageTracking. + /// Name of the feature. + /// Action to carry out. + public static void WithSubFeatureUsageTrackingSession( + this IFeatureUsageTrackingSession instance, + string featureName, + Action action) + { + if (instance is null) { - if (instance is null) - { - throw new ArgumentNullException(nameof(instance)); - } + throw new ArgumentNullException(nameof(instance)); + } - if (action is null) + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } + + using (var session = instance.SubFeature(featureName)) + { + try { - throw new ArgumentNullException(nameof(action)); + action(session); } - - using (var session = instance.SubFeature(featureName)) + catch (Exception exception) { - try - { - action(session); - } - catch (Exception exception) - { - session.OnException(exception); - throw; - } + session.OnException(exception); + throw; } } } diff --git a/src/Splat/ApplicationPerformanceMonitoring/FuncFeatureUsageTrackingManager.cs b/src/Splat/ApplicationPerformanceMonitoring/FuncFeatureUsageTrackingManager.cs index 528fc5bcb..6c4a0d918 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/FuncFeatureUsageTrackingManager.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/FuncFeatureUsageTrackingManager.cs @@ -5,31 +5,30 @@ using System; -namespace Splat.ApplicationPerformanceMonitoring +namespace Splat.ApplicationPerformanceMonitoring; + +/// +/// Func based Feature Usage Tracking Manager. +/// +public class FuncFeatureUsageTrackingManager : IFeatureUsageTrackingManager { + private readonly Func _featureUsageTrackingSessionFunc; + /// - /// Func based Feature Usage Tracking Manager. + /// Initializes a new instance of the class. /// - public class FuncFeatureUsageTrackingManager : IFeatureUsageTrackingManager + /// + /// Factory function for a Feature Usage Tracking Session. + /// + public FuncFeatureUsageTrackingManager(Func featureUsageTrackingSessionFunc) { - private readonly Func _featureUsageTrackingSessionFunc; - - /// - /// Initializes a new instance of the class. - /// - /// - /// Factory function for a Feature Usage Tracking Session. - /// - public FuncFeatureUsageTrackingManager(Func featureUsageTrackingSessionFunc) - { - _featureUsageTrackingSessionFunc = featureUsageTrackingSessionFunc ?? - throw new ArgumentNullException(nameof(featureUsageTrackingSessionFunc)); - } + _featureUsageTrackingSessionFunc = featureUsageTrackingSessionFunc ?? + throw new ArgumentNullException(nameof(featureUsageTrackingSessionFunc)); + } - /// - public IFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) - { - return _featureUsageTrackingSessionFunc(featureName); - } + /// + public IFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName) + { + return _featureUsageTrackingSessionFunc(featureName); } } diff --git a/src/Splat/ApplicationPerformanceMonitoring/IEnableFeatureUsageTracking.cs b/src/Splat/ApplicationPerformanceMonitoring/IEnableFeatureUsageTracking.cs index 7a2cfb129..eac933261 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/IEnableFeatureUsageTracking.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/IEnableFeatureUsageTracking.cs @@ -6,14 +6,12 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; -namespace Splat.ApplicationPerformanceMonitoring +namespace Splat.ApplicationPerformanceMonitoring; + +/// +/// Interface for exposing Feature Usage Tracking as an extension to a class. +/// +[ComVisible(false)] +public interface IEnableFeatureUsageTracking { - /// - /// Interface for exposing Feature Usage Tracking as an extension to a class. - /// - [SuppressMessage("Design", "CA1040: Avoid empty interfaces", Justification = "Deliberate use")] - [ComVisible(false)] - public interface IEnableFeatureUsageTracking - { - } } diff --git a/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingManager.cs b/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingManager.cs index f5601b12e..b4c36898f 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingManager.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingManager.cs @@ -3,20 +3,17 @@ // 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.ApplicationPerformanceMonitoring; -namespace Splat.ApplicationPerformanceMonitoring +/// +/// A manager which will generate a for the specified type. +/// +public interface IFeatureUsageTrackingManager { /// - /// A manager which will generate a for the specified type. + /// Generate a for the specified type. /// - public interface IFeatureUsageTrackingManager - { - /// - /// Generate a for the specified type. - /// - /// The name of the feature. - /// The . - IFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName); - } + /// The name of the feature. + /// The . + IFeatureUsageTrackingSession GetFeatureUsageTrackingSession(string featureName); } diff --git a/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession.cs b/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession.cs index 8a04026a4..c9dc98429 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession.cs @@ -5,29 +5,28 @@ using System; -namespace Splat.ApplicationPerformanceMonitoring +namespace Splat.ApplicationPerformanceMonitoring; + +/// +/// Base interface for a feature usage tracking session. +/// +public interface IFeatureUsageTrackingSession : IDisposable { /// - /// Base interface for a feature usage tracking session. + /// Gets the name of the Feature being tracked. /// - public interface IFeatureUsageTrackingSession : IDisposable - { - /// - /// Gets the name of the Feature being tracked. - /// - string FeatureName { get; } + string FeatureName { get; } - /// - /// Starts a sub-feature usage tracking session on the current session. - /// - /// Description of the sub-feature. - /// The sub-feature usage tracking session. - IFeatureUsageTrackingSession SubFeature(string description); + /// + /// Starts a sub-feature usage tracking session on the current session. + /// + /// Description of the sub-feature. + /// The sub-feature usage tracking session. + IFeatureUsageTrackingSession SubFeature(string description); - /// - /// Notify the APM toolset an exception has occured in the current tracking session. - /// - /// The exception that occurred. - void OnException(Exception exception); - } + /// + /// Notify the APM toolset an exception has occured in the current tracking session. + /// + /// The exception that occurred. + void OnException(Exception exception); } diff --git a/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession{TReferenceType}.cs b/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession{TReferenceType}.cs index ea97512c1..1f09c32c7 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession{TReferenceType}.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/IFeatureUsageTrackingSession{TReferenceType}.cs @@ -3,24 +3,21 @@ // 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.ApplicationPerformanceMonitoring; -namespace Splat.ApplicationPerformanceMonitoring +/// +/// Generic interface for a Feature Usage Tracking Session. +/// +/// The Type for the Unique Tracking References. +public interface IFeatureUsageTrackingSession : IFeatureUsageTrackingSession { /// - /// Generic interface for a Feature Usage Tracking Session. + /// Gets the current Feature Usage Unique Reference. /// - /// The Type for the Unique Tracking References. - public interface IFeatureUsageTrackingSession : IFeatureUsageTrackingSession - { - /// - /// Gets the current Feature Usage Unique Reference. - /// - TReferenceType FeatureReference { get; } + TReferenceType FeatureReference { get; } - /// - /// Gets the unique reference for the Parent Tracking Session, if any. - /// - TReferenceType ParentReference { get; } - } + /// + /// Gets the unique reference for the Parent Tracking Session, if any. + /// + TReferenceType ParentReference { get; } } diff --git a/src/Splat/ApplicationPerformanceMonitoring/IViewTracking.cs b/src/Splat/ApplicationPerformanceMonitoring/IViewTracking.cs index 5c68ea068..7e75f351d 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/IViewTracking.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/IViewTracking.cs @@ -3,17 +3,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.ApplicationPerformanceMonitoring +namespace Splat.ApplicationPerformanceMonitoring; + +/// +/// Base interface for tracking view usage. +/// +public interface IViewTracking { /// - /// Base interface for tracking view usage. + /// Track a view navigation using just a name. /// - public interface IViewTracking - { - /// - /// Track a view navigation using just a name. - /// - /// Name of the view. - void OnViewNavigation(string name); - } + /// Name of the view. + void OnViewNavigation(string name); } diff --git a/src/Splat/AssemblyFinder.cs b/src/Splat/AssemblyFinder.cs index e80cd11fa..53380a7c0 100644 --- a/src/Splat/AssemblyFinder.cs +++ b/src/Splat/AssemblyFinder.cs @@ -8,47 +8,45 @@ using System.Linq; using System.Reflection; -namespace Splat +namespace Splat; + +internal static class AssemblyFinder { - internal static class AssemblyFinder + /// + /// Attempt to find the type based on the specified string. + /// + /// The type to cast the value to if we find it. + /// The name of the full type. + /// The created object or the default value. + public static T? AttemptToLoadType(string fullTypeName) { - /// - /// Attempt to find the type based on the specified string. - /// - /// The type to cast the value to if we find it. - /// The name of the full type. - /// The created object or the default value. - [SuppressMessage("Globalization", "CA1307:Specify StringComparison for clarity", Justification = "Not available all platforms.")] - public static T? AttemptToLoadType(string fullTypeName) - { - var thisType = typeof(AssemblyFinder); + var thisType = typeof(AssemblyFinder); - var thisTypeName = thisType.AssemblyQualifiedName; + var thisTypeName = thisType.AssemblyQualifiedName; - if (thisTypeName is null) - { - return default; - } + if (thisTypeName is null) + { + return default; + } - var toSearch = new[] - { - thisTypeName.Replace(thisType.FullName + ", ", string.Empty), - thisTypeName.Replace(thisType.FullName + ", ", string.Empty).Replace(".Portable", string.Empty), - }.Select(x => new AssemblyName(x)).ToArray(); + var toSearch = new[] + { + thisTypeName.Replace(thisType.FullName + ", ", string.Empty), + thisTypeName.Replace(thisType.FullName + ", ", string.Empty).Replace(".Portable", string.Empty), + }.Select(x => new AssemblyName(x)).ToArray(); - foreach (var assembly in toSearch) + foreach (var assembly in toSearch) + { + var fullName = fullTypeName + ", " + assembly.FullName; + var type = Type.GetType(fullName, false); + if (type is null) { - var fullName = fullTypeName + ", " + assembly.FullName; - var type = Type.GetType(fullName, false); - if (type is null) - { - continue; - } - - return (T?)Activator.CreateInstance(type); + continue; } - return default; + return (T?)Activator.CreateInstance(type); } + + return default; } } diff --git a/src/Splat/Disposables/ActionDisposable.cs b/src/Splat/Disposables/ActionDisposable.cs index 558cec1b3..4f587e27d 100644 --- a/src/Splat/Disposables/ActionDisposable.cs +++ b/src/Splat/Disposables/ActionDisposable.cs @@ -6,29 +6,28 @@ using System; using System.Threading; -namespace Splat +namespace Splat; + +/// +/// A disposable which will call the specified action. +/// +internal sealed class ActionDisposable : IDisposable { - /// - /// A disposable which will call the specified action. - /// - internal sealed class ActionDisposable : IDisposable - { - private Action _block; + private Action _block; - public ActionDisposable(Action block) - { - _block = block; - } + public ActionDisposable(Action block) + { + _block = block; + } - /// - /// Gets a action disposable which does nothing. - /// - public static IDisposable Empty => new ActionDisposable(() => { }); + /// + /// Gets a action disposable which does nothing. + /// + public static IDisposable Empty => new ActionDisposable(() => { }); - /// - public void Dispose() - { - Interlocked.Exchange(ref _block, () => { })(); - } + /// + public void Dispose() + { + Interlocked.Exchange(ref _block, () => { })(); } } diff --git a/src/Splat/Disposables/BooleanDisposable.cs b/src/Splat/Disposables/BooleanDisposable.cs index 78267d22a..50e53ce6e 100644 --- a/src/Splat/Disposables/BooleanDisposable.cs +++ b/src/Splat/Disposables/BooleanDisposable.cs @@ -4,44 +4,39 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Splat +namespace Splat; + +/// +/// Represents a disposable resource that can be checked for disposal status. +/// Based on the System.Reactive.Disposable class. +/// +internal sealed class BooleanDisposable : IDisposable { + private volatile bool _isDisposed; + /// - /// Represents a disposable resource that can be checked for disposal status. - /// Based on the System.Reactive.Disposable class. + /// Initializes a new instance of the class. /// - internal sealed class BooleanDisposable : IDisposable + public BooleanDisposable() { - private volatile bool _isDisposed; - - /// - /// Initializes a new instance of the class. - /// - public BooleanDisposable() - { - } + } - private BooleanDisposable(bool isDisposed) - { - _isDisposed = isDisposed; - } + private BooleanDisposable(bool isDisposed) + { + _isDisposed = isDisposed; + } - /// - /// Gets a value indicating whether the object is disposed. - /// - public bool IsDisposed => _isDisposed; + /// + /// Gets a value indicating whether the object is disposed. + /// + public bool IsDisposed => _isDisposed; - /// - /// Sets the status to disposed, which can be observer through the property. - /// - public void Dispose() - { - _isDisposed = true; - } + /// + /// Sets the status to disposed, which can be observer through the property. + /// + public void Dispose() + { + _isDisposed = true; } } diff --git a/src/Splat/Disposables/CompositeDisposable.cs b/src/Splat/Disposables/CompositeDisposable.cs index 4720624ee..238b875b9 100644 --- a/src/Splat/Disposables/CompositeDisposable.cs +++ b/src/Splat/Disposables/CompositeDisposable.cs @@ -7,141 +7,140 @@ using System.Collections.Generic; using System.Threading; -namespace Splat +namespace Splat; + +/// +/// Represents a group of disposable resources that are disposed together. +/// This is a simplified version based on System.Reactive's one. +/// +internal sealed class CompositeDisposable : IDisposable { + // Default initial capacity of the _disposables list in case + // The number of items is not known upfront + private const int DefaultCapacity = 16; + + private bool _disposed; + private List? _disposables; + private int _count; + + /// + /// Initializes a new instance of the class with no disposables contained by it initially. + /// + public CompositeDisposable() + { + _disposables = new List(); + } + /// - /// Represents a group of disposable resources that are disposed together. - /// This is a simplified version based on System.Reactive's one. + /// Initializes a new instance of the class with the specified number of disposables. /// - internal sealed class CompositeDisposable : IDisposable + /// The number of disposables that the new CompositeDisposable can initially store. + /// is less than zero. + public CompositeDisposable(int capacity) { - // Default initial capacity of the _disposables list in case - // The number of items is not known upfront - private const int DefaultCapacity = 16; - - private bool _disposed; - private List? _disposables; - private int _count; - - /// - /// Initializes a new instance of the class with no disposables contained by it initially. - /// - public CompositeDisposable() + if (capacity < 0) { - _disposables = new List(); + throw new ArgumentOutOfRangeException(nameof(capacity)); } - /// - /// Initializes a new instance of the class with the specified number of disposables. - /// - /// The number of disposables that the new CompositeDisposable can initially store. - /// is less than zero. - public CompositeDisposable(int capacity) - { - if (capacity < 0) - { - throw new ArgumentOutOfRangeException(nameof(capacity)); - } + _disposables = new List(capacity); + } - _disposables = new List(capacity); + /// + /// Initializes a new instance of the class from a group of disposables. + /// + /// Disposables that will be disposed together. + /// is null. + /// Any of the disposables in the collection is null. + public CompositeDisposable(params IDisposable[] disposables) + { + if (disposables is null) + { + throw new ArgumentNullException(nameof(disposables)); } - /// - /// Initializes a new instance of the class from a group of disposables. - /// - /// Disposables that will be disposed together. - /// is null. - /// Any of the disposables in the collection is null. - public CompositeDisposable(params IDisposable[] disposables) + _disposables = new List(disposables.Length); + Init(disposables); + } + + /// + /// Initializes a new instance of the class from a group of disposables. + /// + /// Disposables that will be disposed together. + /// is null. + /// Any of the disposables in the collection is null. + public CompositeDisposable(IEnumerable disposables) + { + if (disposables is null) { - if (disposables is null) - { - throw new ArgumentNullException(nameof(disposables)); - } + throw new ArgumentNullException(nameof(disposables)); + } - _disposables = new List(disposables.Length); + // If the disposables is a collection, get its size + // and use it as a capacity hint for the copy. + if (disposables is ICollection c) + { + _disposables = new List(c.Count); Init(disposables); } - - /// - /// Initializes a new instance of the class from a group of disposables. - /// - /// Disposables that will be disposed together. - /// is null. - /// Any of the disposables in the collection is null. - public CompositeDisposable(IEnumerable disposables) + else { - if (disposables is null) - { - throw new ArgumentNullException(nameof(disposables)); - } + _disposables = new List(DefaultCapacity); - // If the disposables is a collection, get its size - // and use it as a capacity hint for the copy. - if (disposables is ICollection c) - { - _disposables = new List(c.Count); - Init(disposables); - } - else - { - _disposables = new List(DefaultCapacity); - - // Unknown sized disposables, use the default capacity hint - Init(disposables); - } + // Unknown sized disposables, use the default capacity hint + Init(disposables); } + } - /// - /// Disposes all disposables in the group and removes them from the group. - /// - public void Dispose() + /// + /// Disposes all disposables in the group and removes them from the group. + /// + public void Dispose() + { + if (_disposed) { - if (_disposed) - { - return; - } + return; + } - var disposables = Interlocked.Exchange(ref _disposables, null); + var disposables = Interlocked.Exchange(ref _disposables, null); - if (disposables is not null) + if (disposables is not null) + { + foreach (var disposed in disposables) { - foreach (var disposed in disposables) - { - disposed.Dispose(); - } + disposed.Dispose(); } - - Volatile.Write(ref _count, 0); - Volatile.Write(ref _disposed, true); } - /// - /// Initialize the inner disposable list and count fields. - /// - /// The enumerable sequence of disposables. - private void Init(IEnumerable disposables) + Volatile.Write(ref _count, 0); + Volatile.Write(ref _disposed, true); + } + + /// + /// Initialize the inner disposable list and count fields. + /// + /// The enumerable sequence of disposables. + private void Init(IEnumerable disposables) + { + if (_disposables is null) { - if (_disposables is null) - { - return; - } + return; + } - // do the copy and null-check in one step to avoid a - // second loop for just checking for null items - foreach (var d in disposables) + // do the copy and null-check in one step to avoid a + // second loop for just checking for null items + foreach (var d in disposables) + { + if (d is null) { - if (d is null) - { - throw new ArgumentException("disposables for some reason are null", nameof(disposables)); - } - - _disposables.Add(d); + throw new ArgumentException("disposables for some reason are null", nameof(disposables)); } - // _count can be read by other threads and thus should be properly visible - // also releases the _disposables contents so it becomes thread-safe - Volatile.Write(ref _count, _disposables.Count); + _disposables.Add(d); } + + // _count can be read by other threads and thus should be properly visible + // also releases the _disposables contents so it becomes thread-safe + Volatile.Write(ref _count, _disposables.Count); } } diff --git a/src/Splat/Logging/ActionLogger.cs b/src/Splat/Logging/ActionLogger.cs index 0514111d8..a3e8f658a 100644 --- a/src/Splat/Logging/ActionLogger.cs +++ b/src/Splat/Logging/ActionLogger.cs @@ -6,62 +6,61 @@ using System; using System.ComponentModel; -namespace Splat +namespace Splat; + +/// +/// A logger where you pass in Action delegates that will be invoked when the Write methods are invoked. +/// +public class ActionLogger : ILogger { + private readonly Action _writeNoType; + private readonly Action _writeNoTypeWithException; + private readonly Action _writeWithType; + private readonly Action _writeWithTypeAndException; + /// - /// A logger where you pass in Action delegates that will be invoked when the Write methods are invoked. + /// Initializes a new instance of the class. /// - public class ActionLogger : ILogger + /// A action which is called when the is called. + /// A action which is called when the is called. + /// A action which is called when the is called. + /// A action which is called when the is called. + public ActionLogger( + Action writeNoType, + Action writeWithType, + Action writeNoTypeWithException, + Action writeWithTypeAndException) { - private readonly Action _writeNoType; - private readonly Action _writeNoTypeWithException; - private readonly Action _writeWithType; - private readonly Action _writeWithTypeAndException; - - /// - /// Initializes a new instance of the class. - /// - /// A action which is called when the is called. - /// A action which is called when the is called. - /// A action which is called when the is called. - /// A action which is called when the is called. - public ActionLogger( - Action writeNoType, - Action writeWithType, - Action writeNoTypeWithException, - Action writeWithTypeAndException) - { - _writeNoType = writeNoType; - _writeWithType = writeWithType; - _writeNoTypeWithException = writeNoTypeWithException; - _writeWithTypeAndException = writeWithTypeAndException; - } + _writeNoType = writeNoType; + _writeWithType = writeWithType; + _writeNoTypeWithException = writeNoTypeWithException; + _writeWithTypeAndException = writeWithTypeAndException; + } - /// - public LogLevel Level { get; set; } + /// + public LogLevel Level { get; set; } - /// - public void Write([Localizable(false)] string message, LogLevel logLevel) - { - _writeNoType?.Invoke(message, logLevel); - } + /// + public void Write([Localizable(false)] string message, LogLevel logLevel) + { + _writeNoType?.Invoke(message, logLevel); + } - /// - public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) - { - _writeNoTypeWithException?.Invoke(exception, message, logLevel); - } + /// + public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) + { + _writeNoTypeWithException?.Invoke(exception, message, logLevel); + } - /// - public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - _writeWithType?.Invoke(message, type, logLevel); - } + /// + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + _writeWithType?.Invoke(message, type, logLevel); + } - /// - public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - _writeWithTypeAndException?.Invoke(exception, message, type, logLevel); - } + /// + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + _writeWithTypeAndException?.Invoke(exception, message, type, logLevel); } } diff --git a/src/Splat/Logging/AllocationFreeLoggerBase.cs b/src/Splat/Logging/AllocationFreeLoggerBase.cs index 1c628181e..2600552a2 100644 --- a/src/Splat/Logging/AllocationFreeLoggerBase.cs +++ b/src/Splat/Logging/AllocationFreeLoggerBase.cs @@ -8,2473 +8,2472 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; -namespace Splat +namespace Splat; + +/// +/// Base class for a logger the provides allocation free logging. +/// +/// +[SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] +public abstract class AllocationFreeLoggerBase : IAllocationFreeLogger { + private readonly ILogger _inner; + /// - /// Base class for a logger the provides allocation free logging. + /// Initializes a new instance of the class. /// - /// - [SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] - public abstract class AllocationFreeLoggerBase : IAllocationFreeLogger + /// The to wrap in this class. + protected AllocationFreeLoggerBase(ILogger inner) + { + _inner = inner; + } + + /// + public LogLevel Level => _inner.Level; + + /// + public bool IsDebugEnabled => Level <= LogLevel.Debug; + + /// + public bool IsInfoEnabled => Level <= LogLevel.Info; + + /// + public bool IsWarnEnabled => Level <= LogLevel.Warn; + + /// + public bool IsErrorEnabled => Level <= LogLevel.Error; + + /// + public bool IsFatalEnabled => Level <= LogLevel.Fatal; + + /// + public virtual void Debug([Localizable(false)] string messageFormat, TArgument argument) + { + if (IsDebugEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Debug); + } + } + + /// + public virtual void Debug(Exception exception, string messageFormat, TArgument argument) + { + if (IsDebugEnabled) + { + _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Debug); + } + } + + /// + public virtual void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + if (IsDebugEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2) + { + if (IsDebugEnabled) + { + _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Debug); + } + } + + /// + public virtual void Debug( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Debug); + } + } + + /// + public virtual void Debug( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4), + LogLevel.Debug); + } + } + + /// + public virtual void Debug( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Debug); + } + } + + /// + public virtual void Debug( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Debug); + } + } + + /// + public virtual void Debug( + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Debug); + } + } + + /// + public virtual void Debug( + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Debug); + } + } + + /// + public virtual void Debug( + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Debug); + } + } + + /// + public virtual void Debug( + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsDebugEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Debug); + } + } + + /// + public void Debug( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsDebugEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Debug); + } + } + + /// + public virtual void Info([Localizable(false)] string messageFormat, TArgument argument) + { + if (IsInfoEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Info); + } + } + + /// + public void Info(Exception exception, string messageFormat, TArgument argument) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format(CultureInfo.InvariantCulture, messageFormat, argument), + LogLevel.Info); + } + } + + /// + public virtual void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + if (IsInfoEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Info); + } + } + + /// + public virtual void Info( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsInfoEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Info); + } + } + + /// + public void Info( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsInfoEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Info); + } + } + + /// + public virtual void Warn([Localizable(false)] string messageFormat, TArgument argument) + { + if (IsWarnEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Warn); + } + } + + /// + public void Warn(Exception exception, string messageFormat, TArgument argument) + { + if (IsWarnEnabled) + { + _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Warn); + } + } + + /// + public virtual void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + if (IsWarnEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2) + { + if (IsWarnEnabled) + { + _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4), + LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Warn); + } + } + + /// + public virtual void Warn( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsWarnEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Warn); + } + } + + /// + public void Warn( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) { - private readonly ILogger _inner; + if (IsWarnEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Warn); + } + } - /// - /// Initializes a new instance of the class. - /// - /// The to wrap in this class. - protected AllocationFreeLoggerBase(ILogger inner) + /// + public virtual void Error([Localizable(false)] string messageFormat, TArgument argument) + { + if (IsErrorEnabled) { - _inner = inner; + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Error); } + } - /// - public LogLevel Level => _inner.Level; + /// + public void Error(Exception exception, string messageFormat, TArgument argument) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format(CultureInfo.InvariantCulture, messageFormat, argument), + LogLevel.Error); + } + } - /// - public bool IsDebugEnabled => Level <= LogLevel.Debug; + /// + public virtual void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + if (IsErrorEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Error); + } + } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2), + LogLevel.Error); + } + } + + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Error); + } + } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3), + LogLevel.Error); + } + } - /// - public bool IsInfoEnabled => Level <= LogLevel.Info; - - /// - public bool IsWarnEnabled => Level <= LogLevel.Warn; + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), + LogLevel.Error); + } + } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4), + LogLevel.Error); + } + } - /// - public bool IsErrorEnabled => Level <= LogLevel.Error; + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Error); + } + } - /// - public bool IsFatalEnabled => Level <= LogLevel.Fatal; - - /// - public virtual void Debug([Localizable(false)] string messageFormat, TArgument argument) - { - if (IsDebugEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Debug); - } - } - - /// - public virtual void Debug(Exception exception, string messageFormat, TArgument argument) - { - if (IsDebugEnabled) - { - _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Debug); - } - } - - /// - public virtual void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - if (IsDebugEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2) - { - if (IsDebugEnabled) - { - _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Debug); - } - } - - /// - public virtual void Debug( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Debug); - } - } - - /// - public virtual void Debug( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4), - LogLevel.Debug); - } - } - - /// - public virtual void Debug( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Debug); - } - } - - /// - public virtual void Debug( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Debug); - } - } - - /// - public virtual void Debug( - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Debug); - } - } - - /// - public virtual void Debug( - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Debug); - } - } - - /// - public virtual void Debug( - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Debug); - } - } - - /// - public virtual void Debug( - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsDebugEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Debug); - } - } - - /// - public void Debug( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsDebugEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Debug); - } - } - - /// - public virtual void Info([Localizable(false)] string messageFormat, TArgument argument) - { - if (IsInfoEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Info); - } - } - - /// - public void Info(Exception exception, string messageFormat, TArgument argument) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format(CultureInfo.InvariantCulture, messageFormat, argument), - LogLevel.Info); - } - } - - /// - public virtual void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - if (IsInfoEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Info); - } - } - - /// - public virtual void Info( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsInfoEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Info); - } - } - - /// - public void Info( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsInfoEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Info); - } - } - - /// - public virtual void Warn([Localizable(false)] string messageFormat, TArgument argument) - { - if (IsWarnEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Warn); - } - } - - /// - public void Warn(Exception exception, string messageFormat, TArgument argument) - { - if (IsWarnEnabled) - { - _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Warn); - } - } - - /// - public virtual void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - if (IsWarnEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2) - { - if (IsWarnEnabled) - { - _inner.Write(exception, string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4), - LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Warn); - } - } - - /// - public virtual void Warn( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsWarnEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Warn); - } - } - - /// - public void Warn( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsWarnEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Warn); - } - } - - /// - public virtual void Error([Localizable(false)] string messageFormat, TArgument argument) - { - if (IsErrorEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Error); - } - } - - /// - public void Error(Exception exception, string messageFormat, TArgument argument) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format(CultureInfo.InvariantCulture, messageFormat, argument), - LogLevel.Error); - } - } - - /// - public virtual void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - if (IsErrorEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Error); - } - } - - /// - public virtual void Error( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsErrorEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Error); - } - } - - /// - public void Error( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsErrorEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Error); - } - } - - /// - public virtual void Fatal([Localizable(false)] string messageFormat, TArgument argument) - { - if (IsFatalEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Fatal); - } - } - - /// - public void Fatal(Exception exception, string messageFormat, TArgument argument) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format(CultureInfo.InvariantCulture, messageFormat, argument), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) - { - if (IsFatalEnabled) - { - _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9), - LogLevel.Fatal); - } - } - - /// - public virtual void Fatal( - [Localizable(false)] string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsFatalEnabled) - { - _inner.Write( - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Fatal); - } - } - - /// - public void Fatal( - Exception exception, - string messageFormat, - TArgument1 argument1, - TArgument2 argument2, - TArgument3 argument3, - TArgument4 argument4, - TArgument5 argument5, - TArgument6 argument6, - TArgument7 argument7, - TArgument8 argument8, - TArgument9 argument9, - TArgument10 argument10) - { - if (IsFatalEnabled) - { - _inner.Write( - exception, - string.Format( - CultureInfo.InvariantCulture, - messageFormat, - argument1, - argument2, - argument3, - argument4, - argument5, - argument6, - argument7, - argument8, - argument9, - argument10), - LogLevel.Fatal); - } - } - - /// - public void Write([Localizable(false)] string message, LogLevel logLevel) - { - _inner.Write(message, logLevel); - } - - /// - public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) - { - _inner.Write(exception, message, logLevel); - } - - /// - public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - _inner.Write(message, type, logLevel); - } - - /// - public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - _inner.Write(exception, message, type, logLevel); + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Error); + } + } + + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Error); + } + } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Error); + } + } + + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Error); + } + } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Error); + } + } + + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Error); + } + } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Error); + } + } + + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Error); } } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Error); + } + } + + /// + public virtual void Error( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsErrorEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Error); + } + } + + /// + public void Error( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsErrorEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Error); + } + } + + /// + public virtual void Fatal([Localizable(false)] string messageFormat, TArgument argument) + { + if (IsFatalEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument), LogLevel.Fatal); + } + } + + /// + public void Fatal(Exception exception, string messageFormat, TArgument argument) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format(CultureInfo.InvariantCulture, messageFormat, argument), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) + { + if (IsFatalEnabled) + { + _inner.Write(string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2), LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format(CultureInfo.InvariantCulture, messageFormat, argument1, argument2, argument3, argument4), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9), + LogLevel.Fatal); + } + } + + /// + public virtual void Fatal( + [Localizable(false)] string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsFatalEnabled) + { + _inner.Write( + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Fatal); + } + } + + /// + public void Fatal( + Exception exception, + string messageFormat, + TArgument1 argument1, + TArgument2 argument2, + TArgument3 argument3, + TArgument4 argument4, + TArgument5 argument5, + TArgument6 argument6, + TArgument7 argument7, + TArgument8 argument8, + TArgument9 argument9, + TArgument10 argument10) + { + if (IsFatalEnabled) + { + _inner.Write( + exception, + string.Format( + CultureInfo.InvariantCulture, + messageFormat, + argument1, + argument2, + argument3, + argument4, + argument5, + argument6, + argument7, + argument8, + argument9, + argument10), + LogLevel.Fatal); + } + } + + /// + public void Write([Localizable(false)] string message, LogLevel logLevel) + { + _inner.Write(message, logLevel); + } + + /// + public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) + { + _inner.Write(exception, message, logLevel); + } + + /// + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + _inner.Write(message, type, logLevel); + } + + /// + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + _inner.Write(exception, message, type, logLevel); + } } diff --git a/src/Splat/Logging/ConsoleLogger.cs b/src/Splat/Logging/ConsoleLogger.cs index 43692b9a1..36121f22b 100644 --- a/src/Splat/Logging/ConsoleLogger.cs +++ b/src/Splat/Logging/ConsoleLogger.cs @@ -7,64 +7,63 @@ using System.ComponentModel; using System.Globalization; -namespace Splat +namespace Splat; + +/// +/// A logger which will send messages to the console. +/// +public class ConsoleLogger : ILogger { /// - /// A logger which will send messages to the console. + /// Gets or sets the exception message format. + /// First parameter will be the message, second will be the exception. /// - public class ConsoleLogger : ILogger - { - /// - /// Gets or sets the exception message format. - /// First parameter will be the message, second will be the exception. - /// - public string ExceptionMessageFormat { get; set; } = "{0} - {1}"; + public string ExceptionMessageFormat { get; set; } = "{0} - {1}"; - /// - public LogLevel Level { get; set; } + /// + public LogLevel Level { get; set; } - /// - public void Write([Localizable(false)] string message, LogLevel logLevel) + /// + public void Write([Localizable(false)] string message, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) { - if ((int)logLevel < (int)Level) - { - return; - } - - Console.WriteLine(message); + return; } - /// - public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) - { - if ((int)logLevel < (int)Level) - { - return; - } + Console.WriteLine(message); + } - Console.WriteLine(string.Format(CultureInfo.InvariantCulture, ExceptionMessageFormat, message, exception)); + /// + public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) + { + return; } - /// - public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - if ((int)logLevel < (int)Level) - { - return; - } + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, ExceptionMessageFormat, message, exception)); + } - Console.WriteLine(message); + /// + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) + { + return; } - /// - public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - if ((int)logLevel < (int)Level) - { - return; - } + Console.WriteLine(message); + } - Console.WriteLine(string.Format(CultureInfo.InvariantCulture, ExceptionMessageFormat, message, exception)); + /// + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) + { + return; } + + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, ExceptionMessageFormat, message, exception)); } } diff --git a/src/Splat/Logging/DebugLogger.cs b/src/Splat/Logging/DebugLogger.cs index edae3da7d..4d18c76be 100644 --- a/src/Splat/Logging/DebugLogger.cs +++ b/src/Splat/Logging/DebugLogger.cs @@ -11,58 +11,57 @@ using System; using System.ComponentModel; -namespace Splat +namespace Splat; + +/// +/// A logger which will send messages to the debug logger. +/// +public class DebugLogger : ILogger { - /// - /// A logger which will send messages to the debug logger. - /// - public class DebugLogger : ILogger - { - /// - public LogLevel Level { get; set; } + /// + public LogLevel Level { get; set; } - /// - public void Write([Localizable(false)] string message, LogLevel logLevel) + /// + public void Write([Localizable(false)] string message, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) { - if ((int)logLevel < (int)Level) - { - return; - } - - System.Diagnostics.Debug.WriteLine(message); + return; } - /// - public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) - { - if ((int)logLevel < (int)Level) - { - return; - } + System.Diagnostics.Debug.WriteLine(message); + } - System.Diagnostics.Debug.WriteLine($"{message} - {exception}"); + /// + public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) + { + return; } - /// - public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - if ((int)logLevel < (int)Level) - { - return; - } + System.Diagnostics.Debug.WriteLine($"{message} - {exception}"); + } - System.Diagnostics.Debug.WriteLine(message, type?.Name); + /// + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) + { + return; } - /// - public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - if ((int)logLevel < (int)Level) - { - return; - } + System.Diagnostics.Debug.WriteLine(message, type?.Name); + } - System.Diagnostics.Debug.WriteLine($"{message} - {exception}", type?.Name); + /// + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + if ((int)logLevel < (int)Level) + { + return; } + + System.Diagnostics.Debug.WriteLine($"{message} - {exception}", type?.Name); } } diff --git a/src/Splat/Logging/DefaultLogManager.cs b/src/Splat/Logging/DefaultLogManager.cs index 465be09c0..10d9f0b82 100644 --- a/src/Splat/Logging/DefaultLogManager.cs +++ b/src/Splat/Logging/DefaultLogManager.cs @@ -5,52 +5,51 @@ using System; -namespace Splat +namespace Splat; + +/// +/// The default log manager provided by splat. +/// This log manager will cache the loggers for each type, +/// This will use the default registered inside the . +/// +public sealed class DefaultLogManager : ILogManager { + private static readonly IFullLogger _nullLogger = new WrappingFullLogger(new NullLogger()); + private readonly MemoizingMRUCache _loggerCache; + /// - /// The default log manager provided by splat. - /// This log manager will cache the loggers for each type, - /// This will use the default registered inside the . + /// Initializes a new instance of the class. /// - public sealed class DefaultLogManager : ILogManager + /// A dependency resolver for testing purposes, will use the default Locator if null. + public DefaultLogManager(IReadonlyDependencyResolver? dependencyResolver = null) { - private static readonly IFullLogger _nullLogger = new WrappingFullLogger(new NullLogger()); - private readonly MemoizingMRUCache _loggerCache; - - /// - /// Initializes a new instance of the class. - /// - /// A dependency resolver for testing purposes, will use the default Locator if null. - public DefaultLogManager(IReadonlyDependencyResolver? dependencyResolver = null) - { - dependencyResolver = dependencyResolver ?? Locator.Current; + dependencyResolver = dependencyResolver ?? Locator.Current; - _loggerCache = new MemoizingMRUCache( - (type, _) => + _loggerCache = new MemoizingMRUCache( + (type, _) => + { + var ret = dependencyResolver.GetService(); + if (ret is null) { - var ret = dependencyResolver.GetService(); - if (ret is null) - { - throw new LoggingException("Couldn't find an ILogger. This should never happen, your dependency resolver is probably broken."); - } - - return new WrappingFullLogger(new WrappingPrefixLogger(ret, type)); - }, - 64); - } + throw new LoggingException("Couldn't find an ILogger. This should never happen, your dependency resolver is probably broken."); + } + + return new WrappingFullLogger(new WrappingPrefixLogger(ret, type)); + }, + 64); + } - /// - public IFullLogger GetLogger(Type type) + /// + public IFullLogger GetLogger(Type type) + { + if (type == typeof(MemoizingMRUCache)) { - if (type == typeof(MemoizingMRUCache)) - { - return _nullLogger; - } + return _nullLogger; + } - lock (_loggerCache) - { - return _loggerCache.Get(type); - } + lock (_loggerCache) + { + return _loggerCache.Get(type); } } } diff --git a/src/Splat/Logging/FullLoggerExtensions.cs b/src/Splat/Logging/FullLoggerExtensions.cs index 4e785bdb1..81643a890 100644 --- a/src/Splat/Logging/FullLoggerExtensions.cs +++ b/src/Splat/Logging/FullLoggerExtensions.cs @@ -4,378 +4,376 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Diagnostics.CodeAnalysis; -namespace Splat +namespace Splat; + +/// +/// Provides extension methods to the interface. +/// +public static class FullLoggerExtensions { /// - /// Provides extension methods to the interface. + /// Sends the value provided by the provided delegate, only if Debug is enabled. + /// + /// The logger to use. + /// The function to evaluate if Debug logging is enabled. + public static void Debug(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsDebugEnabled) + { + logger.Debug(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Debug is enabled. + /// + /// The type of object we are logging about. + /// The logger to use. + /// The function to evaluate if Debug logging is enabled. + public static void Debug(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsDebugEnabled) + { + logger.Debug(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Debug is enabled. /// - public static class FullLoggerExtensions + /// The logger to use. + /// The function to evaluate if Debug logging is enabled. + /// A exception to log about. + public static void DebugException(this IFullLogger logger, Func function, Exception exception) { - /// - /// Sends the value provided by the provided delegate, only if Debug is enabled. - /// - /// The logger to use. - /// The function to evaluate if Debug logging is enabled. - public static void Debug(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsDebugEnabled) - { - logger.Debug(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Debug is enabled. - /// - /// The type of object we are logging about. - /// The logger to use. - /// The function to evaluate if Debug logging is enabled. - public static void Debug(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsDebugEnabled) - { - logger.Debug(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Debug is enabled. - /// - /// The logger to use. - /// The function to evaluate if Debug logging is enabled. - /// A exception to log about. - public static void DebugException(this IFullLogger logger, Func function, Exception exception) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsDebugEnabled) - { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsDebugEnabled) + { #pragma warning disable CS0618 // Type or member is obsolete - logger.DebugException(function.Invoke(), exception); + logger.DebugException(function.Invoke(), exception); #pragma warning restore CS0618 // Type or member is obsolete - } - } - - /// - /// Sends the value provided by the provided delegate, only if Debug is enabled. - /// - /// The logger to use. - /// The function to evaluate if Debug logging is enabled. - public static void Info(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsInfoEnabled) - { - logger.Info(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Debug is enabled. - /// - /// The type of object we are logging about. - /// The logger to use. - /// The function to evaluate if Debug logging is enabled. - public static void Info(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsInfoEnabled) - { - logger.Info(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Info is enabled. - /// - /// The logger to use. - /// The function to evaluate if Info logging is enabled. - /// A exception to log about. - public static void InfoException(this IFullLogger logger, Func function, Exception exception) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsInfoEnabled) - { + } + } + + /// + /// Sends the value provided by the provided delegate, only if Debug is enabled. + /// + /// The logger to use. + /// The function to evaluate if Debug logging is enabled. + public static void Info(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsInfoEnabled) + { + logger.Info(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Debug is enabled. + /// + /// The type of object we are logging about. + /// The logger to use. + /// The function to evaluate if Debug logging is enabled. + public static void Info(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsInfoEnabled) + { + logger.Info(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Info is enabled. + /// + /// The logger to use. + /// The function to evaluate if Info logging is enabled. + /// A exception to log about. + public static void InfoException(this IFullLogger logger, Func function, Exception exception) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsInfoEnabled) + { #pragma warning disable CS0618 // Type or member is obsolete - logger.InfoException(function.Invoke(), exception); + logger.InfoException(function.Invoke(), exception); #pragma warning restore CS0618 // Type or member is obsolete - } - } - - /// - /// Sends the value provided by the provided delegate, only if Warn is enabled. - /// - /// The logger to use. - /// The function to evaluate if Warn logging is enabled. - public static void Warn(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsWarnEnabled) - { - logger.Warn(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Warn is enabled. - /// - /// The type of object we are logging about. - /// The logger to use. - /// The function to evaluate if Warn logging is enabled. - public static void Warn(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsWarnEnabled) - { - logger.Warn(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Warn is enabled. - /// - /// The logger to use. - /// The function to evaluate if Warn logging is enabled. - /// A exception to log about. - public static void WarnException(this IFullLogger logger, Func function, Exception exception) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsWarnEnabled) - { + } + } + + /// + /// Sends the value provided by the provided delegate, only if Warn is enabled. + /// + /// The logger to use. + /// The function to evaluate if Warn logging is enabled. + public static void Warn(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsWarnEnabled) + { + logger.Warn(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Warn is enabled. + /// + /// The type of object we are logging about. + /// The logger to use. + /// The function to evaluate if Warn logging is enabled. + public static void Warn(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsWarnEnabled) + { + logger.Warn(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Warn is enabled. + /// + /// The logger to use. + /// The function to evaluate if Warn logging is enabled. + /// A exception to log about. + public static void WarnException(this IFullLogger logger, Func function, Exception exception) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsWarnEnabled) + { #pragma warning disable CS0618 // Type or member is obsolete - logger.WarnException(function.Invoke(), exception); + logger.WarnException(function.Invoke(), exception); #pragma warning restore CS0618 // Type or member is obsolete - } - } - - /// - /// Sends the value provided by the provided delegate, only if Error is enabled. - /// - /// The logger to use. - /// The function to evaluate if Error logging is enabled. - public static void Error(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsErrorEnabled) - { - logger.Error(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Error is enabled. - /// - /// The type of object we are logging about. - /// The logger to use. - /// The function to evaluate if Error logging is enabled. - public static void Error(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsErrorEnabled) - { - logger.Error(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Error is enabled. - /// - /// The logger to use. - /// The function to evaluate if Error logging is enabled. - /// A exception to log about. - public static void ErrorException(this IFullLogger logger, Func function, Exception exception) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsErrorEnabled) - { + } + } + + /// + /// Sends the value provided by the provided delegate, only if Error is enabled. + /// + /// The logger to use. + /// The function to evaluate if Error logging is enabled. + public static void Error(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsErrorEnabled) + { + logger.Error(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Error is enabled. + /// + /// The type of object we are logging about. + /// The logger to use. + /// The function to evaluate if Error logging is enabled. + public static void Error(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsErrorEnabled) + { + logger.Error(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Error is enabled. + /// + /// The logger to use. + /// The function to evaluate if Error logging is enabled. + /// A exception to log about. + public static void ErrorException(this IFullLogger logger, Func function, Exception exception) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsErrorEnabled) + { #pragma warning disable CS0618 // Type or member is obsolete - logger.ErrorException(function.Invoke(), exception); + logger.ErrorException(function.Invoke(), exception); #pragma warning restore CS0618 // Type or member is obsolete - } - } - - /// - /// Sends the value provided by the provided delegate, only if Fatal is enabled. - /// - /// The logger to use. - /// The function to evaluate if Fatal logging is enabled. - public static void Fatal(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsFatalEnabled) - { - logger.Fatal(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Fatal is enabled. - /// - /// The type of object we are logging about. - /// The logger to use. - /// The function to evaluate if Fatal logging is enabled. - public static void Fatal(this IFullLogger logger, Func function) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsFatalEnabled) - { - logger.Fatal(function.Invoke()); - } - } - - /// - /// Sends the value provided by the provided delegate, only if Fatal is enabled. - /// - /// The logger to use. - /// The function to evaluate if Fatal logging is enabled. - /// A exception to log about. - public static void FatalException(this IFullLogger logger, Func function, Exception exception) - { - if (logger is null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - if (logger.IsFatalEnabled) - { + } + } + + /// + /// Sends the value provided by the provided delegate, only if Fatal is enabled. + /// + /// The logger to use. + /// The function to evaluate if Fatal logging is enabled. + public static void Fatal(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsFatalEnabled) + { + logger.Fatal(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Fatal is enabled. + /// + /// The type of object we are logging about. + /// The logger to use. + /// The function to evaluate if Fatal logging is enabled. + public static void Fatal(this IFullLogger logger, Func function) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsFatalEnabled) + { + logger.Fatal(function.Invoke()); + } + } + + /// + /// Sends the value provided by the provided delegate, only if Fatal is enabled. + /// + /// The logger to use. + /// The function to evaluate if Fatal logging is enabled. + /// A exception to log about. + public static void FatalException(this IFullLogger logger, Func function, Exception exception) + { + if (logger is null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (function is null) + { + throw new ArgumentNullException(nameof(function)); + } + + if (logger.IsFatalEnabled) + { #pragma warning disable CS0618 // Type or member is obsolete - logger.ErrorException(function.Invoke(), exception); + logger.ErrorException(function.Invoke(), exception); #pragma warning restore CS0618 // Type or member is obsolete - } } } } diff --git a/src/Splat/Logging/FuncLogManager.cs b/src/Splat/Logging/FuncLogManager.cs index d04f494eb..e642d2195 100644 --- a/src/Splat/Logging/FuncLogManager.cs +++ b/src/Splat/Logging/FuncLogManager.cs @@ -5,28 +5,27 @@ using System; -namespace Splat +namespace Splat; + +/// +/// A log manager which will generate the by using the specified Func. +/// +public class FuncLogManager : ILogManager { + private readonly Func _inner; + /// - /// A log manager which will generate the by using the specified Func. + /// Initializes a new instance of the class. /// - public class FuncLogManager : ILogManager + /// The function which will be used to generate the . + public FuncLogManager(Func getLoggerFunc) { - private readonly Func _inner; - - /// - /// Initializes a new instance of the class. - /// - /// The function which will be used to generate the . - public FuncLogManager(Func getLoggerFunc) - { - _inner = getLoggerFunc; - } + _inner = getLoggerFunc; + } - /// - public IFullLogger GetLogger(Type type) - { - return _inner(type); - } + /// + public IFullLogger GetLogger(Type type) + { + return _inner(type); } } diff --git a/src/Splat/Logging/IAllocationFreeErrorLogger.cs b/src/Splat/Logging/IAllocationFreeErrorLogger.cs index 666a1b21a..d1cc5f512 100644 --- a/src/Splat/Logging/IAllocationFreeErrorLogger.cs +++ b/src/Splat/Logging/IAllocationFreeErrorLogger.cs @@ -7,914 +7,913 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -namespace Splat +namespace Splat; + +/// +/// An allocation free exception logger which wraps all the possible logging methods available. +/// Often not needed for your own loggers. +/// A will wrap simple loggers into a full logger. +/// +[SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] +public interface IAllocationFreeErrorLogger : ILogger { /// - /// An allocation free exception logger which wraps all the possible logging methods available. - /// Often not needed for your own loggers. - /// A will wrap simple loggers into a full logger. - /// - [SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] - public interface IAllocationFreeErrorLogger : ILogger - { - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Logs a info message with the provided message format and values. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Logs a info message with the provided message format and values. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The exception. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - } + /// Emits a message using formatting to the debug log. + /// + /// The type of the argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Debug(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Logs a info message with the provided message format and values. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Logs a info message with the provided message format and values. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Info(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Warn(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Error(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The exception. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Fatal(Exception exception, [Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); } diff --git a/src/Splat/Logging/IAllocationFreeLogger.cs b/src/Splat/Logging/IAllocationFreeLogger.cs index d23d8c32b..2833f1c2f 100644 --- a/src/Splat/Logging/IAllocationFreeLogger.cs +++ b/src/Splat/Logging/IAllocationFreeLogger.cs @@ -3,893 +3,891 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -namespace Splat +namespace Splat; + +/// +/// An allocation free logger which wraps all the possible logging methods available. +/// Often not needed for your own loggers. +/// A will wrap simple loggers into a full logger. +/// +[SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] +public interface IAllocationFreeLogger : IAllocationFreeErrorLogger { /// - /// An allocation free logger which wraps all the possible logging methods available. - /// Often not needed for your own loggers. - /// A will wrap simple loggers into a full logger. - /// - [SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] - public interface IAllocationFreeLogger : IAllocationFreeErrorLogger - { - /// - /// Gets a value indicating whether the logger currently emits debug logs. - /// - bool IsDebugEnabled { get; } - - /// - /// Gets a value indicating whether the logger currently emits information logs. - /// - bool IsInfoEnabled { get; } - - /// - /// Gets a value indicating whether the logger currently emits warning logs. - /// - bool IsWarnEnabled { get; } - - /// - /// Gets a value indicating whether the logger currently emits error logs. - /// - bool IsErrorEnabled { get; } - - /// - /// Gets a value indicating whether the logger currently emits fatal logs. - /// - bool IsFatalEnabled { get; } - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Logs a info message with the provided message format and values. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Logs a info message with the provided message format and values. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the warn log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument argument); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The type of the fourth argument which is used in the formatting. - /// The type of the fifth argument which is used in the formatting. - /// The type of the sixth argument which is used in the formatting. - /// The type of the seventh argument which is used in the formatting. - /// The type of the eighth argument which is used in the formatting. - /// The type of the ninth argument which is used in the formatting. - /// The type of the tenth argument which is used in the formatting. - /// The message format used to emit a message with the type arguments. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// The fourth argument for formatting purposes. - /// The fifth argument for formatting purposes. - /// The sixth argument for formatting purposes. - /// The seventh argument for formatting purposes. - /// The eighth argument for formatting purposes. - /// The ninth argument for formatting purposes. - /// The tenth argument for formatting purposes. - void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); - } + /// Gets a value indicating whether the logger currently emits debug logs. + /// + bool IsDebugEnabled { get; } + + /// + /// Gets a value indicating whether the logger currently emits information logs. + /// + bool IsInfoEnabled { get; } + + /// + /// Gets a value indicating whether the logger currently emits warning logs. + /// + bool IsWarnEnabled { get; } + + /// + /// Gets a value indicating whether the logger currently emits error logs. + /// + bool IsErrorEnabled { get; } + + /// + /// Gets a value indicating whether the logger currently emits fatal logs. + /// + bool IsFatalEnabled { get; } + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Logs a info message with the provided message format and values. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Logs a info message with the provided message format and values. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the warn log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument argument); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The type of the fourth argument which is used in the formatting. + /// The type of the fifth argument which is used in the formatting. + /// The type of the sixth argument which is used in the formatting. + /// The type of the seventh argument which is used in the formatting. + /// The type of the eighth argument which is used in the formatting. + /// The type of the ninth argument which is used in the formatting. + /// The type of the tenth argument which is used in the formatting. + /// The message format used to emit a message with the type arguments. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// The fourth argument for formatting purposes. + /// The fifth argument for formatting purposes. + /// The sixth argument for formatting purposes. + /// The seventh argument for formatting purposes. + /// The eighth argument for formatting purposes. + /// The ninth argument for formatting purposes. + /// The tenth argument for formatting purposes. + void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10); } diff --git a/src/Splat/Logging/IEnableLogger.cs b/src/Splat/Logging/IEnableLogger.cs index eea27f9f5..df9ee349d 100644 --- a/src/Splat/Logging/IEnableLogger.cs +++ b/src/Splat/Logging/IEnableLogger.cs @@ -6,16 +6,14 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; -namespace Splat +namespace Splat; + +/// +/// "Implement" this interface in your class to get access to the Log() +/// Mixin, which will give you a Logger that includes the class name in the +/// log. +/// +[ComVisible(false)] +public interface IEnableLogger { - /// - /// "Implement" this interface in your class to get access to the Log() - /// Mixin, which will give you a Logger that includes the class name in the - /// log. - /// - [SuppressMessage("Design", "CA1040: Avoid empty interfaces", Justification = "Deliberate use")] - [ComVisible(false)] - public interface IEnableLogger - { - } } diff --git a/src/Splat/Logging/IFullLogger.cs b/src/Splat/Logging/IFullLogger.cs index a752a1a09..aa39c5214 100644 --- a/src/Splat/Logging/IFullLogger.cs +++ b/src/Splat/Logging/IFullLogger.cs @@ -7,537 +7,536 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -namespace Splat +namespace Splat; + +/// +/// A full logger which wraps all the possible logging methods available. +/// Often not needed for your own loggers. +/// A will wrap simple loggers into a full logger. +/// +[SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] +public interface IFullLogger : IAllocationFreeLogger, IAllocationFreeErrorLogger { /// - /// A full logger which wraps all the possible logging methods available. - /// Often not needed for your own loggers. - /// A will wrap simple loggers into a full logger. - /// - [SuppressMessage("Naming", "CA1716: Do not use built in identifiers", Justification = "Deliberate usage")] - public interface IFullLogger : IAllocationFreeLogger, IAllocationFreeErrorLogger - { - /// - /// Emits a debug log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The log to emit. - void Debug(T value); - - /// - /// Emits a debug log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The format provider to use. - /// The value to emit. - void Debug(IFormatProvider formatProvider, T value); - - /// - /// Emits a debug log message. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// A message to emit. - /// The exception which to emit in the log. - [Obsolete("Use void Debug(Exception exception, [Localizable(false)] string? message)")] - void DebugException([Localizable(false)] string? message, Exception exception); - - /// - /// Emits a debug log message with an exception. - /// - /// The exception. - /// The message. - void Debug(Exception exception, [Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); - - /// - /// Emits a message to the debug log. - /// - /// A non-localizable message to send to the log. - void Debug([Localizable(false)] string? message); - - /// - /// Emits a message to the debug log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - void Debug([Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the debug log. - /// - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Debug([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The calling type. - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Debug([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a info log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The log to emit. - void Info(T value); - - /// - /// Emits a info log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The format provider to use. - /// The value to emit. - void Info(IFormatProvider formatProvider, T value); - - /// - /// Emits a info log message. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// A message to emit. - /// The exception which to emit in the log. - [Obsolete("Use void Info(Exception exception, [Localizable(false)] string? message)")] - void InfoException([Localizable(false)] string? message, Exception exception); - - /// - /// Emits a info log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - void Info(Exception exception, [Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the info log. - /// - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Info(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); - - /// - /// Emits a message to the info log. - /// - /// A non-localizable message to send to the log. - void Info([Localizable(false)] string? message); - - /// - /// Emits a message to the info log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - void Info([Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the info log. - /// - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Info([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the info log. - /// - /// The calling type. - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Info([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a warning log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The log to emit. - void Warn(T value); - - /// - /// Emits a warning log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The format provider to use. - /// The value to emit. - void Warn(IFormatProvider formatProvider, T value); - - /// - /// Emits a warning log message. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// A message to emit. - /// The exception which to emit in the log. - [Obsolete("Use void Warn(Exception exception, [Localizable(false)] string? message)")] - void WarnException([Localizable(false)] string? message, Exception exception); - - /// - /// Emits a warning log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - void Warn(Exception exception, [Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); - - /// - /// Emits a message to the warning log. - /// - /// A non-localizable message to send to the log. - void Warn([Localizable(false)] string? message); - - /// - /// Emits a message to the warning log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - void Warn([Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the warning log. - /// - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Warn([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The calling type. - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Warn([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a error log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The log to emit. - void Error(T value); - - /// - /// Emits a error log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The format provider to use. - /// The value to emit. - void Error(IFormatProvider formatProvider, T value); - - /// - /// Emits a error log message. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// A message to emit. - /// The exception which to emit in the log. - [Obsolete("Use void Error(Exception exception, [Localizable(false)] string? message)")] - void ErrorException([Localizable(false)] string? message, Exception exception); - - /// - /// Emits a error log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - void Error(Exception exception, [Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the error log. - /// - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Error(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); - - /// - /// Emits a message to the error log. - /// - /// A non-localizable message to send to the log. - void Error([Localizable(false)] string? message); - - /// - /// Emits a message to the error log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - void Error([Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the error log. - /// - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Error([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the error log. - /// - /// The calling type. - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Error([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - - /// - /// Emits a fatal log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The log to emit. - void Fatal(T value); - - /// - /// Emits a fatal log message. - /// This will emit the public contents of the object provided to the log. - /// - /// The type of object used as the message. - /// The format provider to use. - /// The value to emit. - void Fatal(IFormatProvider formatProvider, T value); - - /// - /// Emits a fatal log message. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// A message to emit. - /// The exception which to emit in the log. - [Obsolete("Use void Fatal(Exception exception, [Localizable(false)] string? message)")] - void FatalException([Localizable(false)] string? message, Exception exception); - - /// - /// Emits a fatal log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - void Fatal(Exception exception, [Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); - - /// - /// Emits a message to the fatal log. - /// - /// A non-localizable message to send to the log. - void Fatal([Localizable(false)] string? message); - - /// - /// Emits a message to the fatal log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - void Fatal([Localizable(false)] string? message); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Fatal([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The calling type. - /// A non-localizable message to emit to the log which includes the standard formatting tags. - /// The arguments for formatting purposes. - void Fatal([Localizable(false)] string message, params object[] args); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); - } + /// Emits a debug log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The log to emit. + void Debug(T value); + + /// + /// Emits a debug log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The format provider to use. + /// The value to emit. + void Debug(IFormatProvider formatProvider, T value); + + /// + /// Emits a debug log message. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// A message to emit. + /// The exception which to emit in the log. + [Obsolete("Use void Debug(Exception exception, [Localizable(false)] string? message)")] + void DebugException([Localizable(false)] string? message, Exception exception); + + /// + /// Emits a debug log message with an exception. + /// + /// The exception. + /// The message. + void Debug(Exception exception, [Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Emits a message to the debug log. + /// + /// A non-localizable message to send to the log. + void Debug([Localizable(false)] string? message); + + /// + /// Emits a message to the debug log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + void Debug([Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the debug log. + /// + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Debug([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The calling type. + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Debug([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a info log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The log to emit. + void Info(T value); + + /// + /// Emits a info log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The format provider to use. + /// The value to emit. + void Info(IFormatProvider formatProvider, T value); + + /// + /// Emits a info log message. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// A message to emit. + /// The exception which to emit in the log. + [Obsolete("Use void Info(Exception exception, [Localizable(false)] string? message)")] + void InfoException([Localizable(false)] string? message, Exception exception); + + /// + /// Emits a info log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + void Info(Exception exception, [Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the info log. + /// + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Emits a message to the info log. + /// + /// A non-localizable message to send to the log. + void Info([Localizable(false)] string? message); + + /// + /// Emits a message to the info log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + void Info([Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the info log. + /// + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Info([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the info log. + /// + /// The calling type. + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Info([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a warning log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The log to emit. + void Warn(T value); + + /// + /// Emits a warning log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The format provider to use. + /// The value to emit. + void Warn(IFormatProvider formatProvider, T value); + + /// + /// Emits a warning log message. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// A message to emit. + /// The exception which to emit in the log. + [Obsolete("Use void Warn(Exception exception, [Localizable(false)] string? message)")] + void WarnException([Localizable(false)] string? message, Exception exception); + + /// + /// Emits a warning log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + void Warn(Exception exception, [Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Emits a message to the warning log. + /// + /// A non-localizable message to send to the log. + void Warn([Localizable(false)] string? message); + + /// + /// Emits a message to the warning log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + void Warn([Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the warning log. + /// + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Warn([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The calling type. + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Warn([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a error log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The log to emit. + void Error(T value); + + /// + /// Emits a error log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The format provider to use. + /// The value to emit. + void Error(IFormatProvider formatProvider, T value); + + /// + /// Emits a error log message. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// A message to emit. + /// The exception which to emit in the log. + [Obsolete("Use void Error(Exception exception, [Localizable(false)] string? message)")] + void ErrorException([Localizable(false)] string? message, Exception exception); + + /// + /// Emits a error log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + void Error(Exception exception, [Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the error log. + /// + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Emits a message to the error log. + /// + /// A non-localizable message to send to the log. + void Error([Localizable(false)] string? message); + + /// + /// Emits a message to the error log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + void Error([Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the error log. + /// + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Error([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the error log. + /// + /// The calling type. + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Error([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Emits a fatal log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The log to emit. + void Fatal(T value); + + /// + /// Emits a fatal log message. + /// This will emit the public contents of the object provided to the log. + /// + /// The type of object used as the message. + /// The format provider to use. + /// The value to emit. + void Fatal(IFormatProvider formatProvider, T value); + + /// + /// Emits a fatal log message. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// A message to emit. + /// The exception which to emit in the log. + [Obsolete("Use void Fatal(Exception exception, [Localizable(false)] string? message)")] + void FatalException([Localizable(false)] string? message, Exception exception); + + /// + /// Emits a fatal log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + void Fatal(Exception exception, [Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Emits a message to the fatal log. + /// + /// A non-localizable message to send to the log. + void Fatal([Localizable(false)] string? message); + + /// + /// Emits a message to the fatal log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + void Fatal([Localizable(false)] string? message); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Fatal([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The calling type. + /// A non-localizable message to emit to the log which includes the standard formatting tags. + /// The arguments for formatting purposes. + void Fatal([Localizable(false)] string message, params object[] args); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); } diff --git a/src/Splat/Logging/ILogManager.cs b/src/Splat/Logging/ILogManager.cs index 675cda69f..3faa2556b 100644 --- a/src/Splat/Logging/ILogManager.cs +++ b/src/Splat/Logging/ILogManager.cs @@ -5,18 +5,17 @@ using System; -namespace Splat +namespace Splat; + +/// +/// A manaager which will generate a for the specified type. +/// +public interface ILogManager { /// - /// A manaager which will generate a for the specified type. + /// Generate a for the specified type. /// - public interface ILogManager - { - /// - /// Generate a for the specified type. - /// - /// The type to generate the logger for. - /// The for the specified type. - IFullLogger GetLogger(Type type); - } + /// The type to generate the logger for. + /// The for the specified type. + IFullLogger GetLogger(Type type); } diff --git a/src/Splat/Logging/ILogger.cs b/src/Splat/Logging/ILogger.cs index 22a8ccf7d..503981687 100644 --- a/src/Splat/Logging/ILogger.cs +++ b/src/Splat/Logging/ILogger.cs @@ -6,48 +6,47 @@ using System; using System.ComponentModel; -namespace Splat +namespace Splat; + +/// +/// Represents a log target where messages can be written to. +/// +public interface ILogger { /// - /// Represents a log target where messages can be written to. + /// Gets the level at which the target will emit messages. /// - public interface ILogger - { - /// - /// Gets the level at which the target will emit messages. - /// - LogLevel Level { get; } + LogLevel Level { get; } - /// - /// Writes a message to the target. - /// - /// The message to write. - /// The severity level of the log message. - void Write([Localizable(false)] string message, LogLevel logLevel); + /// + /// Writes a message to the target. + /// + /// The message to write. + /// The severity level of the log message. + void Write([Localizable(false)] string message, LogLevel logLevel); - /// - /// Writes a message to the target. - /// - /// The exception that occured. - /// The message to write. - /// The severity level of the log message. - void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel); + /// + /// Writes a message to the target. + /// + /// The exception that occured. + /// The message to write. + /// The severity level of the log message. + void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel); - /// - /// Writes a messge to the target. - /// - /// The message. - /// The type. - /// The log level. - void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel); + /// + /// Writes a messge to the target. + /// + /// The message. + /// The type. + /// The log level. + void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel); - /// - /// Writes a messge to the target. - /// - /// The exception that occured. - /// The message. - /// The type. - /// The log level. - void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel); - } + /// + /// Writes a messge to the target. + /// + /// The exception that occured. + /// The message. + /// The type. + /// The log level. + void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel); } diff --git a/src/Splat/Logging/IStaticFullLogger.cs b/src/Splat/Logging/IStaticFullLogger.cs index 2ca7735e2..b53b7dfb5 100644 --- a/src/Splat/Logging/IStaticFullLogger.cs +++ b/src/Splat/Logging/IStaticFullLogger.cs @@ -9,356 +9,355 @@ #pragma warning disable CA1716 // Identifiers should not match keywords -namespace Splat +namespace Splat; + +/// +/// Represents the logging interface for the Static Default Logger. +/// +public interface IStaticFullLogger { /// - /// Represents the logging interface for the Static Default Logger. - /// - public interface IStaticFullLogger - { - /// - /// Gets the level at which the target will emit messages. - /// - LogLevel Level { get; } - - /// - /// Emits a debug log message with an exception. - /// - /// The exception. - /// The message. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Debug(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the debug log. - /// - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Debug([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the debug log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Debug([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the debug log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a info log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Info(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the info log. - /// - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Info([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the info log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Info([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the info log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a warning log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Warn(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the warning log. - /// - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Warn([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the warning log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Warn([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the warning log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a error log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Error(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the error log. - /// - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Error([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the error log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Error([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the error log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a fatal log message with exception. - /// This will emit details about a exception. - /// This type of logging is not able to be localized. - /// - /// The exception which to emit in the log. - /// A message to emit. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Fatal(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the fatal log. - /// - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Fatal([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message to the fatal log. - /// - /// The calling type. - /// A non-localizable message to send to the log. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Fatal([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); - - /// - /// Emits a message using formatting to the fatal log. - /// - /// The type of the first argument which is used in the formatting. - /// The type of the second argument which is used in the formatting. - /// The type of the third argument which is used in the formatting. - /// The format provider to use. - /// A message to emit to the log which includes the standard formatting tags. - /// The first argument for formatting purposes. - /// The second argument for formatting purposes. - /// The third argument for formatting purposes. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); - - /// - /// Writes a message to the target. - /// - /// The message to write. - /// The severity level of the log message. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Write([Localizable(false)] string message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); - - /// - /// Writes a message to the target. - /// - /// The exception that occured. - /// The message to write. - /// The severity level of the log message. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); - - /// - /// Writes a messge to the target. - /// - /// The message. - /// The type. - /// The log level. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); - - /// - /// Writes a messge to the target. - /// - /// The exception that occured. - /// The message. - /// The type. - /// The log level. - /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. - void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); - } + /// Gets the level at which the target will emit messages. + /// + LogLevel Level { get; } + + /// + /// Emits a debug log message with an exception. + /// + /// The exception. + /// The message. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Debug(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the debug log. + /// + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Debug([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the debug log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Debug([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the debug log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a info log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Info(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the info log. + /// + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Info([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the info log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Info([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the info log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a warning log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Warn(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the warning log. + /// + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Warn([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the warning log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Warn([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the warning log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a error log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Error(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the error log. + /// + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Error([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the error log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Error([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the error log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a fatal log message with exception. + /// This will emit details about a exception. + /// This type of logging is not able to be localized. + /// + /// The exception which to emit in the log. + /// A message to emit. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Fatal(Exception exception, [Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the fatal log. + /// + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Fatal([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message to the fatal log. + /// + /// The calling type. + /// A non-localizable message to send to the log. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Fatal([Localizable(false)] string message, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null); + + /// + /// Emits a message using formatting to the fatal log. + /// + /// The type of the first argument which is used in the formatting. + /// The type of the second argument which is used in the formatting. + /// The type of the third argument which is used in the formatting. + /// The format provider to use. + /// A message to emit to the log which includes the standard formatting tags. + /// The first argument for formatting purposes. + /// The second argument for formatting purposes. + /// The third argument for formatting purposes. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null); + + /// + /// Writes a message to the target. + /// + /// The message to write. + /// The severity level of the log message. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Write([Localizable(false)] string message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); + + /// + /// Writes a message to the target. + /// + /// The exception that occured. + /// The message to write. + /// The severity level of the log message. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); + + /// + /// Writes a messge to the target. + /// + /// The message. + /// The type. + /// The log level. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); + + /// + /// Writes a messge to the target. + /// + /// The exception that occured. + /// The message. + /// The type. + /// The log level. + /// Allows you to pass the method or property name of the caller to the method, used to allow the capture in the static logger of some additional context for support and debugging. + void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null); } #pragma warning restore CA1716 // Identifiers should not match keywords diff --git a/src/Splat/Logging/LocalizableAttribute.cs b/src/Splat/Logging/LocalizableAttribute.cs index 0a683eef5..4a3aab0cb 100644 --- a/src/Splat/Logging/LocalizableAttribute.cs +++ b/src/Splat/Logging/LocalizableAttribute.cs @@ -3,30 +3,27 @@ // 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; -namespace Splat -{ #if PORTABLE || WINDOWS_PHONE || NETFX_CORE +/// +/// Specifies whether a property should be localized. +/// +[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] +public sealed class LocalizableAttribute : Attribute +{ /// - /// Specifies whether a property should be localized. + /// Initializes a new instance of the class. /// - [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] - public sealed class LocalizableAttribute : Attribute + /// If the value is localizable or not. + public LocalizableAttribute(bool isLocalizable) { - /// - /// Initializes a new instance of the class. - /// - /// If the value is localizable or not. - public LocalizableAttribute(bool isLocalizable) - { - IsLocalizable = isLocalizable; - } - - /// - /// Gets a value indicating whether a property should be localized. - /// - public bool IsLocalizable { get; } + IsLocalizable = isLocalizable; } -#endif + + /// + /// Gets a value indicating whether a property should be localized. + /// + public bool IsLocalizable { get; } } +#endif diff --git a/src/Splat/Logging/LogHost.cs b/src/Splat/Logging/LogHost.cs index 9f0b4e911..e9d5294e3 100644 --- a/src/Splat/Logging/LogHost.cs +++ b/src/Splat/Logging/LogHost.cs @@ -6,57 +6,56 @@ using System; using System.Diagnostics.CodeAnalysis; -namespace Splat +namespace Splat; + +/// +/// Contains helper methods to get access to the Default . +/// +public static class LogHost { /// - /// Contains helper methods to get access to the Default . + /// Gets the default registered within the . /// - public static class LogHost + [SuppressMessage("Design", "CA1065: Do not raise exceptions in properties", Justification = "Very rare scenario")] + public static IStaticFullLogger Default { - /// - /// Gets the default registered within the . - /// - [SuppressMessage("Design", "CA1065: Do not raise exceptions in properties", Justification = "Very rare scenario")] - public static IStaticFullLogger Default + get { - get - { - /* - * DV - this will need an extension of the dependency resolver. - * RegisterLazy(Func factory); - * which will allow a lazy instance of the static logger. - * - * return Locator.Current.GetService(); - */ - - var factory = Locator.Current.GetService(); - if (factory is null) - { - throw new LoggingException("ILogManager is null. This should never happen, your dependency resolver is broken"); - } - - var fullLogger = factory.GetLogger(typeof(LogHost)); - - return new StaticFullLogger(fullLogger); - } - } + /* + * DV - this will need an extension of the dependency resolver. + * RegisterLazy(Func factory); + * which will allow a lazy instance of the static logger. + * + * return Locator.Current.GetService(); + */ - /// - /// Call this method to write log entries on behalf of the current class. - /// - /// The type to get the for. - /// The class we are getting the logger for. - /// The for the class type. - public static IFullLogger Log(this T logClassInstance) - where T : IEnableLogger - { var factory = Locator.Current.GetService(); if (factory is null) { - throw new InvalidOperationException("ILogManager is null. This should never happen, your dependency resolver is broken"); + throw new LoggingException("ILogManager is null. This should never happen, your dependency resolver is broken"); } - return factory.GetLogger(); + var fullLogger = factory.GetLogger(typeof(LogHost)); + + return new StaticFullLogger(fullLogger); + } + } + + /// + /// Call this method to write log entries on behalf of the current class. + /// + /// The type to get the for. + /// The class we are getting the logger for. + /// The for the class type. + public static IFullLogger Log(this T logClassInstance) + where T : IEnableLogger + { + var factory = Locator.Current.GetService(); + if (factory is null) + { + throw new InvalidOperationException("ILogManager is null. This should never happen, your dependency resolver is broken"); } + + return factory.GetLogger(); } } diff --git a/src/Splat/Logging/LogLevel.cs b/src/Splat/Logging/LogLevel.cs index 45dba8fd2..6c78473de 100644 --- a/src/Splat/Logging/LogLevel.cs +++ b/src/Splat/Logging/LogLevel.cs @@ -3,37 +3,35 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// Represents the minimum log level a will start emitting from. +/// +public enum LogLevel { /// - /// Represents the minimum log level a will start emitting from. + /// The log message is for debuging purposes. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1008:Enums should have zero value", Justification = "Deliberate none zero value.")] - public enum LogLevel - { - /// - /// The log message is for debuging purposes. - /// - Debug = 1, + Debug = 1, - /// - /// The log message is for information purposes. - /// - Info, + /// + /// The log message is for information purposes. + /// + Info, - /// - /// The log message is for warning purposes. - /// - Warn, + /// + /// The log message is for warning purposes. + /// + Warn, - /// - /// The log message is for error purposes. - /// - Error, + /// + /// The log message is for error purposes. + /// + Error, - /// - /// The log message is for fatal purposes. - /// - Fatal, - } + /// + /// The log message is for fatal purposes. + /// + Fatal, } diff --git a/src/Splat/Logging/LogManagerMixin.cs b/src/Splat/Logging/LogManagerMixin.cs index 937c4f3e0..6602afd53 100644 --- a/src/Splat/Logging/LogManagerMixin.cs +++ b/src/Splat/Logging/LogManagerMixin.cs @@ -3,27 +3,26 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// Extension methods associated with the logging module. +/// +public static class LogManagerMixin { /// - /// Extension methods associated with the logging module. + /// Gets a for the specified . /// - public static class LogManagerMixin + /// The type of to use. + /// The log manager to get the logger from. + /// A logger for the specified type. + public static IFullLogger GetLogger(this ILogManager logManager) { - /// - /// Gets a for the specified . - /// - /// The type of to use. - /// The log manager to get the logger from. - /// A logger for the specified type. - public static IFullLogger GetLogger(this ILogManager logManager) + if (logManager is null) { - if (logManager is null) - { - throw new System.ArgumentNullException(nameof(logManager)); - } - - return logManager.GetLogger(typeof(T)); + throw new System.ArgumentNullException(nameof(logManager)); } + + return logManager.GetLogger(typeof(T)); } } diff --git a/src/Splat/Logging/LoggingException.cs b/src/Splat/Logging/LoggingException.cs index d97976eb6..8d133dbf6 100644 --- a/src/Splat/Logging/LoggingException.cs +++ b/src/Splat/Logging/LoggingException.cs @@ -6,46 +6,45 @@ using System; using System.Runtime.Serialization; -namespace Splat +namespace Splat; + +/// +/// A exception that occurs when there is a problem using the logging module. +/// +[Serializable] +public class LoggingException : Exception { /// - /// A exception that occurs when there is a problem using the logging module. + /// Initializes a new instance of the class. /// - [Serializable] - public class LoggingException : Exception + public LoggingException() { - /// - /// Initializes a new instance of the class. - /// - public LoggingException() - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// The message about the exception. - public LoggingException(string message) - : base(message) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The message about the exception. + public LoggingException(string message) + : base(message) + { + } - /// - /// Initializes a new instance of the class. - /// - /// The message about the exception. - /// Any other internal exceptions we are mapping. - public LoggingException(string message, Exception innerException) - : base(message, innerException) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The message about the exception. + /// Any other internal exceptions we are mapping. + 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) - { - } + /// 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/NullLogger.cs b/src/Splat/Logging/NullLogger.cs index 39abf4282..72e019d5f 100644 --- a/src/Splat/Logging/NullLogger.cs +++ b/src/Splat/Logging/NullLogger.cs @@ -6,34 +6,33 @@ using System; using System.ComponentModel; -namespace Splat +namespace Splat; + +/// +/// a logger which will never emit any value. +/// +public class NullLogger : ILogger { - /// - /// a logger which will never emit any value. - /// - public class NullLogger : ILogger - { - /// - public LogLevel Level { get; set; } + /// + public LogLevel Level { get; set; } - /// - public void Write([Localizable(false)] string message, LogLevel logLevel) - { - } + /// + public void Write([Localizable(false)] string message, LogLevel logLevel) + { + } - /// - public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) - { - } + /// + public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) + { + } - /// - public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - } + /// + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + } - /// - public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - } + /// + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { } } diff --git a/src/Splat/Logging/StaticFullLogger.cs b/src/Splat/Logging/StaticFullLogger.cs index 95c07c9b9..fb0e28e42 100644 --- a/src/Splat/Logging/StaticFullLogger.cs +++ b/src/Splat/Logging/StaticFullLogger.cs @@ -7,293 +7,292 @@ using System.ComponentModel; using System.Runtime.CompilerServices; -namespace Splat +namespace Splat; + +/// +/// A full logger which used by the default static logger to allow capture of .NET framework caller data. Wraps a . +/// +public sealed class StaticFullLogger : IStaticFullLogger { + private readonly IFullLogger _fullLogger; + /// - /// A full logger which used by the default static logger to allow capture of .NET framework caller data. Wraps a . + /// Initializes a new instance of the class. /// - public sealed class StaticFullLogger : IStaticFullLogger - { - private readonly IFullLogger _fullLogger; - - /// - /// Initializes a new instance of the class. - /// - /// The to wrap in this class. - public StaticFullLogger(IFullLogger fullLogger) - { - _fullLogger = fullLogger ?? throw new ArgumentNullException(nameof(fullLogger)); - } - - /// - public LogLevel Level => _fullLogger.Level; - - /// - public void Debug(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Debug(exception, GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Debug(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Debug(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Debug(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Debug(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Debug(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Debug( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument); - } - - /// - public void Debug(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Debug( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2); - } - - /// - public void Debug(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Debug( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2, - argument3); - } - - /// - public void Info(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Info(exception, GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Info(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Info(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Info(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Info(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Info(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Info( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument); - } - - /// - public void Info(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Info( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2); - } - - /// - public void Info(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Info( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2, - argument3); - } - - /// - public void Warn(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Warn(exception, GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Warn(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Warn(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Warn(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Warn(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Warn(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Warn( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument); - } - - /// - public void Warn(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Warn( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2); - } - - /// - public void Warn(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Warn( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2, - argument3); - } - - /// - public void Error(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Error(exception, GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Error(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Error(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Error(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Error(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Error(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Error( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument); - } - - /// - public void Error(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Error( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2); - } - - /// - public void Error(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Error( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2, - argument3); - } - - /// - public void Fatal(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Fatal(exception, GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Fatal(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Fatal(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Fatal(string? message, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Fatal(GetSuffixedCallerData(message, callerMemberName)); - } - - /// - public void Fatal(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Fatal( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument); - } - - /// - public void Fatal(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Fatal( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2); - } - - /// - public void Fatal(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Fatal( - formatProvider, - GetSuffixedCallerData(message, callerMemberName), - argument1, - argument2, - argument3); - } - - /// - public void Write(string? message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Write(GetSuffixedCallerData(message, callerMemberName), logLevel); - } - - /// - public void Write(Exception exception, string? message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Write(exception, GetSuffixedCallerData(message, callerMemberName), logLevel); - } - - /// - public void Write([Localizable(false)] string? message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Write(GetSuffixedCallerData(message, callerMemberName), type, logLevel); - } - - /// - public void Write(Exception exception, [Localizable(false)] string? message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) - { - _fullLogger.Write(exception, GetSuffixedCallerData(message, callerMemberName), type, logLevel); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static string GetSuffixedCallerData(string? message, string? callerMemberName) => - $"{message} ({callerMemberName})"; + /// The to wrap in this class. + public StaticFullLogger(IFullLogger fullLogger) + { + _fullLogger = fullLogger ?? throw new ArgumentNullException(nameof(fullLogger)); + } + + /// + public LogLevel Level => _fullLogger.Level; + + /// + public void Debug(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Debug(exception, GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Debug(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Debug(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Debug(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Debug(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Debug(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Debug( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument); + } + + /// + public void Debug(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Debug( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2); + } + + /// + public void Debug(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Debug( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2, + argument3); + } + + /// + public void Info(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Info(exception, GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Info(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Info(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Info(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Info(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Info(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Info( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument); } + + /// + public void Info(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Info( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2); + } + + /// + public void Info(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Info( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2, + argument3); + } + + /// + public void Warn(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Warn(exception, GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Warn(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Warn(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Warn(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Warn(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Warn(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Warn( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument); + } + + /// + public void Warn(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Warn( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2); + } + + /// + public void Warn(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Warn( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2, + argument3); + } + + /// + public void Error(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Error(exception, GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Error(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Error(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Error(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Error(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Error(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Error( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument); + } + + /// + public void Error(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Error( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2); + } + + /// + public void Error(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Error( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2, + argument3); + } + + /// + public void Fatal(Exception exception, string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Fatal(exception, GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Fatal(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Fatal(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Fatal(string? message, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Fatal(GetSuffixedCallerData(message, callerMemberName)); + } + + /// + public void Fatal(IFormatProvider formatProvider, string message, TArgument argument, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Fatal( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument); + } + + /// + public void Fatal(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Fatal( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2); + } + + /// + public void Fatal(IFormatProvider formatProvider, string? message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Fatal( + formatProvider, + GetSuffixedCallerData(message, callerMemberName), + argument1, + argument2, + argument3); + } + + /// + public void Write(string? message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Write(GetSuffixedCallerData(message, callerMemberName), logLevel); + } + + /// + public void Write(Exception exception, string? message, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Write(exception, GetSuffixedCallerData(message, callerMemberName), logLevel); + } + + /// + public void Write([Localizable(false)] string? message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Write(GetSuffixedCallerData(message, callerMemberName), type, logLevel); + } + + /// + public void Write(Exception exception, [Localizable(false)] string? message, [Localizable(false)] Type type, LogLevel logLevel, [CallerMemberName]string? callerMemberName = null) + { + _fullLogger.Write(exception, GetSuffixedCallerData(message, callerMemberName), type, logLevel); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static string GetSuffixedCallerData(string? message, string? callerMemberName) => + $"{message} ({callerMemberName})"; } diff --git a/src/Splat/Logging/WrappingFullLogger.cs b/src/Splat/Logging/WrappingFullLogger.cs index 8462458eb..705ceb8aa 100644 --- a/src/Splat/Logging/WrappingFullLogger.cs +++ b/src/Splat/Logging/WrappingFullLogger.cs @@ -4,441 +4,438 @@ // See the LICENSE file in the project root for full license information. using System; -using System.ComponentModel; -using System.Diagnostics.Contracts; using System.Globalization; using System.Reflection; -namespace Splat +namespace Splat; + +/// +/// A full logger which wraps a . +/// +public class WrappingFullLogger : AllocationFreeLoggerBase, IFullLogger { + private readonly ILogger _inner; + private readonly MethodInfo _stringFormat; + /// - /// A full logger which wraps a . + /// Initializes a new instance of the class. /// - public class WrappingFullLogger : AllocationFreeLoggerBase, IFullLogger + /// The to wrap in this class. + public WrappingFullLogger(ILogger inner) + : base(inner) { - private readonly ILogger _inner; - private readonly MethodInfo _stringFormat; + _inner = inner ?? throw new ArgumentNullException(nameof(inner)); - /// - /// Initializes a new instance of the class. - /// - /// The to wrap in this class. - public WrappingFullLogger(ILogger inner) - : base(inner) - { - _inner = inner ?? throw new ArgumentNullException(nameof(inner)); + _stringFormat = typeof(string).GetMethod("Format", new[] { typeof(IFormatProvider), typeof(string), typeof(object[]) }) ?? throw new InvalidOperationException("Cannot find the Format method which is required."); + } - _stringFormat = typeof(string).GetMethod("Format", new[] { typeof(IFormatProvider), typeof(string), typeof(object[]) }) ?? throw new InvalidOperationException("Cannot find the Format method which is required."); + /// + public void Debug(T value) + { + if (value is null) + { + return; } - /// - public void Debug(T value) - { - if (value is null) - { - return; - } + _inner.Write(value.ToString() ?? "(null)", LogLevel.Debug); + } - _inner.Write(value.ToString() ?? "(null)", LogLevel.Debug); - } + /// + public void Debug(IFormatProvider formatProvider, T value) + { + _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Debug); + } - /// - public void Debug(IFormatProvider formatProvider, T value) - { - _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Debug); - } + /// + public void DebugException(string? message, Exception exception) + { + _inner.Write(exception, $"{message}: {exception}", LogLevel.Debug); + } - /// - public void DebugException(string? message, Exception exception) - { - _inner.Write(exception, $"{message}: {exception}", LogLevel.Debug); - } + /// + public void Debug(Exception exception, string? message) + { + _inner.Write(exception, $"{message}", LogLevel.Debug); + } - /// - public void Debug(Exception exception, string? message) - { - _inner.Write(exception, $"{message}", LogLevel.Debug); - } + /// + public void Debug(IFormatProvider formatProvider, string message, params object[] args) + { + var result = InvokeStringFormat(formatProvider, message, args); - /// - public void Debug(IFormatProvider formatProvider, string message, params object[] args) - { - var result = InvokeStringFormat(formatProvider, message, args); + _inner.Write(result, LogLevel.Debug); + } - _inner.Write(result, LogLevel.Debug); - } + /// + public void Debug(string? message) + { + _inner.Write(message ?? "(null)", LogLevel.Debug); + } - /// - public void Debug(string? message) - { - _inner.Write(message ?? "(null)", LogLevel.Debug); - } + /// + public void Debug(string? message) + { + _inner.Write(message ?? "(null)", typeof(T), LogLevel.Debug); + } - /// - public void Debug(string? message) - { - _inner.Write(message ?? "(null)", typeof(T), LogLevel.Debug); - } + /// + public void Debug(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, LogLevel.Debug); + } - /// - public void Debug(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, LogLevel.Debug); - } + /// + public void Debug(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, typeof(T), LogLevel.Debug); + } - /// - public void Debug(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, typeof(T), LogLevel.Debug); - } + /// + public void Debug(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Debug); + } - /// - public void Debug(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Debug); - } + /// + public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Debug); + } - /// - public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Debug); - } + /// + public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Debug); + } - /// - public void Debug(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + /// + public void Info(T value) + { + if (value is null) { - _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Debug); + return; } - /// - public void Info(T value) - { - if (value is null) - { - return; - } + _inner.Write(value.ToString() ?? "(null)", LogLevel.Info); + } - _inner.Write(value.ToString() ?? "(null)", LogLevel.Info); - } + /// + public void Info(IFormatProvider formatProvider, T value) + { + _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Info); + } - /// - public void Info(IFormatProvider formatProvider, T value) - { - _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Info); - } + /// + public void InfoException(string? message, Exception exception) + { + _inner.Write(exception, $"{message}: {exception}", LogLevel.Info); + } - /// - public void InfoException(string? message, Exception exception) - { - _inner.Write(exception, $"{message}: {exception}", LogLevel.Info); - } + /// + public void Info(Exception exception, string? message) + { + _inner.Write(exception, $"{message}", LogLevel.Info); + } - /// - public void Info(Exception exception, string? message) - { - _inner.Write(exception, $"{message}", LogLevel.Info); - } + /// + public void Info(IFormatProvider formatProvider, string message, params object[] args) + { + var result = InvokeStringFormat(formatProvider, message, args); + _inner.Write(result, LogLevel.Info); + } - /// - public void Info(IFormatProvider formatProvider, string message, params object[] args) - { - var result = InvokeStringFormat(formatProvider, message, args); - _inner.Write(result, LogLevel.Info); - } + /// + public void Info(string? message) + { + _inner.Write(message ?? "(null)", LogLevel.Info); + } - /// - public void Info(string? message) - { - _inner.Write(message ?? "(null)", LogLevel.Info); - } + /// + public void Info(string? message) + { + _inner.Write(message ?? "(null)", typeof(T), LogLevel.Info); + } - /// - public void Info(string? message) - { - _inner.Write(message ?? "(null)", typeof(T), LogLevel.Info); - } + /// + public void Info(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, LogLevel.Info); + } - /// - public void Info(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, LogLevel.Info); - } + /// + public void Info(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, typeof(T), LogLevel.Info); + } - /// - public void Info(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, typeof(T), LogLevel.Info); - } + /// + public void Info(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Info); + } - /// - public void Info(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Info); - } + /// + public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Info); + } - /// - public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Info); - } + /// + public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Info); + } - /// - public void Info(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + /// + public void Warn(T value) + { + if (value is null) { - _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Info); + return; } - /// - public void Warn(T value) - { - if (value is null) - { - return; - } + _inner.Write(value.ToString() ?? "(null)", LogLevel.Warn); + } - _inner.Write(value.ToString() ?? "(null)", LogLevel.Warn); - } + /// + public void Warn(IFormatProvider formatProvider, T value) + { + _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Warn); + } - /// - public void Warn(IFormatProvider formatProvider, T value) - { - _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Warn); - } + /// + public void WarnException(string? message, Exception exception) + { + _inner.Write(exception, $"{message}: {exception}", LogLevel.Warn); + } - /// - public void WarnException(string? message, Exception exception) - { - _inner.Write(exception, $"{message}: {exception}", LogLevel.Warn); - } + /// + public void Warn(Exception exception, string? message) + { + _inner.Write(exception, $"{message}", LogLevel.Warn); + } - /// - public void Warn(Exception exception, string? message) - { - _inner.Write(exception, $"{message}", LogLevel.Warn); - } + /// + public void Warn(IFormatProvider formatProvider, string message, params object[] args) + { + var result = InvokeStringFormat(formatProvider, message, args); + _inner.Write(result, LogLevel.Warn); + } - /// - public void Warn(IFormatProvider formatProvider, string message, params object[] args) - { - var result = InvokeStringFormat(formatProvider, message, args); - _inner.Write(result, LogLevel.Warn); - } + /// + public void Warn(string? message) + { + _inner.Write(message ?? "(null)", LogLevel.Warn); + } - /// - public void Warn(string? message) - { - _inner.Write(message ?? "(null)", LogLevel.Warn); - } + /// + public void Warn(string? message) + { + _inner.Write(message ?? "(null)", typeof(T), LogLevel.Warn); + } - /// - public void Warn(string? message) - { - _inner.Write(message ?? "(null)", typeof(T), LogLevel.Warn); - } + /// + public void Warn(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, LogLevel.Warn); + } - /// - public void Warn(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, LogLevel.Warn); - } + /// + public void Warn(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, typeof(T), LogLevel.Warn); + } - /// - public void Warn(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, typeof(T), LogLevel.Warn); - } + /// + public void Warn(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Warn); + } - /// - public void Warn(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Warn); - } + /// + public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Warn); + } - /// - public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Warn); - } + /// + public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Warn); + } - /// - public void Warn(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + /// + public void Error(T value) + { + if (value is null) { - _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Warn); + return; } - /// - public void Error(T value) - { - if (value is null) - { - return; - } + _inner.Write(value.ToString() ?? "(null)", LogLevel.Error); + } - _inner.Write(value.ToString() ?? "(null)", LogLevel.Error); - } + /// + public void Error(IFormatProvider formatProvider, T value) + { + _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Error); + } - /// - public void Error(IFormatProvider formatProvider, T value) - { - _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Error); - } + /// + public void ErrorException(string? message, Exception exception) + { + _inner.Write(exception, $"{message}: {exception}", LogLevel.Error); + } - /// - public void ErrorException(string? message, Exception exception) - { - _inner.Write(exception, $"{message}: {exception}", LogLevel.Error); - } + /// + public void Error(Exception exception, string? message) + { + _inner.Write(exception, $"{message}", LogLevel.Error); + } - /// - public void Error(Exception exception, string? message) - { - _inner.Write(exception, $"{message}", LogLevel.Error); - } + /// + public void Error(IFormatProvider formatProvider, string message, params object[] args) + { + var result = InvokeStringFormat(formatProvider, message, args); + _inner.Write(result, LogLevel.Error); + } - /// - public void Error(IFormatProvider formatProvider, string message, params object[] args) - { - var result = InvokeStringFormat(formatProvider, message, args); - _inner.Write(result, LogLevel.Error); - } + /// + public void Error(string? message) + { + _inner.Write(message ?? "(null)", LogLevel.Error); + } - /// - public void Error(string? message) - { - _inner.Write(message ?? "(null)", LogLevel.Error); - } + /// + public void Error(string? message) + { + _inner.Write(message ?? "(null)", typeof(T), LogLevel.Error); + } - /// - public void Error(string? message) - { - _inner.Write(message ?? "(null)", typeof(T), LogLevel.Error); - } + /// + public void Error(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, LogLevel.Error); + } - /// - public void Error(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, LogLevel.Error); - } + /// + public void Error(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, typeof(T), LogLevel.Error); + } - /// - public void Error(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, typeof(T), LogLevel.Error); - } + /// + public void Error(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Error); + } - /// - public void Error(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Error); - } + /// + public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Error); + } - /// - public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Error); - } + /// + public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Error); + } - /// - public void Error(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + /// + public void Fatal(T value) + { + if (value is null) { - _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Error); + return; } - /// - public void Fatal(T value) - { - if (value is null) - { - return; - } - - _inner.Write(value.ToString() ?? "(null)", LogLevel.Fatal); - } + _inner.Write(value.ToString() ?? "(null)", LogLevel.Fatal); + } - /// - public void Fatal(IFormatProvider formatProvider, T value) - { - _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Fatal); - } + /// + public void Fatal(IFormatProvider formatProvider, T value) + { + _inner.Write(string.Format(formatProvider, "{0}", value), LogLevel.Fatal); + } - /// - public void FatalException(string? message, Exception exception) - { - _inner.Write(exception, $"{message}: {exception}", LogLevel.Fatal); - } + /// + public void FatalException(string? message, Exception exception) + { + _inner.Write(exception, $"{message}: {exception}", LogLevel.Fatal); + } - /// - public void Fatal(Exception exception, string? message) - { - _inner.Write(exception, $"{message}", LogLevel.Fatal); - } + /// + public void Fatal(Exception exception, string? message) + { + _inner.Write(exception, $"{message}", LogLevel.Fatal); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, params object[] args) - { - var result = InvokeStringFormat(formatProvider, message, args); - _inner.Write(result, LogLevel.Fatal); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, params object[] args) + { + var result = InvokeStringFormat(formatProvider, message, args); + _inner.Write(result, LogLevel.Fatal); + } - /// - public void Fatal(string? message) - { - _inner.Write(message ?? "(null)", LogLevel.Fatal); - } + /// + public void Fatal(string? message) + { + _inner.Write(message ?? "(null)", LogLevel.Fatal); + } - /// - public void Fatal(string? message) - { - _inner.Write(message ?? "(null)", typeof(T), LogLevel.Fatal); - } + /// + public void Fatal(string? message) + { + _inner.Write(message ?? "(null)", typeof(T), LogLevel.Fatal); + } - /// - public void Fatal(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, LogLevel.Fatal); - } + /// + public void Fatal(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, LogLevel.Fatal); + } - /// - public void Fatal(string message, params object[] args) - { - var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); - _inner.Write(result, typeof(T), LogLevel.Fatal); - } + /// + public void Fatal(string message, params object[] args) + { + var result = InvokeStringFormat(CultureInfo.InvariantCulture, message, args); + _inner.Write(result, typeof(T), LogLevel.Fatal); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, TArgument argument) - { - _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Fatal); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, TArgument argument) + { + _inner.Write(string.Format(formatProvider, message, argument), LogLevel.Fatal); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) - { - _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Fatal); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2), LogLevel.Fatal); + } - /// - public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) - { - _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Fatal); - } + /// + public void Fatal(IFormatProvider formatProvider, string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + { + _inner.Write(string.Format(formatProvider, message, argument1, argument2, argument3), LogLevel.Fatal); + } - private string InvokeStringFormat(IFormatProvider formatProvider, string message, object[] args) - { - var sfArgs = new object?[3]; - sfArgs[0] = formatProvider; - sfArgs[1] = message; - sfArgs[2] = args; - return (string?)_stringFormat.Invoke(null, sfArgs) ?? "(null)"; - } + private string InvokeStringFormat(IFormatProvider formatProvider, string message, object[] args) + { + var sfArgs = new object?[3]; + sfArgs[0] = formatProvider; + sfArgs[1] = message; + sfArgs[2] = args; + return (string?)_stringFormat.Invoke(null, sfArgs) ?? "(null)"; } } diff --git a/src/Splat/Logging/WrappingLogLevelLogger.cs b/src/Splat/Logging/WrappingLogLevelLogger.cs index 75dabb731..6173f097f 100644 --- a/src/Splat/Logging/WrappingLogLevelLogger.cs +++ b/src/Splat/Logging/WrappingLogLevelLogger.cs @@ -5,52 +5,50 @@ using System; using System.ComponentModel; -using System.Globalization; -namespace Splat +namespace Splat; + +/// +/// A prefix logger which wraps a . +/// +public class WrappingLogLevelLogger : ILogger { + private readonly ILogger _inner; + /// - /// A prefix logger which wraps a . + /// Initializes a new instance of the class. + /// Placeholder. /// - public class WrappingLogLevelLogger : ILogger + /// The to wrap in this class. + public WrappingLogLevelLogger(ILogger inner) + { + _inner = inner; + } + + /// + public LogLevel Level => _inner.Level; + + /// + public void Write([Localizable(false)]string message, LogLevel logLevel) + { + _inner.Write($"{logLevel}: {message}", logLevel); + } + + /// + public void Write(Exception exception, [Localizable(false)]string message, LogLevel logLevel) + { + _inner.Write(exception, $"{logLevel}: {message}", logLevel); + } + + /// + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + _inner.Write($"{logLevel}: {message}", type, logLevel); + } + + /// + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) { - private readonly ILogger _inner; - - /// - /// Initializes a new instance of the class. - /// Placeholder. - /// - /// The to wrap in this class. - public WrappingLogLevelLogger(ILogger inner) - { - _inner = inner; - } - - /// - public LogLevel Level => _inner.Level; - - /// - public void Write([Localizable(false)]string message, LogLevel logLevel) - { - _inner.Write($"{logLevel}: {message}", logLevel); - } - - /// - public void Write(Exception exception, [Localizable(false)]string message, LogLevel logLevel) - { - _inner.Write(exception, $"{logLevel}: {message}", logLevel); - } - - /// - public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - _inner.Write($"{logLevel}: {message}", type, logLevel); - } - - /// - public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - _inner.Write(exception, $"{logLevel}: {message}", type, logLevel); - } + _inner.Write(exception, $"{logLevel}: {message}", type, logLevel); } } diff --git a/src/Splat/Logging/WrappingPrefixLogger.cs b/src/Splat/Logging/WrappingPrefixLogger.cs index 5b965a9c6..f45a273ce 100644 --- a/src/Splat/Logging/WrappingPrefixLogger.cs +++ b/src/Splat/Logging/WrappingPrefixLogger.cs @@ -5,65 +5,63 @@ using System; using System.ComponentModel; -using System.Globalization; -namespace Splat +namespace Splat; + +/// +/// A prefix logger which wraps a . +/// +public class WrappingPrefixLogger : ILogger { + private readonly ILogger _inner; + private readonly string _prefix; + /// - /// A prefix logger which wraps a . + /// Initializes a new instance of the class. + /// Placeholder. /// - public class WrappingPrefixLogger : ILogger + /// The to wrap in this class. + /// The type which will be calling this logger. + public WrappingPrefixLogger(ILogger inner, Type callingType) { - private readonly ILogger _inner; - private readonly string _prefix; + _inner = inner; + _prefix = $"{callingType?.Name}: "; + } - /// - /// Initializes a new instance of the class. - /// Placeholder. - /// - /// The to wrap in this class. - /// The type which will be calling this logger. - public WrappingPrefixLogger(ILogger inner, Type callingType) - { - _inner = inner; - _prefix = $"{callingType?.Name}: "; - } + /// + public LogLevel Level => _inner.Level; - /// - 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) + /// + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + if (type is null) { - _inner.Write(exception, _prefix + message, logLevel); + throw new ArgumentNullException(nameof(type)); } - /// - public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) - { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - _inner.Write($"{type.Name}: {message}", type, logLevel); - } + _inner.Write($"{type.Name}: {message}", type, logLevel); + } - /// - public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + /// + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) + { + if (type is null) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - _inner.Write(exception, $"{type.Name}: {message}", type, logLevel); + throw new ArgumentNullException(nameof(type)); } + + _inner.Write(exception, $"{type.Name}: {message}", type, logLevel); } } diff --git a/src/Splat/Maths/PointMathExtensions.cs b/src/Splat/Maths/PointMathExtensions.cs index 0cdac8e1a..ebd5f7fd9 100644 --- a/src/Splat/Maths/PointMathExtensions.cs +++ b/src/Splat/Maths/PointMathExtensions.cs @@ -6,137 +6,136 @@ using System; using System.Drawing; -namespace Splat +namespace Splat; + +/// +/// Extension methods which extend the point mathematics. +/// +public static class PointMathExtensions { /// - /// Extension methods which extend the point mathematics. + /// Floor the specified point (i.e. round it to integer values). /// - public static class PointMathExtensions + /// The point value to use for the calculation. + /// The point that has been floored. + public static PointF Floor(this Point value) { - /// - /// Floor the specified point (i.e. round it to integer values). - /// - /// The point value to use for the calculation. - /// The point that has been floored. - public static PointF Floor(this Point value) - { #if UIKIT - // NB: I have no idea but Archimedes does this, soooooooo.... - return new PointF((float)Math.Floor((double)value.X), (float)Math.Floor((double)value.Y)); + // NB: I have no idea but Archimedes does this, soooooooo.... + return new PointF((float)Math.Floor((double)value.X), (float)Math.Floor((double)value.Y)); #else - return new PointF((float)Math.Floor((double)value.X), (float)Math.Ceiling((double)value.Y)); + return new PointF((float)Math.Floor((double)value.X), (float)Math.Ceiling((double)value.Y)); #endif - } + } - /// - /// Determines whether two points are within 'epsilon' of each other. - /// - /// The point value to use for the calculation. - /// The point to compare against. - /// The tolerated epsilon value. - /// If the value is equal based on the epsilon. - public static bool WithinEpsilonOf(this PointF value, PointF other, float epsilon) - { - return value.DistanceTo(other) < epsilon; - } + /// + /// Determines whether two points are within 'epsilon' of each other. + /// + /// The point value to use for the calculation. + /// The point to compare against. + /// The tolerated epsilon value. + /// If the value is equal based on the epsilon. + public static bool WithinEpsilonOf(this PointF value, PointF other, float epsilon) + { + return value.DistanceTo(other) < epsilon; + } - /// - /// Calculates the Dot product of two points. - /// - /// The point value to use for the calculation. - /// The point to perform the dot product against. - /// The calculated dot product. - public static float DotProduct(this PointF value, PointF other) - { - return (value.X * other.X) + (value.Y * other.Y); - } + /// + /// Calculates the Dot product of two points. + /// + /// The point value to use for the calculation. + /// The point to perform the dot product against. + /// The calculated dot product. + public static float DotProduct(this PointF value, PointF other) + { + return (value.X * other.X) + (value.Y * other.Y); + } - /// - /// Scales a PointF by a scalar factor. - /// - /// The point value to use for the calculation. - /// The amount to scale by. - /// The scaled point. - public static PointF ScaledBy(this PointF value, float factor) - { - return new(value.X * factor, value.Y * factor); - } + /// + /// Scales a PointF by a scalar factor. + /// + /// The point value to use for the calculation. + /// The amount to scale by. + /// The scaled point. + public static PointF ScaledBy(this PointF value, float factor) + { + return new(value.X * factor, value.Y * factor); + } - /// - /// Calculates the magnitude of a point from (0,0). - /// - /// The point value to use for the calculation. - /// The length of the point. - public static float Length(this PointF value) - { - return PointF.Empty.DistanceTo(value); - } + /// + /// Calculates the magnitude of a point from (0,0). + /// + /// The point value to use for the calculation. + /// The length of the point. + public static float Length(this PointF value) + { + return PointF.Empty.DistanceTo(value); + } - /// - /// Normalize the specified PointF (i.e. makes its magnitude = 1.0f). - /// - /// The point value to use for the calculation. - /// The normalized point. - public static PointF Normalize(this PointF value) + /// + /// Normalize the specified PointF (i.e. makes its magnitude = 1.0f). + /// + /// The point value to use for the calculation. + /// The normalized point. + public static PointF Normalize(this PointF value) + { + var length = value.Length(); + if (length == 0.0f) { - var length = value.Length(); - if (length == 0.0f) - { - return value; - } - - return new PointF(value.X / length, value.Y / length); + return value; } - /// - /// Calculates the angle in degrees of a PointF. - /// - /// The point value to use for the calculation. - /// The angle that has been generated. - public static float AngleInDegrees(this PointF value) - { - return (float)(Math.Atan2(value.Y, value.X) * 180.0f / Math.PI); - } + return new PointF(value.X / length, value.Y / length); + } - /// - /// Projects a PointF along a specified direction. - /// - /// The point value to use for the calculation. - /// The point containing the direction. - /// The projected point. - public static PointF ProjectAlong(this PointF value, PointF direction) - { - var normalDirection = direction.Normalize(); - var dist = value.DotProduct(normalDirection); + /// + /// Calculates the angle in degrees of a PointF. + /// + /// The point value to use for the calculation. + /// The angle that has been generated. + public static float AngleInDegrees(this PointF value) + { + return (float)(Math.Atan2(value.Y, value.X) * 180.0f / Math.PI); + } - return normalDirection.ScaledBy(dist); - } + /// + /// Projects a PointF along a specified direction. + /// + /// The point value to use for the calculation. + /// The point containing the direction. + /// The projected point. + public static PointF ProjectAlong(this PointF value, PointF direction) + { + var normalDirection = direction.Normalize(); + var dist = value.DotProduct(normalDirection); - /// - /// Projects a PointF along a specified angle. - /// - /// The point value to use for the calculation. - /// The angle in degrees to perform the projection against. - /// The point that has been projected. - public static PointF ProjectAlongAngle(this PointF value, float angleInDegrees) - { - var rads = angleInDegrees * Math.PI / 180.0f; - var direction = new PointF((float)Math.Cos(rads), (float)Math.Sin(rads)); + return normalDirection.ScaledBy(dist); + } - return value.ProjectAlong(direction); - } + /// + /// Projects a PointF along a specified angle. + /// + /// The point value to use for the calculation. + /// The angle in degrees to perform the projection against. + /// The point that has been projected. + public static PointF ProjectAlongAngle(this PointF value, float angleInDegrees) + { + var rads = angleInDegrees * Math.PI / 180.0f; + var direction = new PointF((float)Math.Cos(rads), (float)Math.Sin(rads)); - /// - /// Calculates the distance between two points. - /// - /// The point value to use for the calculation. - /// The other point to generate for. - /// The distance to the other point. - public static float DistanceTo(this PointF value, PointF other) - { - var deltaX = other.X - value.X; - var deltaY = other.Y - value.Y; - return (float)Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)); - } + return value.ProjectAlong(direction); + } + + /// + /// Calculates the distance between two points. + /// + /// The point value to use for the calculation. + /// The other point to generate for. + /// The distance to the other point. + public static float DistanceTo(this PointF value, PointF other) + { + var deltaX = other.X - value.X; + var deltaY = other.Y - value.Y; + return (float)Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)); } } diff --git a/src/Splat/Maths/RectEdge.cs b/src/Splat/Maths/RectEdge.cs index 94dea50ce..24d3c0c6b 100644 --- a/src/Splat/Maths/RectEdge.cs +++ b/src/Splat/Maths/RectEdge.cs @@ -3,31 +3,30 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// Specified which edge of a rectangle to use. +/// +public enum RectEdge { /// - /// Specified which edge of a rectangle to use. + /// The left of the rectangle. /// - public enum RectEdge - { - /// - /// The left of the rectangle. - /// - Left, + Left, - /// - /// The top of the rectangle. - /// - Top, + /// + /// The top of the rectangle. + /// + Top, - /// - /// The right of the rectangle. - /// - Right, + /// + /// The right of the rectangle. + /// + Right, - /// - /// The bottom of the rectangle. - /// - Bottom, - } + /// + /// The bottom of the rectangle. + /// + Bottom, } diff --git a/src/Splat/Maths/RectangleMathExtensions.cs b/src/Splat/Maths/RectangleMathExtensions.cs index ba166783e..711e45d79 100644 --- a/src/Splat/Maths/RectangleMathExtensions.cs +++ b/src/Splat/Maths/RectangleMathExtensions.cs @@ -6,158 +6,157 @@ using System; using System.Drawing; -namespace Splat +namespace Splat; + +/// +/// Extension methods to help with operations associated with the struct. +/// +public static class RectangleMathExtensions { /// - /// Extension methods to help with operations associated with the struct. + /// Determine the center of a Rectangle. + /// + /// The rectangle to perform the calculation against. + /// The point of the center of the rectangle. + public static PointF Center(this RectangleF value) + { + return new(value.X + (value.Width / 2.0f), value.Y + (value.Height / 2.0f)); + } + + /// + /// Divide the specified Rectangle into two component rectangles. /// - public static class RectangleMathExtensions + /// The rectangle to perform the calculation against. + /// Amount to move away from the given edge. + /// The edge to create the slice from. + /// The set of rectnagles that are generated. + public static Tuple Divide(this RectangleF value, float amount, RectEdge fromEdge) { - /// - /// Determine the center of a Rectangle. - /// - /// The rectangle to perform the calculation against. - /// The point of the center of the rectangle. - public static PointF Center(this RectangleF value) + var delta = default(float); + + switch (fromEdge) { - return new(value.X + (value.Width / 2.0f), value.Y + (value.Height / 2.0f)); + case RectEdge.Left: + delta = Math.Max(value.Width, amount); + return Tuple.Create( + value.Copy(width: delta), + value.Copy(x: value.Left + delta, width: value.Width - delta)); + case RectEdge.Top: + delta = Math.Max(value.Height, amount); + return Tuple.Create( + value.Copy(height: amount), + value.Copy(y: value.Top + delta, height: value.Height - delta)); + case RectEdge.Right: + delta = Math.Max(value.Width, amount); + return Tuple.Create( + value.Copy(x: value.Right - delta, width: delta), + value.Copy(width: value.Width - delta)); + case RectEdge.Bottom: + delta = Math.Max(value.Height, amount); + return Tuple.Create( + value.Copy(y: value.Bottom - delta, height: delta), + value.Copy(height: value.Height - delta)); + default: + throw new ArgumentException("edge"); } + } - /// - /// Divide the specified Rectangle into two component rectangles. - /// - /// The rectangle to perform the calculation against. - /// Amount to move away from the given edge. - /// The edge to create the slice from. - /// The set of rectnagles that are generated. - public static Tuple Divide(this RectangleF value, float amount, RectEdge fromEdge) - { - var delta = default(float); + /// + /// Divide the specified Rectangle into two component rectangles, adding + /// a padding between them. + /// + /// The rectangle to perform the calculation against. + /// Amount to move away from the given edge. + /// The amount of padding that is in neither rectangle. + /// The edge to create the slice from. + /// The set of rectangles that are generated. + public static Tuple DivideWithPadding(this RectangleF value, float sliceAmount, float padding, RectEdge fromEdge) + { + var slice = value.Divide(sliceAmount, fromEdge); + var pad = value.Divide(padding, fromEdge); + return Tuple.Create(slice.Item1, pad.Item2); + } - switch (fromEdge) - { - case RectEdge.Left: - delta = Math.Max(value.Width, amount); - return Tuple.Create( - value.Copy(width: delta), - value.Copy(x: value.Left + delta, width: value.Width - delta)); - case RectEdge.Top: - delta = Math.Max(value.Height, amount); - return Tuple.Create( - value.Copy(height: amount), - value.Copy(y: value.Top + delta, height: value.Height - delta)); - case RectEdge.Right: - delta = Math.Max(value.Width, amount); - return Tuple.Create( - value.Copy(x: value.Right - delta, width: delta), - value.Copy(width: value.Width - delta)); - case RectEdge.Bottom: - delta = Math.Max(value.Height, amount); - return Tuple.Create( - value.Copy(y: value.Bottom - delta, height: delta), - value.Copy(height: value.Height - delta)); - default: - throw new ArgumentException("edge"); - } - } + /// + /// Vertically inverts the coordinates of the rectangle within containingRect. + /// + /// value can effectively be used to change the coordinate system of a rectangle. + /// For example, if `rect` is defined for a coordinate system starting at the + /// top-left, the result will be a rectangle relative to the bottom-left. + /// + /// The rectangle to perform the calculation against. + /// The containing rectangle. + /// The inverted rentangle. + public static RectangleF InvertWithin(this RectangleF value, RectangleF containingRect) + { + return new(value.X, containingRect.Height - value.Bottom, value.Width, value.Height); + } - /// - /// Divide the specified Rectangle into two component rectangles, adding - /// a padding between them. - /// - /// The rectangle to perform the calculation against. - /// Amount to move away from the given edge. - /// The amount of padding that is in neither rectangle. - /// The edge to create the slice from. - /// The set of rectangles that are generated. - public static Tuple DivideWithPadding(this RectangleF value, float sliceAmount, float padding, RectEdge fromEdge) + /// + /// Creates a new RectangleF as a Copy of an existing one . + /// + /// value is useful when you have a rectangle that is almost what you + /// want, but you just want to change a couple properties. + /// + /// The rectangle to perform the calculation against. + /// Optional new x coordinate of the rectangle to use. + /// Optional new y coordinate of the rectangle to use. + /// Optional new width of the rectangle to use. + /// Optional new height of the rectangle to use. + /// Optional new top of the rectangle to use. + /// Optional new bottom of the rectangle to use. + /// The copied rectangle. + public static RectangleF Copy( + this RectangleF value, + float? x = null, + float? y = null, + float? width = null, + float? height = null, + float? top = null, + float? bottom = null) + { + var newRect = new RectangleF(value.Location, value.Size); + + if (x.HasValue) { - var slice = value.Divide(sliceAmount, fromEdge); - var pad = value.Divide(padding, fromEdge); - return Tuple.Create(slice.Item1, pad.Item2); + newRect.X = x.Value; } - /// - /// Vertically inverts the coordinates of the rectangle within containingRect. - /// - /// value can effectively be used to change the coordinate system of a rectangle. - /// For example, if `rect` is defined for a coordinate system starting at the - /// top-left, the result will be a rectangle relative to the bottom-left. - /// - /// The rectangle to perform the calculation against. - /// The containing rectangle. - /// The inverted rentangle. - public static RectangleF InvertWithin(this RectangleF value, RectangleF containingRect) + if (y.HasValue) { - return new(value.X, containingRect.Height - value.Bottom, value.Width, value.Height); + newRect.Y = y.Value; } - /// - /// Creates a new RectangleF as a Copy of an existing one . - /// - /// value is useful when you have a rectangle that is almost what you - /// want, but you just want to change a couple properties. - /// - /// The rectangle to perform the calculation against. - /// Optional new x coordinate of the rectangle to use. - /// Optional new y coordinate of the rectangle to use. - /// Optional new width of the rectangle to use. - /// Optional new height of the rectangle to use. - /// Optional new top of the rectangle to use. - /// Optional new bottom of the rectangle to use. - /// The copied rectangle. - public static RectangleF Copy( - this RectangleF value, - float? x = null, - float? y = null, - float? width = null, - float? height = null, - float? top = null, - float? bottom = null) + if (width.HasValue) { - var newRect = new RectangleF(value.Location, value.Size); + newRect.Width = width.Value; + } - if (x.HasValue) - { - newRect.X = x.Value; - } + if (height.HasValue) + { + newRect.Height = height.Value; + } + if (top.HasValue) + { if (y.HasValue) { - newRect.Y = y.Value; + throw new ArgumentException("Conflicting Copy arguments Y and Top"); } - if (width.HasValue) - { - newRect.Width = width.Value; - } + newRect.Y = top.Value; + } + if (bottom.HasValue) + { if (height.HasValue) { - newRect.Height = height.Value; - } - - if (top.HasValue) - { - if (y.HasValue) - { - throw new ArgumentException("Conflicting Copy arguments Y and Top"); - } - - newRect.Y = top.Value; - } - - if (bottom.HasValue) - { - if (height.HasValue) - { - throw new ArgumentException("Conflicting Copy arguments Height and Bottom"); - } - - newRect.Height = newRect.Y + bottom.Value; + throw new ArgumentException("Conflicting Copy arguments Height and Bottom"); } - return newRect; + newRect.Height = newRect.Y + bottom.Value; } + + return newRect; } } diff --git a/src/Splat/Maths/SizeMathExtensions.cs b/src/Splat/Maths/SizeMathExtensions.cs index 22631ff96..9b5c0cc00 100644 --- a/src/Splat/Maths/SizeMathExtensions.cs +++ b/src/Splat/Maths/SizeMathExtensions.cs @@ -6,36 +6,35 @@ using System; using System.Drawing; -namespace Splat +namespace Splat; + +/// +/// Extension methods to assist with the struct. +/// +public static class SizeMathExtensions { /// - /// Extension methods to assist with the struct. + /// Determines whether two sizes are within epsilon of each other. /// - public static class SizeMathExtensions + /// The size we doing the operation against. + /// The size to compare if we are equal to. + /// The tolerated epsilon value. + /// If the value is equal based on the epsilon. + public static bool WithinEpsilonOf(this SizeF value, SizeF other, float epsilon) { - /// - /// Determines whether two sizes are within epsilon of each other. - /// - /// The size we doing the operation against. - /// The size to compare if we are equal to. - /// The tolerated epsilon value. - /// If the value is equal based on the epsilon. - public static bool WithinEpsilonOf(this SizeF value, SizeF other, float epsilon) - { - var deltaW = other.Width - value.Width; - var deltaH = other.Height - value.Height; - return Math.Sqrt((deltaW * deltaW) + (deltaH * deltaH)) < epsilon; - } + var deltaW = other.Width - value.Width; + var deltaH = other.Height - value.Height; + return Math.Sqrt((deltaW * deltaW) + (deltaH * deltaH)) < epsilon; + } - /// - /// Scales a size by a scalar value. - /// - /// The size we doing the operation against. - /// The amount to scale by. - /// The scaled size. - public static SizeF ScaledBy(this SizeF value, float factor) - { - return new(value.Width * factor, value.Height * factor); - } + /// + /// Scales a size by a scalar value. + /// + /// The size we doing the operation against. + /// The amount to scale by. + /// The scaled size. + public static SizeF ScaledBy(this SizeF value, float factor) + { + return new(value.Width * factor, value.Height * factor); } } diff --git a/src/Splat/MemoizingMRUCache.cs b/src/Splat/MemoizingMRUCache.cs index d4997d8ed..e56f8c970 100644 --- a/src/Splat/MemoizingMRUCache.cs +++ b/src/Splat/MemoizingMRUCache.cs @@ -7,319 +7,317 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; -using System.Threading; -namespace Splat +namespace Splat; + +/// +/// This data structure is a representation of a memoizing cache - i.e. a +/// class that will evaluate a function, but keep a cache of recently +/// evaluated parameters. +/// +/// Since this is a memoizing cache, it is important that this function be a +/// "pure" function in the mathematical sense - that a key *always* maps to +/// a corresponding return value. +/// +/// The type of the parameter to the calculation function. +/// The type of the value returned by the calculation +/// function. +public sealed class MemoizingMRUCache + where TParam : notnull { + private readonly object _lockObject = new(); + private readonly Func _calculationFunction; + private readonly Action? _releaseFunction; + private readonly int _maxCacheSize; + + private readonly IEqualityComparer _comparer; + + private LinkedList _cacheMRUList; + private Dictionary param, TVal value)> _cacheEntries; + /// - /// This data structure is a representation of a memoizing cache - i.e. a - /// class that will evaluate a function, but keep a cache of recently - /// evaluated parameters. - /// - /// Since this is a memoizing cache, it is important that this function be a - /// "pure" function in the mathematical sense - that a key *always* maps to - /// a corresponding return value. + /// Initializes a new instance of the class. /// - /// The type of the parameter to the calculation function. - /// The type of the value returned by the calculation - /// function. - public sealed class MemoizingMRUCache - where TParam : notnull + /// The function whose results you want to cache, + /// which is provided the key value, and an Tag object that is + /// user-defined. + /// The size of the cache to maintain, after which old + /// items will start to be thrown out. + public MemoizingMRUCache(Func calculationFunc, int maxSize) + : this(calculationFunc, maxSize, null, EqualityComparer.Default) { - private readonly object _lockObject = new(); - private readonly Func _calculationFunction; - private readonly Action? _releaseFunction; - private readonly int _maxCacheSize; - - private readonly IEqualityComparer _comparer; - - private LinkedList _cacheMRUList; - private Dictionary param, TVal value)> _cacheEntries; - - /// - /// Initializes a new instance of the class. - /// - /// The function whose results you want to cache, - /// which is provided the key value, and an Tag object that is - /// user-defined. - /// The size of the cache to maintain, after which old - /// items will start to be thrown out. - public MemoizingMRUCache(Func calculationFunc, int maxSize) - : this(calculationFunc, maxSize, null, EqualityComparer.Default) - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// The function whose results you want to cache, - /// which is provided the key value, and an Tag object that is - /// user-defined. - /// The size of the cache to maintain, after which old - /// items will start to be thrown out. - /// A function to call when a result gets - /// evicted from the cache (i.e. because Invalidate was called or the - /// cache is full). - public MemoizingMRUCache(Func calculationFunc, int maxSize, Action onRelease) - : this(calculationFunc, maxSize, onRelease, EqualityComparer.Default) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The function whose results you want to cache, + /// which is provided the key value, and an Tag object that is + /// user-defined. + /// The size of the cache to maintain, after which old + /// items will start to be thrown out. + /// A function to call when a result gets + /// evicted from the cache (i.e. because Invalidate was called or the + /// cache is full). + public MemoizingMRUCache(Func calculationFunc, int maxSize, Action onRelease) + : this(calculationFunc, maxSize, onRelease, EqualityComparer.Default) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The function whose results you want to cache, + /// which is provided the key value, and an Tag object that is + /// user-defined. + /// The size of the cache to maintain, after which old + /// items will start to be thrown out. + /// A comparer for the parameter. + public MemoizingMRUCache(Func calculationFunc, int maxSize, IEqualityComparer paramComparer) + : this(calculationFunc, maxSize, null, paramComparer) + { + } - /// - /// Initializes a new instance of the class. - /// - /// The function whose results you want to cache, - /// which is provided the key value, and an Tag object that is - /// user-defined. - /// The size of the cache to maintain, after which old - /// items will start to be thrown out. - /// A comparer for the parameter. - public MemoizingMRUCache(Func calculationFunc, int maxSize, IEqualityComparer paramComparer) - : this(calculationFunc, maxSize, null, paramComparer) + /// + /// Initializes a new instance of the class. + /// + /// The function whose results you want to cache, + /// which is provided the key value, and an Tag object that is + /// user-defined. + /// The size of the cache to maintain, after which old + /// items will start to be thrown out. + /// A function to call when a result gets + /// evicted from the cache (i.e. because Invalidate was called or the + /// cache is full). + /// A comparer for the parameter. + public MemoizingMRUCache(Func calculationFunc, int maxSize, Action? onRelease, IEqualityComparer paramComparer) + { + if (maxSize <= 0) { + throw new ArgumentException("Max size must be larger than 0.", nameof(maxSize)); } - /// - /// Initializes a new instance of the class. - /// - /// The function whose results you want to cache, - /// which is provided the key value, and an Tag object that is - /// user-defined. - /// The size of the cache to maintain, after which old - /// items will start to be thrown out. - /// A function to call when a result gets - /// evicted from the cache (i.e. because Invalidate was called or the - /// cache is full). - /// A comparer for the parameter. - public MemoizingMRUCache(Func calculationFunc, int maxSize, Action? onRelease, IEqualityComparer paramComparer) - { - if (maxSize <= 0) - { - throw new ArgumentException("Max size must be larger than 0.", nameof(maxSize)); - } + _calculationFunction = calculationFunc ?? throw new ArgumentNullException(nameof(calculationFunc)); + _releaseFunction = onRelease; + _maxCacheSize = maxSize; + _comparer = paramComparer ?? EqualityComparer.Default; + _cacheMRUList = new LinkedList(); + _cacheEntries = new Dictionary param, TVal value)>(); + } - _calculationFunction = calculationFunc ?? throw new ArgumentNullException(nameof(calculationFunc)); - _releaseFunction = onRelease; - _maxCacheSize = maxSize; - _comparer = paramComparer ?? EqualityComparer.Default; - _cacheMRUList = new LinkedList(); - _cacheEntries = new Dictionary param, TVal value)>(); + /// + /// Gets the value from the specified key. + /// + /// The value to pass to the calculation function. + /// The value that we have got. + public TVal Get(TParam key) => Get(key, null); + + /// + /// Evaluates the function provided, returning the cached value if possible. + /// + /// The value to pass to the calculation function. + /// An additional optional user-specific parameter. + /// The value that we have got. + public TVal Get(TParam key, object? context = null) + { + if (key is null) + { + throw new ArgumentNullException(nameof(key)); } - /// - /// Gets the value from the specified key. - /// - /// The value to pass to the calculation function. - /// The value that we have got. - public TVal Get(TParam key) => Get(key, null); - - /// - /// Evaluates the function provided, returning the cached value if possible. - /// - /// The value to pass to the calculation function. - /// An additional optional user-specific parameter. - /// The value that we have got. - public TVal Get(TParam key, object? context = null) + lock (_lockObject) { - if (key is null) + if (_cacheEntries.TryGetValue(key, out var found)) { - throw new ArgumentNullException(nameof(key)); - } + RefreshEntry(found.param); - lock (_lockObject) - { - if (_cacheEntries.TryGetValue(key, out var found)) - { - RefreshEntry(found.param); + return found.value; + } - return found.value; - } + var result = _calculationFunction(key, context); - var result = _calculationFunction(key, context); + var node = new LinkedListNode(key); + _cacheMRUList.AddFirst(node); + _cacheEntries[key] = (node, result); + MaintainCache(); - var node = new LinkedListNode(key); - _cacheMRUList.AddFirst(node); - _cacheEntries[key] = (node, result); - MaintainCache(); + return result; + } + } - return result; - } + /// + /// Tries to get the value if it's available. + /// + /// The input value of the key to use. + /// The result if available, otherwise it will be the default value. + /// If we were able to retrieve the value or not. + public bool TryGet(TParam key, out TVal? result) + { + if (key is null) + { + throw new ArgumentNullException(nameof(key)); } - /// - /// Tries to get the value if it's available. - /// - /// The input value of the key to use. - /// The result if available, otherwise it will be the default value. - /// If we were able to retrieve the value or not. - public bool TryGet(TParam key, out TVal? result) + lock (_lockObject) { - if (key is null) + var ret = _cacheEntries.TryGetValue(key, out var output); + if (ret) { - throw new ArgumentNullException(nameof(key)); + RefreshEntry(output.param); + result = output.value; } - - lock (_lockObject) + else { - var ret = _cacheEntries.TryGetValue(key, out var output); - if (ret) - { - RefreshEntry(output.param); - result = output.value; - } - else - { - result = default; - } - - return ret; + result = default; } + + return ret; } + } - /// - /// Ensure that the next time this key is queried, the calculation - /// function will be called. - /// - /// The key to invalidate the value for. - public void Invalidate(TParam key) + /// + /// Ensure that the next time this key is queried, the calculation + /// function will be called. + /// + /// The key to invalidate the value for. + public void Invalidate(TParam key) + { + if (key is null) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } + throw new ArgumentNullException(nameof(key)); + } - lock (_lockObject) + lock (_lockObject) + { + if (!_cacheEntries.TryGetValue(key, out var toRemove)) { - if (!_cacheEntries.TryGetValue(key, out var toRemove)) - { - return; - } + return; + } - var releaseVar = toRemove.value; + var releaseVar = toRemove.value; - _cacheMRUList.Remove(toRemove.param); - _cacheEntries.Remove(key); + _cacheMRUList.Remove(toRemove.param); + _cacheEntries.Remove(key); - // moved down to allow removal from list - // even if the release call fails. - _releaseFunction?.Invoke(releaseVar); - } + // moved down to allow removal from list + // even if the release call fails. + _releaseFunction?.Invoke(releaseVar); } + } - /// - /// Invalidate all the items in the cache. - /// - /// - /// Flag to indicate whether Exceptions during the resource Release call should not fail on the first item. - /// But should try all items then throw an aggregate exception. - /// - public void InvalidateAll(bool aggregateReleaseExceptions = false) + /// + /// Invalidate all the items in the cache. + /// + /// + /// Flag to indicate whether Exceptions during the resource Release call should not fail on the first item. + /// But should try all items then throw an aggregate exception. + /// + public void InvalidateAll(bool aggregateReleaseExceptions = false) + { + Dictionary param, TVal value)>? oldCacheToClear = null; + lock (_lockObject) { - Dictionary param, TVal value)>? oldCacheToClear = null; - lock (_lockObject) + if (_releaseFunction is null || _cacheEntries is null) { - if (_releaseFunction is null || _cacheEntries is null) - { - _cacheMRUList = new LinkedList(); - _cacheEntries = new Dictionary param, TVal value)>(_comparer); - return; - } - - if (_cacheEntries.Count == 0) - { - return; - } - - // by moving to a temp variable - // can free up the lock quicker for other calls to MRU - // no point doing it, if nothing to release - oldCacheToClear = _cacheEntries; - _cacheMRUList = new LinkedList(); _cacheEntries = new Dictionary param, TVal value)>(_comparer); + return; } - if (oldCacheToClear is null) + if (_cacheEntries.Count == 0) { return; } - if (aggregateReleaseExceptions) + // by moving to a temp variable + // can free up the lock quicker for other calls to MRU + // no point doing it, if nothing to release + oldCacheToClear = _cacheEntries; + + _cacheMRUList = new LinkedList(); + _cacheEntries = new Dictionary param, TVal value)>(_comparer); + } + + if (oldCacheToClear is null) + { + return; + } + + if (aggregateReleaseExceptions) + { + var exceptions = new List(oldCacheToClear.Count); + foreach (var item in oldCacheToClear) { - var exceptions = new List(oldCacheToClear.Count); - foreach (var item in oldCacheToClear) + try { - try - { - _releaseFunction?.Invoke(item.Value.value); - } - catch (Exception e) - { - exceptions.Add(e); - } + _releaseFunction?.Invoke(item.Value.value); } - - if (exceptions.Count > 0) + catch (Exception e) { - throw new AggregateException("Exceptions throw during MRU Cache Invalidate All Item Release.", exceptions); + exceptions.Add(e); } - - return; } - // release mechanism that will throw on first failure. - // but they've still been removed from the active cache - // as the cache field was reassigned. - foreach (var item in oldCacheToClear) + if (exceptions.Count > 0) { - _releaseFunction?.Invoke(item.Value.value); + throw new AggregateException("Exceptions throw during MRU Cache Invalidate All Item Release.", exceptions); } + + return; } - /// - /// Returns all values currently in the cache. - /// - /// The values in the cache. - public IEnumerable CachedValues() + // release mechanism that will throw on first failure. + // but they've still been removed from the active cache + // as the cache field was reassigned. + foreach (var item in oldCacheToClear) { - lock (_lockObject) - { - return _cacheEntries.Select(x => x.Value.value); - } + _releaseFunction?.Invoke(item.Value.value); } + } - private void MaintainCache() + /// + /// Returns all values currently in the cache. + /// + /// The values in the cache. + public IEnumerable CachedValues() + { + lock (_lockObject) { - while (_cacheMRUList.Count > _maxCacheSize) - { - if (_cacheMRUList.Last is null) - { - continue; - } - - var toRemove = _cacheMRUList.Last.Value; - _releaseFunction?.Invoke(_cacheEntries[toRemove].value); - - _cacheEntries.Remove(_cacheMRUList.Last.Value); - _cacheMRUList.RemoveLast(); - } + return _cacheEntries.Select(x => x.Value.value); } + } - private void RefreshEntry(LinkedListNode item) + private void MaintainCache() + { + while (_cacheMRUList.Count > _maxCacheSize) { - // only juggle entries if more than 1 of them. - if (_cacheEntries.Count > 1) + if (_cacheMRUList.Last is null) { - _cacheMRUList.Remove(item); - _cacheMRUList.AddFirst(item); + continue; } + + var toRemove = _cacheMRUList.Last.Value; + _releaseFunction?.Invoke(_cacheEntries[toRemove].value); + + _cacheEntries.Remove(_cacheMRUList.Last.Value); + _cacheMRUList.RemoveLast(); } + } - [ContractInvariantMethod] - private void Invariants() + private void RefreshEntry(LinkedListNode item) + { + // only juggle entries if more than 1 of them. + if (_cacheEntries.Count > 1) { - Contract.Invariant(_cacheEntries.Count == _cacheMRUList.Count); - Contract.Invariant(_cacheEntries.Count <= _maxCacheSize); + _cacheMRUList.Remove(item); + _cacheMRUList.AddFirst(item); } } + + [ContractInvariantMethod] + private void Invariants() + { + Contract.Invariant(_cacheEntries.Count == _cacheMRUList.Count); + Contract.Invariant(_cacheEntries.Count <= _maxCacheSize); + } } diff --git a/src/Splat/ModeDetection/DefaultModeDetector.cs b/src/Splat/ModeDetection/DefaultModeDetector.cs index 568790ed1..c4f1b25ff 100644 --- a/src/Splat/ModeDetection/DefaultModeDetector.cs +++ b/src/Splat/ModeDetection/DefaultModeDetector.cs @@ -5,50 +5,48 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; -namespace Splat +namespace Splat; + +/// +/// Contains the default mode detector to detect if we are currently in a unit test. +/// +public class DefaultModeDetector : IModeDetector, IEnableLogger { - /// - /// Contains the default mode detector to detect if we are currently in a unit test. - /// - public class DefaultModeDetector : IModeDetector, IEnableLogger + /// + public bool? InUnitTestRunner() { - /// - public bool? InUnitTestRunner() + var testAssemblies = new[] { - var testAssemblies = new[] - { - "CSUNIT", - "NUNIT", - "XUNIT", - "MBUNIT", - "NBEHAVE", - "VISUALSTUDIO.QUALITYTOOLS", - "VISUALSTUDIO.TESTPLATFORM", - "FIXIE", - "NCRUNCH", - }; + "CSUNIT", + "NUNIT", + "XUNIT", + "MBUNIT", + "NBEHAVE", + "VISUALSTUDIO.QUALITYTOOLS", + "VISUALSTUDIO.TESTPLATFORM", + "FIXIE", + "NCRUNCH", + }; - try - { - return SearchForAssembly(testAssemblies); - } - catch (Exception e) - { - this.Log().Debug(e, "Unable to find unit test runner value"); - return null; - } + try + { + return SearchForAssembly(testAssemblies); } - - private static bool SearchForAssembly(IEnumerable assemblyList) + catch (Exception e) { - return AppDomain.CurrentDomain.GetAssemblies() - .Select(x => x.FullName?.ToUpperInvariant()) - .Where(x => x is not null) - .Select(x => x!) - .Any(x => assemblyList.Any(name => x.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1)); + this.Log().Debug(e, "Unable to find unit test runner value"); + return null; } } + + private static bool SearchForAssembly(IEnumerable assemblyList) + { + return AppDomain.CurrentDomain.GetAssemblies() + .Select(x => x.FullName?.ToUpperInvariant()) + .Where(x => x is not null) + .Select(x => x!) + .Any(x => assemblyList.Any(name => x.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1)); + } } diff --git a/src/Splat/ModeDetection/IModeDetector.cs b/src/Splat/ModeDetection/IModeDetector.cs index 1222d9565..54a9da33b 100644 --- a/src/Splat/ModeDetection/IModeDetector.cs +++ b/src/Splat/ModeDetection/IModeDetector.cs @@ -3,17 +3,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// Detects if unit tests or design mode are currently running for the current application or library. +/// +public interface IModeDetector { /// - /// Detects if unit tests or design mode are currently running for the current application or library. + /// Gets a value indicating whether the current library or application is running through a unit test. /// - public interface IModeDetector - { - /// - /// Gets a value indicating whether the current library or application is running through a unit test. - /// - /// If we are currently running in a unit test. - bool? InUnitTestRunner(); - } + /// If we are currently running in a unit test. + bool? InUnitTestRunner(); } diff --git a/src/Splat/ModeDetection/Mode.cs b/src/Splat/ModeDetection/Mode.cs index 47c462357..d6ffe5aa2 100644 --- a/src/Splat/ModeDetection/Mode.cs +++ b/src/Splat/ModeDetection/Mode.cs @@ -3,28 +3,27 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat.ModeDetection +namespace Splat.ModeDetection; + +/// +/// The default implementation of the and mode. +/// +public sealed class Mode : IModeDetector { /// - /// The default implementation of the and mode. + /// The default implementation of the run mode. /// - public sealed class Mode : IModeDetector - { - /// - /// The default implementation of the run mode. - /// - public static readonly Mode Run = new(false); + public static readonly Mode Run = new(false); - /// - /// The default implementation of the test mode. - /// - public static readonly Mode Test = new(true); + /// + /// The default implementation of the test mode. + /// + public static readonly Mode Test = new(true); - private readonly bool _inUnitTestRunner; + private readonly bool _inUnitTestRunner; - private Mode(bool inUnitTestRunner) => _inUnitTestRunner = inUnitTestRunner; + private Mode(bool inUnitTestRunner) => _inUnitTestRunner = inUnitTestRunner; - /// - public bool? InUnitTestRunner() => _inUnitTestRunner; - } + /// + public bool? InUnitTestRunner() => _inUnitTestRunner; } diff --git a/src/Splat/ModeDetection/ModeDetector.cs b/src/Splat/ModeDetection/ModeDetector.cs index 4369f8957..629b6c97a 100644 --- a/src/Splat/ModeDetection/ModeDetector.cs +++ b/src/Splat/ModeDetection/ModeDetector.cs @@ -3,61 +3,60 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -namespace Splat +namespace Splat; + +/// +/// A helper class which detect if we are currently running via a unit test or design mode. +/// +public static class ModeDetector { + private static bool? _cachedInUnitTestRunnerResult; + /// - /// A helper class which detect if we are currently running via a unit test or design mode. + /// Initializes static members of the class. /// - public static class ModeDetector + static ModeDetector() { - private static bool? _cachedInUnitTestRunnerResult; + Current = new DefaultModeDetector(); + } - /// - /// Initializes static members of the class. - /// - static ModeDetector() - { - Current = new DefaultModeDetector(); - } + /// + /// Gets or sets the current mode detector set. + /// + private static IModeDetector Current { get; set; } - /// - /// Gets or sets the current mode detector set. - /// - private static IModeDetector Current { get; set; } + /// + /// Overrides the mode detector with one of your own provided ones. + /// + /// The mode detector to use. + public static void OverrideModeDetector(IModeDetector modeDetector) + { + Current = modeDetector; + _cachedInUnitTestRunnerResult = null; + } - /// - /// Overrides the mode detector with one of your own provided ones. - /// - /// The mode detector to use. - public static void OverrideModeDetector(IModeDetector modeDetector) + /// + /// Gets a value indicating whether we are currently running from a unit test. + /// + /// If we are currently running from a unit test. + public static bool InUnitTestRunner() + { + if (_cachedInUnitTestRunnerResult.HasValue) { - Current = modeDetector; - _cachedInUnitTestRunnerResult = null; + return _cachedInUnitTestRunnerResult.Value; } - /// - /// Gets a value indicating whether we are currently running from a unit test. - /// - /// If we are currently running from a unit test. - public static bool InUnitTestRunner() + if (Current is not null) { + _cachedInUnitTestRunnerResult = Current.InUnitTestRunner(); if (_cachedInUnitTestRunnerResult.HasValue) { return _cachedInUnitTestRunnerResult.Value; } - - if (Current is not null) - { - _cachedInUnitTestRunnerResult = Current.InUnitTestRunner(); - if (_cachedInUnitTestRunnerResult.HasValue) - { - return _cachedInUnitTestRunnerResult.Value; - } - } - - // We have no sane platform-independent way to detect a unit test - // runner :-/ - return false; } + + // We have no sane platform-independent way to detect a unit test + // runner :-/ + return false; } } diff --git a/src/Splat/Properties/AssemblyInfo.cs b/src/Splat/Properties/AssemblyInfo.cs index 10d56132d..12f309784 100644 --- a/src/Splat/Properties/AssemblyInfo.cs +++ b/src/Splat/Properties/AssemblyInfo.cs @@ -3,7 +3,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Splat.Tests")] diff --git a/src/Splat/ServiceLocation/DependencyResolverMixins.cs b/src/Splat/ServiceLocation/DependencyResolverMixins.cs index 236a602f8..5aa702329 100644 --- a/src/Splat/ServiceLocation/DependencyResolverMixins.cs +++ b/src/Splat/ServiceLocation/DependencyResolverMixins.cs @@ -7,227 +7,225 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// A set of extension methods that assist with the and interfaces. +/// +public static class DependencyResolverMixins { /// - /// A set of extension methods that assist with the and interfaces. + /// Gets an instance of the given . Must return null + /// if the service is not available (must not throw). /// - public static class DependencyResolverMixins + /// The type for the object we want to retrieve. + /// The resolver we are getting the service from. + /// A optional value which will retrieve only a object registered with the same contract. + /// The requested object, if found; null otherwise. + public static T? GetService(this IReadonlyDependencyResolver resolver, string? contract = null) { - /// - /// Gets an instance of the given . Must return null - /// if the service is not available (must not throw). - /// - /// The type for the object we want to retrieve. - /// The resolver we are getting the service from. - /// A optional value which will retrieve only a object registered with the same contract. - /// The requested object, if found; null otherwise. - public static T? GetService(this IReadonlyDependencyResolver resolver, string? contract = null) + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - return (T?)resolver.GetService(typeof(T), contract); + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Gets all instances of the given . Must return an empty - /// collection if the service is not available (must not return null or throw). - /// - /// The type for the object we want to retrieve. - /// The resolver we are getting the service from. - /// A optional value which will retrieve only a object registered with the same contract. - /// A sequence of instances of the requested . The sequence - /// 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 (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + return (T?)resolver.GetService(typeof(T), contract); + } - return resolver.GetServices(typeof(T), contract).Cast(); + /// + /// Gets all instances of the given . Must return an empty + /// collection if the service is not available (must not return null or throw). + /// + /// The type for the object we want to retrieve. + /// The resolver we are getting the service from. + /// A optional value which will retrieve only a object registered with the same contract. + /// A sequence of instances of the requested . The sequence + /// 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 (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a new callback that occurs when a new service with the specified type is registered. - /// - /// The resolver we want to register the callback with. - /// The service type we are wanting to observe. - /// The callback which should be called. - /// A disposable which will stop notifications to the callback. - public static IDisposable ServiceRegistrationCallback(this IMutableDependencyResolver resolver, Type serviceType, Action callback) - { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + return resolver.GetServices(typeof(T), contract).Cast(); + } - return resolver.ServiceRegistrationCallback(serviceType, null, callback); + /// + /// Registers a new callback that occurs when a new service with the specified type is registered. + /// + /// The resolver we want to register the callback with. + /// The service type we are wanting to observe. + /// The callback which should be called. + /// A disposable which will stop notifications to the callback. + public static IDisposable ServiceRegistrationCallback(this IMutableDependencyResolver resolver, Type serviceType, Action callback) + { + if (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Override the default Dependency Resolver until the object returned - /// is disposed. - /// - /// The test resolver to use. - /// If we should suppress the resolver callback notify. - /// A disposable which will reset the resolver back to the original. - public static IDisposable WithResolver(this IDependencyResolver resolver, bool suppressResolverCallback = true) + return resolver.ServiceRegistrationCallback(serviceType, null, callback); + } + + /// + /// Override the default Dependency Resolver until the object returned + /// is disposed. + /// + /// The test resolver to use. + /// If we should suppress the resolver callback notify. + /// A disposable which will reset the resolver back to the original. + public static IDisposable WithResolver(this IDependencyResolver resolver, bool suppressResolverCallback = true) + { + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + throw new ArgumentNullException(nameof(resolver)); + } - var notificationDisposable = suppressResolverCallback ? Locator.SuppressResolverCallbackChangedNotifications() : ActionDisposable.Empty; + var notificationDisposable = suppressResolverCallback ? Locator.SuppressResolverCallbackChangedNotifications() : ActionDisposable.Empty; - var origResolver = Locator.GetLocator(); - Locator.SetLocator(resolver); + var origResolver = Locator.GetLocator(); + Locator.SetLocator(resolver); - return new CompositeDisposable(new ActionDisposable(() => Locator.SetLocator(origResolver)), notificationDisposable); - } + return new CompositeDisposable(new ActionDisposable(() => Locator.SetLocator(origResolver)), notificationDisposable); + } - /// - /// Registers a factory for the given . - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// A factory method for generating a object of the specified type. - /// 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) + /// + /// Registers a factory for the given . + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// A factory method for generating a object of the specified type. + /// 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 (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - resolver.Register(() => factory(), typeof(T), contract); + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a factory for the given . - /// - /// The type to register as. - /// The service type to register for. - /// The resolver to register the service type with. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - public static void Register(this IMutableDependencyResolver resolver, string? contract = null) - where T : new() + if (factory is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - resolver.Register(() => new T(), typeof(TAs), contract); + throw new ArgumentNullException(nameof(factory)); } - /// - /// Registers a constant value which will always return the specified object instance. - /// - /// The resolver to register the service type with. - /// The specified instance to always return. - /// The type of service to register. - /// 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 (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + resolver.Register(() => factory(), typeof(T), contract); + } - resolver.Register(() => value, serviceType, contract); + /// + /// Registers a factory for the given . + /// + /// The type to register as. + /// The service type to register for. + /// The resolver to register the service type with. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + public static void Register(this IMutableDependencyResolver resolver, string? contract = null) + where T : new() + { + if (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a constant value which will always return the specified object instance. - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// The specified instance to always return. - /// 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 (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + resolver.Register(() => new T(), typeof(TAs), contract); + } - RegisterConstant(resolver, value, typeof(T), contract); + /// + /// Registers a constant value which will always return the specified object instance. + /// + /// The resolver to register the service type with. + /// The specified instance to always return. + /// The type of service to register. + /// 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 (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a lazy singleton value which will always return the specified object instance once created. - /// The value is only generated once someone requests the service from the resolver. - /// - /// The resolver to register the service type with. - /// A factory method for generating a object of the specified type. - /// The type of service to register. - /// 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 (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + resolver.Register(() => value, serviceType, contract); + } - var val = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); - resolver.Register(() => val.Value, serviceType, contract); + /// + /// Registers a constant value which will always return the specified object instance. + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// The specified instance to always return. + /// 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 (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a lazy singleton value which will always return the specified object instance once created. - /// The value is only generated once someone requests the service from the resolver. - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// A factory method for generating a object of the specified type. - /// 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, string? contract = null) + RegisterConstant(resolver, value, typeof(T), contract); + } + + /// + /// Registers a lazy singleton value which will always return the specified object instance once created. + /// The value is only generated once someone requests the service from the resolver. + /// + /// The resolver to register the service type with. + /// A factory method for generating a object of the specified type. + /// The type of service to register. + /// 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 (resolver is null) { - RegisterLazySingleton(resolver, () => valueFactory(), typeof(T), contract); + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Unregisters the current the value for the specified type and the optional contract. - /// - /// The type of item to unregister. - /// The resolver to unregister the service with. - /// 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 (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + var val = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); + resolver.Register(() => val.Value, serviceType, contract); + } - resolver.UnregisterCurrent(typeof(T), contract); - } + /// + /// Registers a lazy singleton value which will always return the specified object instance once created. + /// The value is only generated once someone requests the service from the resolver. + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// A factory method for generating a object of the specified type. + /// 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, string? contract = null) + { + RegisterLazySingleton(resolver, () => valueFactory(), typeof(T), contract); + } - /// - /// Unregisters the all the values for the specified type and the optional contract. - /// - /// The type of items to unregister. - /// The resolver to unregister the services with. - /// A optional contract which indicates to only removed those items registered with this contract. - public static void UnregisterAll(this IMutableDependencyResolver resolver, string? contract = null) + /// + /// Unregisters the current the value for the specified type and the optional contract. + /// + /// The type of item to unregister. + /// The resolver to unregister the service with. + /// 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 (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + throw new ArgumentNullException(nameof(resolver)); + } + + resolver.UnregisterCurrent(typeof(T), contract); + } - resolver.UnregisterAll(typeof(T), contract); + /// + /// Unregisters the all the values for the specified type and the optional contract. + /// + /// The type of items to unregister. + /// The resolver to unregister the services with. + /// 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 (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } + + resolver.UnregisterAll(typeof(T), contract); } } diff --git a/src/Splat/ServiceLocation/FuncDependencyResolver.cs b/src/Splat/ServiceLocation/FuncDependencyResolver.cs index 0679690ea..c2671fc0c 100644 --- a/src/Splat/ServiceLocation/FuncDependencyResolver.cs +++ b/src/Splat/ServiceLocation/FuncDependencyResolver.cs @@ -8,194 +8,193 @@ using System.Linq; using System.Threading; -namespace Splat +namespace Splat; + +/// +/// A simple dependency resolver which takes Funcs for all its actions. +/// GetService is always implemented via GetServices().LastOrDefault(). +/// This container is not thread safe. +/// +public class FuncDependencyResolver : IDependencyResolver { + private readonly Func> _innerGetServices; + private readonly Action, Type?, string?>? _innerRegister; + private readonly Action? _unregisterCurrent; + private readonly Action? _unregisterAll; + private readonly Dictionary<(Type? type, string callback), List>> _callbackRegistry = new(); + + private IDisposable _inner; + private bool _isDisposed; + /// - /// A simple dependency resolver which takes Funcs for all its actions. - /// GetService is always implemented via GetServices().LastOrDefault(). - /// This container is not thread safe. + /// Initializes a new instance of the class. /// - public class FuncDependencyResolver : IDependencyResolver + /// A func which will return all the services contained for the specified service type and contract. + /// A func which will be called when a service type and contract are registered. + /// A func which will unregister the current registered element for a service type and contract. + /// A func which will unregister all the registered elements for a service type and contract. + /// A optional disposable which is called when this resolver is disposed. + public FuncDependencyResolver( + Func> getAllServices, + Action, Type?, string?>? register = null, + Action? unregisterCurrent = null, + Action? unregisterAll = null, + IDisposable? toDispose = null) { - private readonly Func> _innerGetServices; - private readonly Action, Type?, string?>? _innerRegister; - private readonly Action? _unregisterCurrent; - private readonly Action? _unregisterAll; - private readonly Dictionary<(Type? type, string callback), List>> _callbackRegistry = new(); - - private IDisposable _inner; - private bool _isDisposed; - - /// - /// Initializes a new instance of the class. - /// - /// A func which will return all the services contained for the specified service type and contract. - /// A func which will be called when a service type and contract are registered. - /// A func which will unregister the current registered element for a service type and contract. - /// A func which will unregister all the registered elements for a service type and contract. - /// A optional disposable which is called when this resolver is disposed. - public FuncDependencyResolver( - Func> getAllServices, - Action, Type?, string?>? register = null, - Action? unregisterCurrent = null, - Action? unregisterAll = null, - IDisposable? toDispose = null) + _innerGetServices = getAllServices; + _innerRegister = register; + _unregisterCurrent = unregisterCurrent; + _unregisterAll = unregisterAll; + _inner = toDispose ?? ActionDisposable.Empty; + } + + /// + public object? GetService(Type? serviceType, string? contract = null) => + GetServices(serviceType, contract).LastOrDefault(); + + /// + public IEnumerable GetServices(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - _innerGetServices = getAllServices; - _innerRegister = register; - _unregisterCurrent = unregisterCurrent; - _unregisterAll = unregisterAll; - _inner = toDispose ?? ActionDisposable.Empty; + serviceType = typeof(NullServiceType); } - /// - public object? GetService(Type? serviceType, string? contract = null) => - GetServices(serviceType, contract).LastOrDefault(); + return _innerGetServices(serviceType, contract) ?? Array.Empty(); + } - /// - public IEnumerable GetServices(Type? serviceType, string? contract = null) + /// + public bool HasRegistration(Type? serviceType, string? contract = null) + { + if (serviceType is null) { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - return _innerGetServices(serviceType, contract) ?? Array.Empty(); + serviceType = typeof(NullServiceType); } - /// - public bool HasRegistration(Type? serviceType, string? contract = null) - { - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + return _innerGetServices(serviceType, contract) is not null; + } - return _innerGetServices(serviceType, contract) is not null; + /// + public void Register(Func factory, Type? serviceType, string? contract = null) + { + if (_innerRegister is null) + { + throw new NotImplementedException(); } - /// - public void Register(Func factory, Type? serviceType, string? contract = null) + var isNull = serviceType is null; + + if (serviceType is null) { - if (_innerRegister is null) - { - throw new NotImplementedException(); - } + serviceType = typeof(NullServiceType); + } - var isNull = serviceType is null; + _innerRegister( + () => + isNull + ? new NullServiceType(factory) + : factory(), + serviceType, + contract); - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - _innerRegister( - () => - isNull - ? new NullServiceType(factory) - : factory(), - serviceType, - contract); + var pair = (serviceType, contract ?? string.Empty); - var pair = (serviceType, contract ?? string.Empty); + if (_callbackRegistry.ContainsKey(pair)) + { + List>? toRemove = null; - if (_callbackRegistry.ContainsKey(pair)) + foreach (var callback in _callbackRegistry[pair]) { - List>? toRemove = null; + var disp = new BooleanDisposable(); - foreach (var callback in _callbackRegistry[pair]) - { - var disp = new BooleanDisposable(); + callback(disp); - callback(disp); - - if (disp.IsDisposed) - { - (toRemove ??= new List>()).Add(callback); - } + if (disp.IsDisposed) + { + (toRemove ??= new List>()).Add(callback); } + } - if (toRemove is not null) + if (toRemove is not null) + { + foreach (var c in toRemove) { - foreach (var c in toRemove) - { - _callbackRegistry[pair].Remove(c); - } + _callbackRegistry[pair].Remove(c); } } } + } - /// - public void UnregisterCurrent(Type? serviceType, string? contract = null) + /// + public void UnregisterCurrent(Type? serviceType, string? contract = null) + { + if (_unregisterCurrent is null) { - if (_unregisterCurrent is null) - { - throw new NotImplementedException(); - } - - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } - - _unregisterCurrent.Invoke(serviceType, contract); + throw new NotImplementedException(); } - /// - public void UnregisterAll(Type? serviceType, string? contract = null) + if (serviceType is null) { - if (_unregisterAll is null) - { - throw new NotImplementedException(); - } + serviceType = typeof(NullServiceType); + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + _unregisterCurrent.Invoke(serviceType, contract); + } - _unregisterAll.Invoke(serviceType, contract); + /// + public void UnregisterAll(Type? serviceType, string? contract = null) + { + if (_unregisterAll is null) + { + throw new NotImplementedException(); } - /// - public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + if (serviceType is null) { - var pair = (serviceType, contract ?? string.Empty); + serviceType = typeof(NullServiceType); + } - if (!_callbackRegistry.ContainsKey(pair)) - { - _callbackRegistry[pair] = new List>(); - } + _unregisterAll.Invoke(serviceType, contract); + } - _callbackRegistry[pair].Add(callback); + /// + public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + { + var pair = (serviceType, contract ?? string.Empty); - return new ActionDisposable(() => _callbackRegistry[pair].Remove(callback)); + if (!_callbackRegistry.ContainsKey(pair)) + { + _callbackRegistry[pair] = new List>(); } - /// - public void Dispose() + _callbackRegistry[pair].Add(callback); + + return new ActionDisposable(() => _callbackRegistry[pair].Remove(callback)); + } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Disposes of all managed memory from this class. + /// + /// If we are currently disposing managed resources. + protected virtual void Dispose(bool isDisposing) + { + if (_isDisposed) { - Dispose(true); - GC.SuppressFinalize(this); + return; } - /// - /// Disposes of all managed memory from this class. - /// - /// If we are currently disposing managed resources. - protected virtual void Dispose(bool isDisposing) + if (isDisposing) { - if (_isDisposed) - { - return; - } - - if (isDisposing) - { - Interlocked.Exchange(ref _inner, ActionDisposable.Empty).Dispose(); - } - - _isDisposed = true; + Interlocked.Exchange(ref _inner, ActionDisposable.Empty).Dispose(); } + + _isDisposed = true; } } diff --git a/src/Splat/ServiceLocation/IDependencyResolver.cs b/src/Splat/ServiceLocation/IDependencyResolver.cs index dc23fe890..64c21d142 100644 --- a/src/Splat/ServiceLocation/IDependencyResolver.cs +++ b/src/Splat/ServiceLocation/IDependencyResolver.cs @@ -4,15 +4,13 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -namespace Splat +namespace Splat; + +/// +/// Represents a dependency resolver, a service to look up global class +/// instances or types. +/// +public interface IDependencyResolver : IReadonlyDependencyResolver, IMutableDependencyResolver, IDisposable { - /// - /// Represents a dependency resolver, a service to look up global class - /// instances or types. - /// - public interface IDependencyResolver : IReadonlyDependencyResolver, IMutableDependencyResolver, IDisposable - { - } } diff --git a/src/Splat/ServiceLocation/IMutableDependencyResolver.cs b/src/Splat/ServiceLocation/IMutableDependencyResolver.cs index 861c2c8cc..33e37bcff 100644 --- a/src/Splat/ServiceLocation/IMutableDependencyResolver.cs +++ b/src/Splat/ServiceLocation/IMutableDependencyResolver.cs @@ -5,58 +5,57 @@ using System; -namespace Splat +namespace Splat; + +/// +/// Represents a dependency resolver where types can be registered after setup. +/// +public interface IMutableDependencyResolver { /// - /// Represents a dependency resolver where types can be registered after setup. + /// Check to see if a resolvers has a registration for a type. /// - public interface IMutableDependencyResolver - { - /// - /// Check to see if a resolvers has a registration for a type. - /// - /// The type to check for registration. - /// Whether there is a registration for the type. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - bool HasRegistration(Type? serviceType, string? contract = null); + /// The type to check for registration. + /// Whether there is a registration for the type. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + bool HasRegistration(Type? serviceType, string? contract = null); - /// - /// Register a function with the resolver which will generate a object - /// for the specified service type. - /// Optionally a contract can be registered which will indicate - /// that that registration will only work with that contract. - /// Most implementations will use a stack based approach to allow for multile items to be registered. - /// - /// The factory function which generates our object. - /// The type which is used for the registration. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - void Register(Func factory, Type? serviceType, string? contract = null); + /// + /// Register a function with the resolver which will generate a object + /// for the specified service type. + /// Optionally a contract can be registered which will indicate + /// that that registration will only work with that contract. + /// Most implementations will use a stack based approach to allow for multile items to be registered. + /// + /// The factory function which generates our object. + /// The type which is used for the registration. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + void Register(Func factory, Type? serviceType, string? contract = null); - /// - /// Unregisters the current item based on the specified type and contract. - /// - /// The service type to unregister. - /// The optional contract value, which will only remove the value associated with the contract. - void UnregisterCurrent(Type? serviceType, string? contract = null); + /// + /// Unregisters the current item based on the specified type and contract. + /// + /// The service type to unregister. + /// The optional contract value, which will only remove the value associated with the contract. + void UnregisterCurrent(Type? serviceType, string? contract = null); - /// - /// Unregisters all the values associated with the specified type and contract. - /// - /// The service type to unregister. - /// The optional contract value, which will only remove the value associated with the contract. - void UnregisterAll(Type? serviceType, string? contract = null); + /// + /// Unregisters all the values associated with the specified type and contract. + /// + /// The service type to unregister. + /// The optional contract value, which will only remove the value associated with the contract. + void UnregisterAll(Type? serviceType, string? contract = null); - /// - /// Register a callback to be called when a new service matching the type - /// and contract is registered. - /// - /// When registered, the callback is also called for each currently matching - /// service. - /// - /// When disposed removes the callback. - /// The type which is used for the registration. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - /// The callback which will be called when the specified service type and contract are registered. - IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback); - } + /// + /// Register a callback to be called when a new service matching the type + /// and contract is registered. + /// + /// When registered, the callback is also called for each currently matching + /// service. + /// + /// When disposed removes the callback. + /// The type which is used for the registration. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + /// The callback which will be called when the specified service type and contract are registered. + IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback); } diff --git a/src/Splat/ServiceLocation/IReadonlyDependencyResolver.cs b/src/Splat/ServiceLocation/IReadonlyDependencyResolver.cs index a34735818..5c9efceba 100644 --- a/src/Splat/ServiceLocation/IReadonlyDependencyResolver.cs +++ b/src/Splat/ServiceLocation/IReadonlyDependencyResolver.cs @@ -5,30 +5,29 @@ using System; using System.Collections.Generic; -namespace Splat +namespace Splat; + +/// +/// An interface for interacting with a dependency resolver in a read-only fashion. +/// +public interface IReadonlyDependencyResolver { /// - /// An interface for interacting with a dependency resolver in a read-only fashion. + /// Gets an instance of the given . Must return null + /// if the service is not available (must not throw). /// - public interface IReadonlyDependencyResolver - { - /// - /// Gets an instance of the given . Must return null - /// if the service is not available (must not throw). - /// - /// The object type. - /// A optional value which will retrieve only a object registered with the same contract. - /// The requested object, if found; null otherwise. - object? GetService(Type? serviceType, string? contract = null); + /// The object type. + /// A optional value which will retrieve only a object registered with the same contract. + /// The requested object, if found; null otherwise. + object? GetService(Type? serviceType, string? contract = null); - /// - /// Gets all instances of the given . Must return an empty - /// collection if the service is not available (must not return null or throw). - /// - /// The object type. - /// A optional value which will retrieve only objects registered with the same contract. - /// A sequence of instances of the requested . The sequence - /// should be empty (not null) if no objects of the given type are available. - IEnumerable GetServices(Type? serviceType, string? contract = null); - } + /// + /// Gets all instances of the given . Must return an empty + /// collection if the service is not available (must not return null or throw). + /// + /// The object type. + /// A optional value which will retrieve only objects registered with the same contract. + /// A sequence of instances of the requested . The sequence + /// should be empty (not null) if no objects of the given type are available. + IEnumerable GetServices(Type? serviceType, string? contract = null); } diff --git a/src/Splat/ServiceLocation/InternalLocator.cs b/src/Splat/ServiceLocation/InternalLocator.cs index 5d69bd5ea..f09b99c12 100644 --- a/src/Splat/ServiceLocation/InternalLocator.cs +++ b/src/Splat/ServiceLocation/InternalLocator.cs @@ -7,145 +7,144 @@ using System.Collections.Generic; using System.Threading; -namespace Splat +namespace Splat; + +internal class InternalLocator : IDisposable { - internal class InternalLocator : IDisposable + // this has been done to have a default single instance. but allow isolation in unit tests.B + private readonly List _resolverChanged = new(); + private volatile int _resolverChangedNotificationSuspendCount; + private IDependencyResolver _dependencyResolver; + + internal InternalLocator() { - // this has been done to have a default single instance. but allow isolation in unit tests.B - private readonly List _resolverChanged = new(); - private volatile int _resolverChangedNotificationSuspendCount; - private IDependencyResolver _dependencyResolver; + _dependencyResolver = new ModernDependencyResolver(); - internal InternalLocator() + RegisterResolverCallbackChanged(() => { - _dependencyResolver = new ModernDependencyResolver(); - - RegisterResolverCallbackChanged(() => + if (CurrentMutable is null) { - if (CurrentMutable is null) - { - return; - } + return; + } - CurrentMutable.InitializeSplat(); - }); - } + CurrentMutable.InitializeSplat(); + }); + } - /// - /// Gets the read only dependency resolver. This class is used throughout - /// libraries for many internal operations as well as for general use - /// by applications. If this isn't assigned on startup, a default, highly - /// capable implementation will be used, and it is advised for most people - /// to simply use the default implementation. - /// - /// The dependency resolver. - public IReadonlyDependencyResolver Current => _dependencyResolver; - - /// - /// Gets the mutable dependency resolver. - /// The default resolver is also a mutable resolver, so this will be non-null. - /// Use this to register new types on startup if you are using the default resolver. - /// - public IMutableDependencyResolver CurrentMutable => _dependencyResolver; - - internal IDependencyResolver Internal => _dependencyResolver; - - public void Dispose() + /// + /// Gets the read only dependency resolver. This class is used throughout + /// libraries for many internal operations as well as for general use + /// by applications. If this isn't assigned on startup, a default, highly + /// capable implementation will be used, and it is advised for most people + /// to simply use the default implementation. + /// + /// The dependency resolver. + public IReadonlyDependencyResolver Current => _dependencyResolver; + + /// + /// Gets the mutable dependency resolver. + /// The default resolver is also a mutable resolver, so this will be non-null. + /// Use this to register new types on startup if you are using the default resolver. + /// + public IMutableDependencyResolver CurrentMutable => _dependencyResolver; + + internal IDependencyResolver Internal => _dependencyResolver; + + public void Dispose() + { + _dependencyResolver?.Dispose(); + } + + /// + /// Allows setting the dependency resolver. + /// + /// The dependency resolver to set. + public void SetLocator(IDependencyResolver dependencyResolver) + { + _dependencyResolver = dependencyResolver ?? throw new ArgumentNullException(nameof(dependencyResolver)); + + // DV: is this needed if we're changing the behaviour of setlocator? + /* + if (ModeDetector.InUnitTestRunner()) { - _dependencyResolver?.Dispose(); + _unitTestDependencyResolver = value; + _dependencyResolver = _dependencyResolver ?? value; } - - /// - /// Allows setting the dependency resolver. - /// - /// The dependency resolver to set. - public void SetLocator(IDependencyResolver dependencyResolver) + else { - _dependencyResolver = dependencyResolver ?? throw new ArgumentNullException(nameof(dependencyResolver)); - - // DV: is this needed if we're changing the behaviour of setlocator? - /* - if (ModeDetector.InUnitTestRunner()) - { - _unitTestDependencyResolver = value; - _dependencyResolver = _dependencyResolver ?? value; - } - else - { - _dependencyResolver = value; - } - */ - if (AreResolverCallbackChangedNotificationsEnabled()) - { - var currentCallbacks = default(Action[]); - lock (_resolverChanged) - { - // NB: Prevent deadlocks should we reenter this setter from - // the callbacks - currentCallbacks = _resolverChanged.ToArray(); - } - - foreach (var block in currentCallbacks) - { - block(); - } - } + _dependencyResolver = value; } - - /// - /// This method allows libraries to register themselves to be set up - /// whenever the dependency resolver changes. Applications should avoid - /// this method, it is usually used for libraries that depend on service - /// location. - /// - /// A callback that is invoked when the - /// resolver is changed. This callback is also invoked immediately, - /// to configure the current resolver. - /// When disposed, removes the callback. You probably can - /// ignore this. - public IDisposable RegisterResolverCallbackChanged(Action callback) + */ + if (AreResolverCallbackChangedNotificationsEnabled()) { + var currentCallbacks = default(Action[]); lock (_resolverChanged) { - _resolverChanged.Add(callback); + // NB: Prevent deadlocks should we reenter this setter from + // the callbacks + currentCallbacks = _resolverChanged.ToArray(); } - // NB: We always immediately invoke the callback to set up the - // current resolver with whatever we've got - if (AreResolverCallbackChangedNotificationsEnabled()) + foreach (var block in currentCallbacks) { - callback(); + block(); } - - return new ActionDisposable(() => - { - lock (_resolverChanged) - { - _resolverChanged.Remove(callback); - } - }); } + } - /// - /// This method will prevent resolver changed notifications from happening until - /// the returned is disposed. - /// - /// A disposable which when disposed will indicate the change - /// notification is no longer needed. - public IDisposable SuppressResolverCallbackChangedNotifications() + /// + /// This method allows libraries to register themselves to be set up + /// whenever the dependency resolver changes. Applications should avoid + /// this method, it is usually used for libraries that depend on service + /// location. + /// + /// A callback that is invoked when the + /// resolver is changed. This callback is also invoked immediately, + /// to configure the current resolver. + /// When disposed, removes the callback. You probably can + /// ignore this. + public IDisposable RegisterResolverCallbackChanged(Action callback) + { + lock (_resolverChanged) { - Interlocked.Increment(ref _resolverChangedNotificationSuspendCount); - - return new ActionDisposable(() => Interlocked.Decrement(ref _resolverChangedNotificationSuspendCount)); + _resolverChanged.Add(callback); } - /// - /// Indicates if the we are notifying external classes of updates to the resolver being changed. - /// - /// A value indicating whether the notifications are happening. - public bool AreResolverCallbackChangedNotificationsEnabled() + // NB: We always immediately invoke the callback to set up the + // current resolver with whatever we've got + if (AreResolverCallbackChangedNotificationsEnabled()) { - return _resolverChangedNotificationSuspendCount == 0; + callback(); } + + return new ActionDisposable(() => + { + lock (_resolverChanged) + { + _resolverChanged.Remove(callback); + } + }); + } + + /// + /// This method will prevent resolver changed notifications from happening until + /// the returned is disposed. + /// + /// A disposable which when disposed will indicate the change + /// notification is no longer needed. + public IDisposable SuppressResolverCallbackChangedNotifications() + { + Interlocked.Increment(ref _resolverChangedNotificationSuspendCount); + + return new ActionDisposable(() => Interlocked.Decrement(ref _resolverChangedNotificationSuspendCount)); + } + + /// + /// Indicates if the we are notifying external classes of updates to the resolver being changed. + /// + /// A value indicating whether the notifications are happening. + public bool AreResolverCallbackChangedNotificationsEnabled() + { + return _resolverChangedNotificationSuspendCount == 0; } } diff --git a/src/Splat/ServiceLocation/Locator.cs b/src/Splat/ServiceLocation/Locator.cs index 35b8c1b94..f4af67ff0 100644 --- a/src/Splat/ServiceLocation/Locator.cs +++ b/src/Splat/ServiceLocation/Locator.cs @@ -5,100 +5,98 @@ using System; -namespace Splat +namespace Splat; + +/// +/// A Locator which will host the container for dependency injection based operations. +/// +public static class Locator { + static Locator() + { + InternalLocator = new InternalLocator(); + } + /// - /// A Locator which will host the container for dependency injection based operations. + /// Gets the read only dependency resolver. This class is used throughout + /// libraries for many internal operations as well as for general use + /// by applications. If this isn't assigned on startup, a default, highly + /// capable implementation will be used, and it is advised for most people + /// to simply use the default implementation. /// - public static class Locator - { - static Locator() - { - InternalLocator = new InternalLocator(); - } + /// The dependency resolver. + public static IReadonlyDependencyResolver Current => InternalLocator.Current; - /// - /// Gets the read only dependency resolver. This class is used throughout - /// libraries for many internal operations as well as for general use - /// by applications. If this isn't assigned on startup, a default, highly - /// capable implementation will be used, and it is advised for most people - /// to simply use the default implementation. - /// - /// The dependency resolver. - public static IReadonlyDependencyResolver Current => InternalLocator.Current; + /// + /// Gets the mutable dependency resolver. + /// The default resolver is also a mutable resolver, so this will be non-null. + /// Use this to register new types on startup if you are using the default resolver. + /// + public static IMutableDependencyResolver CurrentMutable => InternalLocator.CurrentMutable; - /// - /// Gets the mutable dependency resolver. - /// The default resolver is also a mutable resolver, so this will be non-null. - /// Use this to register new types on startup if you are using the default resolver. - /// - public static IMutableDependencyResolver CurrentMutable => InternalLocator.CurrentMutable; + /// + /// Gets or sets the current locator instance. + /// Used mostly for testing purposes. + /// + internal static InternalLocator InternalLocator { get; set; } - /// - /// Gets or sets the current locator instance. - /// Used mostly for testing purposes. - /// - internal static InternalLocator InternalLocator { get; set; } + /// + /// Allows setting the dependency resolver. + /// + /// The dependency resolver to set. + public static void SetLocator(IDependencyResolver dependencyResolver) + { + InternalLocator.SetLocator(dependencyResolver); + } - /// - /// Allows setting the dependency resolver. - /// - /// The dependency resolver to set. - public static void SetLocator(IDependencyResolver dependencyResolver) - { - InternalLocator.SetLocator(dependencyResolver); - } + /// + /// Gets the full locator. + /// Note you should use or in most situations. + /// + /// The locator. + public static IDependencyResolver GetLocator() + { + return InternalLocator.Internal; + } - /// - /// Gets the full locator. - /// Note you should use or in most situations. - /// - /// The locator. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = "Can be a expensive operation.")] - public static IDependencyResolver GetLocator() + /// + /// This method allows libraries to register themselves to be set up + /// whenever the dependency resolver changes. Applications should avoid + /// this method, it is usually used for libraries that depend on service + /// location. + /// + /// A callback that is invoked when the + /// resolver is changed. This callback is also invoked immediately, + /// to configure the current resolver. + /// When disposed, removes the callback. You probably can + /// ignore this. + public static IDisposable RegisterResolverCallbackChanged(Action callback) + { + if (callback is null) { - return InternalLocator.Internal; + throw new ArgumentNullException(nameof(callback)); } - /// - /// This method allows libraries to register themselves to be set up - /// whenever the dependency resolver changes. Applications should avoid - /// this method, it is usually used for libraries that depend on service - /// location. - /// - /// A callback that is invoked when the - /// resolver is changed. This callback is also invoked immediately, - /// to configure the current resolver. - /// When disposed, removes the callback. You probably can - /// ignore this. - public static IDisposable RegisterResolverCallbackChanged(Action callback) - { - if (callback is null) - { - throw new ArgumentNullException(nameof(callback)); - } - - return InternalLocator.RegisterResolverCallbackChanged(callback); - } + return InternalLocator.RegisterResolverCallbackChanged(callback); + } - /// - /// This method will prevent resolver changed notifications from happening until - /// the returned is disposed. - /// - /// A disposable which when disposed will indicate the change - /// notification is no longer needed. - public static IDisposable SuppressResolverCallbackChangedNotifications() - { - return InternalLocator.SuppressResolverCallbackChangedNotifications(); - } + /// + /// This method will prevent resolver changed notifications from happening until + /// the returned is disposed. + /// + /// A disposable which when disposed will indicate the change + /// notification is no longer needed. + public static IDisposable SuppressResolverCallbackChangedNotifications() + { + return InternalLocator.SuppressResolverCallbackChangedNotifications(); + } - /// - /// Indicates if the we are notifying external classes of updates to the resolver being changed. - /// - /// A value indicating whether the notifications are happening. - public static bool AreResolverCallbackChangedNotificationsEnabled() - { - return InternalLocator.AreResolverCallbackChangedNotificationsEnabled(); - } + /// + /// Indicates if the we are notifying external classes of updates to the resolver being changed. + /// + /// A value indicating whether the notifications are happening. + public static bool AreResolverCallbackChangedNotificationsEnabled() + { + return InternalLocator.AreResolverCallbackChangedNotificationsEnabled(); } } diff --git a/src/Splat/ServiceLocation/ModernDependencyResolver.cs b/src/Splat/ServiceLocation/ModernDependencyResolver.cs index c154ad43f..252b0bd16 100644 --- a/src/Splat/ServiceLocation/ModernDependencyResolver.cs +++ b/src/Splat/ServiceLocation/ModernDependencyResolver.cs @@ -5,301 +5,299 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; -namespace Splat +namespace Splat; + +/// +/// +/// This class is a dependency resolver written for modern C# 5.0 times. +/// It implements all registrations via a Factory method. With the power +/// of Closures, you can actually implement most lifetime styles (i.e. +/// construct per call, lazy construct, singleton) using this. +/// +/// +/// Unless you have a very compelling reason not to, this is the only class +/// you need in order to do dependency resolution, don't bother with using +/// a full IoC container. +/// +/// This container is not thread safe. +/// +public class ModernDependencyResolver : IDependencyResolver { + private readonly Dictionary<(Type serviceType, string? contract), List>> _callbackRegistry; + private Dictionary<(Type serviceType, string? contract), List>>? _registry; + + private bool _isDisposed; + + /// + /// Initializes a new instance of the class. + /// + public ModernDependencyResolver() + : this(null) + { + } + /// - /// - /// This class is a dependency resolver written for modern C# 5.0 times. - /// It implements all registrations via a Factory method. With the power - /// of Closures, you can actually implement most lifetime styles (i.e. - /// construct per call, lazy construct, singleton) using this. - /// - /// - /// Unless you have a very compelling reason not to, this is the only class - /// you need in order to do dependency resolution, don't bother with using - /// a full IoC container. - /// - /// This container is not thread safe. + /// Initializes a new instance of the class. /// - public class ModernDependencyResolver : IDependencyResolver + /// A registry of services. + protected ModernDependencyResolver(Dictionary<(Type serviceType, string? contract), List>>? registry) { - private readonly Dictionary<(Type serviceType, string? contract), List>> _callbackRegistry; - private Dictionary<(Type serviceType, string? contract), List>>? _registry; + _registry = registry is not null ? + registry.ToDictionary(k => k.Key, v => v.Value.ToList()) : + new Dictionary<(Type serviceType, string? contract), List>>(); - private bool _isDisposed; + _callbackRegistry = new Dictionary<(Type serviceType, string? contract), List>>(); + } - /// - /// Initializes a new instance of the class. - /// - public ModernDependencyResolver() - : this(null) + /// + public bool HasRegistration(Type? serviceType, string? contract = null) + { + if (_registry is null) { + return false; } - /// - /// Initializes a new instance of the class. - /// - /// A registry of services. - protected ModernDependencyResolver(Dictionary<(Type serviceType, string? contract), List>>? registry) + if (serviceType is null) { - _registry = registry is not null ? - registry.ToDictionary(k => k.Key, v => v.Value.ToList()) : - new Dictionary<(Type serviceType, string? contract), List>>(); - - _callbackRegistry = new Dictionary<(Type serviceType, string? contract), List>>(); + serviceType = typeof(NullServiceType); } - /// - public bool HasRegistration(Type? serviceType, string? contract = null) + var pair = GetKey(serviceType, contract); + return _registry.TryGetValue(pair, out var registrations) && registrations.Count > 0; + } + + /// + public void Register(Func factory, Type? serviceType, string? contract = null) + { + if (_registry is null) { - if (_registry is null) - { - return false; - } + return; + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + var isNull = serviceType is null; - var pair = GetKey(serviceType, contract); - return _registry.TryGetValue(pair, out var registrations) && registrations.Count > 0; + if (serviceType is null) + { + serviceType = typeof(NullServiceType); } - /// - public void Register(Func factory, Type? serviceType, string? contract = null) - { - if (_registry is null) - { - return; - } + var pair = GetKey(serviceType, contract); - var isNull = serviceType is null; + if (!_registry.ContainsKey(pair)) + { + _registry[pair] = new List>(); + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + _registry[pair].Add(() => + isNull + ? new NullServiceType(factory) + : factory()); - var pair = GetKey(serviceType, contract); + if (_callbackRegistry.ContainsKey(pair)) + { + List>? toRemove = null; - if (!_registry.ContainsKey(pair)) + foreach (var callback in _callbackRegistry[pair]) { - _registry[pair] = new List>(); - } - - _registry[pair].Add(() => - isNull - ? new NullServiceType(factory) - : factory()); + var disp = new BooleanDisposable(); - if (_callbackRegistry.ContainsKey(pair)) - { - List>? toRemove = null; + callback(disp); - foreach (var callback in _callbackRegistry[pair]) + if (disp.IsDisposed) { - var disp = new BooleanDisposable(); - - callback(disp); - - if (disp.IsDisposed) - { - (toRemove ??= new List>()).Add(callback); - } + (toRemove ??= new List>()).Add(callback); } + } - if (toRemove is not null) + if (toRemove is not null) + { + foreach (var c in toRemove) { - foreach (var c in toRemove) - { - _callbackRegistry[pair].Remove(c); - } + _callbackRegistry[pair].Remove(c); } } } + } - /// - public object? GetService(Type? serviceType, string? contract = null) + /// + public object? GetService(Type? serviceType, string? contract = null) + { + if (_registry is null) { - if (_registry is null) - { - return default; - } + return default; + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + if (serviceType is null) + { + serviceType = typeof(NullServiceType); + } - var pair = GetKey(serviceType, contract); - if (!_registry.ContainsKey(pair)) - { - return default; - } + var pair = GetKey(serviceType, contract); + if (!_registry.ContainsKey(pair)) + { + return default; + } - var ret = _registry[pair].LastOrDefault(); - object? returnValue = default; - if (ret != null) + var ret = _registry[pair].LastOrDefault(); + object? returnValue = default; + if (ret != null) + { + returnValue = ret(); + if (returnValue is NullServiceType nullServiceType) { - returnValue = ret(); - if (returnValue is NullServiceType nullServiceType) - { - return nullServiceType.Factory()!; - } + return nullServiceType.Factory()!; } + } - return returnValue; + return returnValue; + } + + /// + public IEnumerable GetServices(Type? serviceType, string? contract = null) + { + if (_registry is null) + { + return Array.Empty(); } - /// - public IEnumerable GetServices(Type? serviceType, string? contract = null) + if (serviceType is null) { - if (_registry is null) - { - return Array.Empty(); - } + serviceType = typeof(NullServiceType); + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + var pair = GetKey(serviceType, contract); + if (!_registry.ContainsKey(pair)) + { + return Array.Empty(); + } - var pair = GetKey(serviceType, contract); - if (!_registry.ContainsKey(pair)) - { - return Array.Empty(); - } + return _registry[pair].ConvertAll(x => x()!); + } - return _registry[pair].ConvertAll(x => x()!); + /// + public void UnregisterCurrent(Type? serviceType, string? contract = null) + { + if (_registry is null) + { + return; } - /// - public void UnregisterCurrent(Type? serviceType, string? contract = null) + if (serviceType is null) { - if (_registry is null) - { - return; - } + serviceType = typeof(NullServiceType); + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + var pair = GetKey(serviceType, contract); - var pair = GetKey(serviceType, contract); + if (!_registry.TryGetValue(pair, out var list)) + { + return; + } - if (!_registry.TryGetValue(pair, out var list)) - { - return; - } + var position = list.Count - 1; + if (position < 0) + { + return; + } - var position = list.Count - 1; - if (position < 0) - { - return; - } + list.RemoveAt(position); + } - list.RemoveAt(position); + /// + public void UnregisterAll(Type? serviceType, string? contract = null) + { + if (_registry is null) + { + return; } - /// - public void UnregisterAll(Type? serviceType, string? contract = null) + if (serviceType is null) { - if (_registry is null) - { - return; - } + serviceType = typeof(NullServiceType); + } - if (serviceType is null) - { - serviceType = typeof(NullServiceType); - } + var pair = GetKey(serviceType, contract); - var pair = GetKey(serviceType, contract); + _registry[pair] = new List>(); + } - _registry[pair] = new List>(); + /// + public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + { + if (serviceType is null) + { + throw new ArgumentNullException(nameof(serviceType)); } - /// - public IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action callback) + if (callback is null) { - if (serviceType is null) - { - throw new ArgumentNullException(nameof(serviceType)); - } - - if (callback is null) - { - throw new ArgumentNullException(nameof(callback)); - } + throw new ArgumentNullException(nameof(callback)); + } - if (_registry is null) - { - return new ActionDisposable(() => { }); - } + if (_registry is null) + { + return new ActionDisposable(() => { }); + } - var pair = GetKey(serviceType, contract); + var pair = GetKey(serviceType, contract); - if (!_callbackRegistry.ContainsKey(pair)) - { - _callbackRegistry[pair] = new List>(); - } + if (!_callbackRegistry.ContainsKey(pair)) + { + _callbackRegistry[pair] = new List>(); + } - _callbackRegistry[pair].Add(callback); + _callbackRegistry[pair].Add(callback); - var disp = new ActionDisposable(() => _callbackRegistry[pair].Remove(callback)); + var disp = new ActionDisposable(() => _callbackRegistry[pair].Remove(callback)); - if (_registry.ContainsKey(pair)) + if (_registry.ContainsKey(pair)) + { + foreach (var s in _registry[pair]) { - foreach (var s in _registry[pair]) - { - callback(disp); - } + callback(disp); } - - return disp; } - /// - /// Generates a duplicate of the resolver with all the current registrations. - /// Useful if you want to generate temporary resolver using the method. - /// - /// The newly generated class with the current registrations. - public ModernDependencyResolver Duplicate() => new(_registry); + return disp; + } + + /// + /// Generates a duplicate of the resolver with all the current registrations. + /// Useful if you want to generate temporary resolver using the method. + /// + /// The newly generated class with the current registrations. + public ModernDependencyResolver Duplicate() => new(_registry); + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } - /// - public void Dispose() + /// + /// Disposes of all managed memory from this class. + /// + /// If we are currently disposing managed resources. + protected virtual void Dispose(bool isDisposing) + { + if (_isDisposed) { - Dispose(true); - GC.SuppressFinalize(this); + return; } - /// - /// Disposes of all managed memory from this class. - /// - /// If we are currently disposing managed resources. - protected virtual void Dispose(bool isDisposing) + if (isDisposing) { - if (_isDisposed) - { - return; - } - - if (isDisposing) - { - _registry = null; - } - - _isDisposed = true; + _registry = null; } - private static (Type type, string contract) GetKey( - Type? serviceType, - string? contract = null) => - (serviceType!, contract ?? string.Empty); + _isDisposed = true; } + + private static (Type type, string contract) GetKey( + Type? serviceType, + string? contract = null) => + (serviceType!, contract ?? string.Empty); } diff --git a/src/Splat/ServiceLocation/NullServiceType.cs b/src/Splat/ServiceLocation/NullServiceType.cs index 64dd58589..3d84f6a72 100644 --- a/src/Splat/ServiceLocation/NullServiceType.cs +++ b/src/Splat/ServiceLocation/NullServiceType.cs @@ -5,22 +5,21 @@ using System; -namespace Splat +namespace Splat; + +/// +/// Null Service Type. +/// +public class NullServiceType { /// - /// Null Service Type. + /// Initializes a new instance of the class. /// - public class NullServiceType - { - /// - /// Initializes a new instance of the class. - /// - /// The value factory. - public NullServiceType(Func factory) => Factory = factory; + /// The value factory. + public NullServiceType(Func factory) => Factory = factory; - /// - /// Gets the Factory. - /// - public Func Factory { get; } - } + /// + /// Gets the Factory. + /// + public Func Factory { get; } } diff --git a/src/Splat/ServiceLocation/ResolverMixins.cs b/src/Splat/ServiceLocation/ResolverMixins.cs index 4f9265c50..2860329ce 100644 --- a/src/Splat/ServiceLocation/ResolverMixins.cs +++ b/src/Splat/ServiceLocation/ResolverMixins.cs @@ -6,218 +6,217 @@ using System; using System.Threading; -namespace Splat +namespace Splat; + +/// +/// Resolver Mixins. +/// +public static class ResolverMixins { /// - /// Resolver Mixins. + /// Registers a factory for the given . /// - public static class ResolverMixins + /// The service type to register for. + /// The resolver to register the service type with. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, string? contract = null) + where T : new() { - /// - /// Registers a factory for the given . - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, string? contract = null) - where T : new() + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - resolver.Register(() => new T(), typeof(T), contract); - return resolver; + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a factory for the given . - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// A factory method for generating a object of the specified type. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, Func factory, string? contract = null) + resolver.Register(() => new T(), typeof(T), contract); + return resolver; + } + + /// + /// Registers a factory for the given . + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// A factory method for generating a object of the specified type. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, Func factory, string? contract = null) + { + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - resolver.Register(() => factory()!, typeof(T), contract); - return resolver; + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a factory for the given . - /// - /// The type to register as. - /// The service type to register for. - /// The resolver to register the service type with. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, string? contract = null) - where T : new() + if (factory is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - resolver.Register(() => new T(), typeof(TAs), contract); - return resolver; + throw new ArgumentNullException(nameof(factory)); } - /// - /// Registers a factory for the given . - /// - /// The type to register as. - /// The service type to register for. - /// The resolver to register the service type with. - /// A factory method for generating a object of the specified type. - /// A optional contract value which will indicates to only generate the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, Func factory, string? contract = null) + resolver.Register(() => factory()!, typeof(T), contract); + return resolver; + } + + /// + /// Registers a factory for the given . + /// + /// The type to register as. + /// The service type to register for. + /// The resolver to register the service type with. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, string? contract = null) + where T : new() + { + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - resolver.Register(() => factory()!, typeof(TAs), contract); - return resolver; + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a constant value which will always return the specified object instance. - /// - /// The resolver to register the service type with. - /// The specified instance to always return. - /// The type of service to register. - /// A optional contract value which will indicates to only return the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, object value, Type serviceType, string? contract = null) - { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + resolver.Register(() => new T(), typeof(TAs), contract); + return resolver; + } - resolver.Register(() => value, serviceType, contract); - return resolver; + /// + /// Registers a factory for the given . + /// + /// The type to register as. + /// The service type to register for. + /// The resolver to register the service type with. + /// A factory method for generating a object of the specified type. + /// A optional contract value which will indicates to only generate the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterAnd(this IMutableDependencyResolver resolver, Func factory, string? contract = null) + { + if (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a constant value which will always return the specified object instance. - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// A optional contract value which will indicates to only return the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, string? contract = null) - where T : new() + if (factory is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + throw new ArgumentNullException(nameof(factory)); + } - var value = new T(); - return resolver.RegisterAnd(() => value, contract); + resolver.Register(() => factory()!, typeof(TAs), contract); + return resolver; + } + + /// + /// Registers a constant value which will always return the specified object instance. + /// + /// The resolver to register the service type with. + /// The specified instance to always return. + /// The type of service to register. + /// A optional contract value which will indicates to only return the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, object value, Type serviceType, string? contract = null) + { + if (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a constant value which will always return the specified object instance. - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// The specified instance to always return. - /// A optional contract value which will indicates to only return the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, T value, string? contract = null) + resolver.Register(() => value, serviceType, contract); + return resolver; + } + + /// + /// Registers a constant value which will always return the specified object instance. + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// A optional contract value which will indicates to only return the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, string? contract = null) + where T : new() + { + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } + throw new ArgumentNullException(nameof(resolver)); + } + + var value = new T(); + return resolver.RegisterAnd(() => value, contract); + } - return resolver.RegisterAnd(() => value, contract); + /// + /// Registers a constant value which will always return the specified object instance. + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// The specified instance to always return. + /// A optional contract value which will indicates to only return the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterConstantAnd(this IMutableDependencyResolver resolver, T value, string? contract = null) + { + if (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a lazy singleton value which will always return the specified object instance once created. - /// The value is only generated once someone requests the service from the resolver. - /// - /// The resolver to register the service type with. - /// A factory method for generating a object of the specified type. - /// The type of service to register. - /// A optional contract value which will indicates to only return the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, Func valueFactory, Type serviceType, string? contract = null) + return resolver.RegisterAnd(() => value, contract); + } + + /// + /// Registers a lazy singleton value which will always return the specified object instance once created. + /// The value is only generated once someone requests the service from the resolver. + /// + /// The resolver to register the service type with. + /// A factory method for generating a object of the specified type. + /// The type of service to register. + /// A optional contract value which will indicates to only return the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, Func valueFactory, Type serviceType, string? contract = null) + { + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - var val = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); - resolver.Register(() => val.Value, serviceType, contract); - return resolver; + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a lazy singleton value which will always return the specified object instance once created. - /// The value is only generated once someone requests the service from the resolver. - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// A optional contract value which will indicates to only return the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, string? contract = null) - where T : new() + var val = new Lazy(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication); + resolver.Register(() => val.Value, serviceType, contract); + return resolver; + } + + /// + /// Registers a lazy singleton value which will always return the specified object instance once created. + /// The value is only generated once someone requests the service from the resolver. + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// A optional contract value which will indicates to only return the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, string? contract = null) + where T : new() + { + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - var val = new Lazy(() => new T(), LazyThreadSafetyMode.ExecutionAndPublication); - resolver.Register(() => val.Value, typeof(T), contract); - return resolver; + throw new ArgumentNullException(nameof(resolver)); } - /// - /// Registers a lazy singleton value which will always return the specified object instance once created. - /// The value is only generated once someone requests the service from the resolver. - /// - /// The service type to register for. - /// The resolver to register the service type with. - /// A factory method for generating a object of the specified type. - /// A optional contract value which will indicates to only return the value if this contract is specified. - /// The resolver. - public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, Func valueFactory, string? contract = null) + var val = new Lazy(() => new T(), LazyThreadSafetyMode.ExecutionAndPublication); + resolver.Register(() => val.Value, typeof(T), contract); + return resolver; + } + + /// + /// Registers a lazy singleton value which will always return the specified object instance once created. + /// The value is only generated once someone requests the service from the resolver. + /// + /// The service type to register for. + /// The resolver to register the service type with. + /// A factory method for generating a object of the specified type. + /// A optional contract value which will indicates to only return the value if this contract is specified. + /// The resolver. + public static IMutableDependencyResolver RegisterLazySingletonAnd(this IMutableDependencyResolver resolver, Func valueFactory, string? contract = null) + { + if (resolver is null) { - if (resolver is null) - { - throw new ArgumentNullException(nameof(resolver)); - } - - var val = new Lazy(() => valueFactory()!, LazyThreadSafetyMode.ExecutionAndPublication); - resolver.Register(() => val.Value, typeof(T), contract); - return resolver; + throw new ArgumentNullException(nameof(resolver)); } + + var val = new Lazy(() => valueFactory()!, LazyThreadSafetyMode.ExecutionAndPublication); + resolver.Register(() => val.Value, typeof(T), contract); + return resolver; } } diff --git a/src/Splat/ServiceLocation/ServiceLocationInitialization.cs b/src/Splat/ServiceLocation/ServiceLocationInitialization.cs index 348edc811..b5713bdb3 100644 --- a/src/Splat/ServiceLocation/ServiceLocationInitialization.cs +++ b/src/Splat/ServiceLocation/ServiceLocationInitialization.cs @@ -5,51 +5,50 @@ using Splat.ApplicationPerformanceMonitoring; -namespace Splat +namespace Splat; + +/// +/// Initialization logic for Splat interacting with Dependency Resolvers. +/// +public static class ServiceLocationInitialization { /// - /// Initialization logic for Splat interacting with Dependency Resolvers. + /// Registers all the default registrations that are needed by the Splat module. /// - public static class ServiceLocationInitialization + /// The resolver to register the needed service types against. + public static void InitializeSplat(this IMutableDependencyResolver resolver) { - /// - /// Registers all the default registrations that are needed by the Splat module. - /// - /// The resolver to register the needed service types against. - public static void InitializeSplat(this IMutableDependencyResolver resolver) + if (resolver is null) { - if (resolver is null) - { - throw new System.ArgumentNullException(nameof(resolver)); - } - - RegisterDefaultLogManager(resolver); - RegisterLogger(resolver); - RegisterApplicationPerformanceMonitoring(resolver); + throw new System.ArgumentNullException(nameof(resolver)); } - private static void RegisterApplicationPerformanceMonitoring(IMutableDependencyResolver resolver) + RegisterDefaultLogManager(resolver); + RegisterLogger(resolver); + RegisterApplicationPerformanceMonitoring(resolver); + } + + private static void RegisterApplicationPerformanceMonitoring(IMutableDependencyResolver resolver) + { + if (!resolver.HasRegistration(typeof(IFeatureUsageTrackingManager))) { - if (!resolver.HasRegistration(typeof(IFeatureUsageTrackingManager))) - { - resolver.RegisterConstant(new DefaultFeatureUsageTrackingManager(), typeof(IFeatureUsageTrackingManager)); - } + resolver.RegisterConstant(new DefaultFeatureUsageTrackingManager(), typeof(IFeatureUsageTrackingManager)); } + } - private static void RegisterDefaultLogManager(IMutableDependencyResolver resolver) + private static void RegisterDefaultLogManager(IMutableDependencyResolver resolver) + { + if (!resolver.HasRegistration(typeof(ILogManager))) { - if (!resolver.HasRegistration(typeof(ILogManager))) - { - resolver.Register(() => new DefaultLogManager(), typeof(ILogManager)); - } + resolver.Register(() => new DefaultLogManager(), typeof(ILogManager)); } + } - private static void RegisterLogger(IMutableDependencyResolver resolver) + private static void RegisterLogger(IMutableDependencyResolver resolver) + { + if (!resolver.HasRegistration(typeof(ILogger))) { - if (!resolver.HasRegistration(typeof(ILogger))) - { - resolver.RegisterConstant(new DebugLogger(), typeof(ILogger)); - } + resolver.RegisterConstant(new DebugLogger(), typeof(ILogger)); } } } diff --git a/src/Splat/TargetFrameworkExtensions.cs b/src/Splat/TargetFrameworkExtensions.cs index cce79c5fb..28b37929c 100644 --- a/src/Splat/TargetFrameworkExtensions.cs +++ b/src/Splat/TargetFrameworkExtensions.cs @@ -6,65 +6,64 @@ using System.Reflection; using System.Runtime.Versioning; -namespace Splat +namespace Splat; + +/// +/// Extension methods that help to get the target framework for a assembly. +/// +public static class TargetFrameworkExtensions { /// - /// Extension methods that help to get the target framework for a assembly. + /// Gets the target framework for an assembly. /// - public static class TargetFrameworkExtensions + /// The assembly to get the target framework for. + /// The target framework or null if not known. + public static string? GetTargetFrameworkName(this Assembly assembly) { - /// - /// Gets the target framework for an assembly. - /// - /// The assembly to get the target framework for. - /// The target framework or null if not known. - public static string? GetTargetFrameworkName(this Assembly assembly) - { - var targetFrameworkAttribute = assembly.GetCustomAttribute(); + var targetFrameworkAttribute = assembly.GetCustomAttribute(); - return GetTargetFrameworkName(targetFrameworkAttribute?.FrameworkName); - } + return GetTargetFrameworkName(targetFrameworkAttribute?.FrameworkName); + } - internal static string? GetTargetFrameworkName(string? frameworkName) + internal static string? GetTargetFrameworkName(string? frameworkName) + { + return frameworkName switch { - return frameworkName switch - { - ".NETCoreApp,Version=v7.0" => "net7.0", - ".NETCoreApp,Version=v6.0" => "net6.0", - ".NETCoreApp,Version=v5.0" => "net5.0", - ".NETCoreApp,Version=v3.1" => "netcoreapp3.1", - ".NETCoreApp,Version=v3.0" => "netcoreapp3.0", - ".NETCoreApp,Version=v2.2" => "netcoreapp2.2", - ".NETCoreApp,Version=v2.1" => "netcoreapp2.1", - ".NETCoreApp,Version=v2.0" => "netcoreapp2.0", - ".NETCoreApp,Version=v1.1" => "netcoreapp1.1", - ".NETCoreApp,Version=v1.0" => "netcoreapp1.0", - ".NETStandard,Version=v2.1" => "netstandard2.1", - ".NETStandard,Version=v2.0" => "netstandard2.0", - ".NETStandard,Version=v1.6" => "netstandard1.6", - ".NETStandard,Version=v1.5" => "netstandard1.5", - ".NETStandard,Version=v1.4" => "netstandard1.4", - ".NETStandard,Version=v1.3" => "netstandard1.3", - ".NETStandard,Version=v1.2" => "netstandard1.2", - ".NETStandard,Version=v1.1" => "netstandard1.1", - ".NETStandard,Version=v1.0" => "netstandard1.0", - ".NETFramework,Version=v4.8" => "net48", - ".NETFramework,Version=v4.7.2" => "net472", - ".NETFramework,Version=v4.7.1" => "net471", - ".NETFramework,Version=v4.7" => "net47", - ".NETFramework,Version=v4.6.2" => "net462", - ".NETFramework,Version=v4.6.1" => "net461", - ".NETFramework,Version=v4.6" => "net46", - ".NETFramework,Version=v4.5.2" => "net452", - ".NETFramework,Version=v4.5.1" => "net451", - ".NETFramework,Version=v4.5" => "net45", - ".NETFramework,Version=v4.0.3" => "net403", - ".NETFramework,Version=v4.0" => "net40", - ".NETFramework,Version=v3.5" => "net35", - ".NETFramework,Version=v2.0" => "net20", - ".NETFramework,Version=v1.1" => "net11", - _ => null, - }; - } + ".NETCoreApp,Version=v7.0" => "net7.0", + ".NETCoreApp,Version=v6.0" => "net6.0", + ".NETCoreApp,Version=v5.0" => "net5.0", + ".NETCoreApp,Version=v3.1" => "netcoreapp3.1", + ".NETCoreApp,Version=v3.0" => "netcoreapp3.0", + ".NETCoreApp,Version=v2.2" => "netcoreapp2.2", + ".NETCoreApp,Version=v2.1" => "netcoreapp2.1", + ".NETCoreApp,Version=v2.0" => "netcoreapp2.0", + ".NETCoreApp,Version=v1.1" => "netcoreapp1.1", + ".NETCoreApp,Version=v1.0" => "netcoreapp1.0", + ".NETStandard,Version=v2.1" => "netstandard2.1", + ".NETStandard,Version=v2.0" => "netstandard2.0", + ".NETStandard,Version=v1.6" => "netstandard1.6", + ".NETStandard,Version=v1.5" => "netstandard1.5", + ".NETStandard,Version=v1.4" => "netstandard1.4", + ".NETStandard,Version=v1.3" => "netstandard1.3", + ".NETStandard,Version=v1.2" => "netstandard1.2", + ".NETStandard,Version=v1.1" => "netstandard1.1", + ".NETStandard,Version=v1.0" => "netstandard1.0", + ".NETFramework,Version=v4.8" => "net48", + ".NETFramework,Version=v4.7.2" => "net472", + ".NETFramework,Version=v4.7.1" => "net471", + ".NETFramework,Version=v4.7" => "net47", + ".NETFramework,Version=v4.6.2" => "net462", + ".NETFramework,Version=v4.6.1" => "net461", + ".NETFramework,Version=v4.6" => "net46", + ".NETFramework,Version=v4.5.2" => "net452", + ".NETFramework,Version=v4.5.1" => "net451", + ".NETFramework,Version=v4.5" => "net45", + ".NETFramework,Version=v4.0.3" => "net403", + ".NETFramework,Version=v4.0" => "net40", + ".NETFramework,Version=v3.5" => "net35", + ".NETFramework,Version=v2.0" => "net20", + ".NETFramework,Version=v1.1" => "net11", + _ => null, + }; } } From 75bec42b4b1bc7d58c0013a03c3227c3959acdc7 Mon Sep 17 00:00:00 2001 From: Glenn Watson <5834289+glennawatson@users.noreply.github.com> Date: Wed, 7 Dec 2022 12:04:18 +1100 Subject: [PATCH 3/4] Remove uap support, users can now use net6-windows or net7-windows --- src/Directory.build.targets | 4 - .../DefaultPlatformModeDetector.cs | 11 --- .../WinRT/Bitmaps/BitmapImageBitmap.cs | 57 ------------ .../Platforms/WinRT/Bitmaps/BitmapMixins.cs | 59 ------------ .../WinRT/Bitmaps/DispatcherMixin.cs | 41 --------- .../WinRT/Bitmaps/PlatformBitmapLoader.cs | 92 ------------------- .../Bitmaps/WriteableBitmapImageBitmap.cs | 63 ------------- .../Platforms/WinRT/Colors/ColorExtensions.cs | 45 --------- .../WinRT/Colors/SplatColorExtensions.cs | 45 --------- src/Splat.Drawing/Splat.Drawing.csproj | 8 +- src/Splat.DryIoc/Splat.DryIoc.csproj | 2 +- src/Splat/Logging/LocalizableAttribute.cs | 2 +- 12 files changed, 3 insertions(+), 426 deletions(-) delete mode 100644 src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs delete mode 100644 src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs delete mode 100644 src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs delete mode 100644 src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs delete mode 100644 src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs delete mode 100644 src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs delete mode 100644 src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs diff --git a/src/Directory.build.targets b/src/Directory.build.targets index 0d12551ec..66ed5af18 100644 --- a/src/Directory.build.targets +++ b/src/Directory.build.targets @@ -7,10 +7,6 @@ $(DefineConstants);NET_45;XAML - - 10.0.16299.0 - $(DefineConstants);NETFX_CORE;XAML;WINDOWS_UWP - $(DefineConstants);MONO;UIKIT;COCOA;IOS diff --git a/src/Splat.Drawing/DefaultPlatformModeDetector.cs b/src/Splat.Drawing/DefaultPlatformModeDetector.cs index bf697e10e..09ff45655 100644 --- a/src/Splat.Drawing/DefaultPlatformModeDetector.cs +++ b/src/Splat.Drawing/DefaultPlatformModeDetector.cs @@ -8,13 +8,6 @@ using System.Linq; using System.Reflection; -#if NETFX_CORE -using System.Threading; -using System.Threading.Tasks; - -using Windows.ApplicationModel; -#endif - namespace Splat; /// @@ -38,9 +31,6 @@ public class DefaultPlatformModeDetector : IPlatformModeDetector /// public bool? InDesignMode() { -#if NETFX_CORE - return DesignMode.DesignModeEnabled; -#else if (_cachedInDesignModeResult.HasValue) { return _cachedInDesignModeResult.Value; @@ -93,6 +83,5 @@ public class DefaultPlatformModeDetector : IPlatformModeDetector _cachedInDesignModeResult = false; return _cachedInDesignModeResult; -#endif } } diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs deleted file mode 100644 index 79c547f89..000000000 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapImageBitmap.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// 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.Diagnostics.CodeAnalysis; - -using Windows.Storage; -using Windows.UI.Xaml.Media.Imaging; - -namespace Splat; - -/// -/// A bitmap that wraps a . -/// -internal sealed class BitmapImageBitmap : IBitmap -{ - private BitmapImage? _inner; - - public BitmapImageBitmap(BitmapImage bitmap) - { - _inner = bitmap; - } - - /// - public float Width => Inner?.PixelWidth ?? 0; - - /// - public float Height => Inner?.PixelHeight ?? 0; - - /// - /// Gets the platform . - /// - public BitmapSource? Inner => _inner; - - /// - public async Task Save(CompressedBitmapFormat format, float quality, Stream target) - { - if (_inner is null) - { - return; - } - - var installedFolderImageSourceUri = _inner.UriSource.OriginalString.Replace("ms-appx:/", string.Empty); - var wb = new WriteableBitmap(_inner.PixelWidth, _inner.PixelHeight); - var file = await StorageFile.GetFileFromPathAsync(_inner.UriSource.OriginalString); - await wb.SetSourceAsync(await file.OpenReadAsync()); - - await new WriteableBitmapImageBitmap(wb).Save(format, quality, target).ConfigureAwait(false); - } - - /// - public void Dispose() - { - _inner = null; - } -} diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs deleted file mode 100644 index b1fb72301..000000000 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/BitmapMixins.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// 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 Windows.UI.Xaml.Media.Imaging; - -namespace Splat; - -/// -/// Extension methods to assist with dealing with Bitmaps. -/// -public static class BitmapMixins -{ - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static IBitmap FromNative(this BitmapImage value) - { - return new BitmapImageBitmap(value); - } - - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static IBitmap FromNative(this WriteableBitmap value) - { - return new WriteableBitmapImageBitmap(value); - } - - /// - /// Converts to a . - /// - /// The bitmap to convert. - /// A bitmap. - public static BitmapSource ToNative(this IBitmap value) - { - if (value is null) - { - throw new System.ArgumentNullException(nameof(value)); - } - - if (value is WriteableBitmapImageBitmap wbib) - { - return wbib.Inner ?? throw new InvalidOperationException("The bitmap has been disposed"); - } - - if (value is BitmapImageBitmap bitmapImage) - { - return bitmapImage.Inner ?? throw new InvalidOperationException("The bitmap has been disposed"); - } - - throw new InvalidOperationException("The bitmap type is unsupported"); - } -} diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs deleted file mode 100644 index d62eadedb..000000000 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// 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 Windows.UI.Core; - -namespace Splat; - -internal static class DispatcherMixin -{ - public static async Task RunTaskAsync(this CoreDispatcher dispatcher, Func> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) - { - var taskCompletionSource = new TaskCompletionSource(); - await dispatcher.RunAsync(priority, async () => - { - try - { - taskCompletionSource.SetResult(await func().ConfigureAwait(false)); - } - catch (Exception ex) - { - taskCompletionSource.SetException(ex); - } - }); - return await taskCompletionSource.Task.ConfigureAwait(false); - } - - // There is no TaskCompletionSource so we use a bool that we throw away. - public static Task RunTaskAsync(this CoreDispatcher dispatcher, Func func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) - { - return RunTaskAsync( - dispatcher, - async () => - { - await func().ConfigureAwait(false); - return false; - }, - priority); - } -} diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs deleted file mode 100644 index 85e5ed5f2..000000000 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// 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.Runtime.InteropServices.WindowsRuntime; - -using Windows.ApplicationModel.Core; -using Windows.Graphics.Imaging; -using Windows.Storage; -using Windows.UI.Core; -using Windows.UI.Xaml.Media.Imaging; - -namespace Splat; - -/// -/// A XAML based platform bitmap loader which will load our bitmaps for us. -/// -public class PlatformBitmapLoader : IBitmapLoader -{ - /// - public Task Load(Stream sourceStream, float? desiredWidth, float? desiredHeight) - { - return GetDispatcher().RunTaskAsync(async () => - { - using (var randomAccessStream = sourceStream.AsRandomAccessStream()) - { - randomAccessStream.Seek(0); - var decoder = await BitmapDecoder.CreateAsync(randomAccessStream); - - var targetWidth = (int)(desiredWidth ?? decoder.OrientedPixelWidth); - var targetHeight = (int)(desiredHeight ?? decoder.OrientedPixelHeight); - - var transform = new BitmapTransform - { - ScaledWidth = (uint)targetWidth, - ScaledHeight = (uint)targetHeight, - InterpolationMode = BitmapInterpolationMode.Fant, - }; - - if (decoder.OrientedPixelHeight != decoder.PixelHeight) - { - // if Exif orientation indicates 90 or 270 degrees rotation we swap width and height for the transformation. - transform.ScaledWidth = (uint)targetHeight; - transform.ScaledHeight = (uint)targetWidth; - } - - var pixelData = await decoder.GetPixelDataAsync(decoder.BitmapPixelFormat, BitmapAlphaMode.Premultiplied, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb); - var pixels = pixelData.DetachPixelData(); - - var bmp = new WriteableBitmap(targetWidth, targetHeight); - using (var bmpStream = bmp.PixelBuffer.AsStream()) - { - bmpStream.Seek(0, SeekOrigin.Begin); - await bmpStream.WriteAsync(pixels, 0, (int)bmpStream.Length); - return (IBitmap?)new WriteableBitmapImageBitmap(bmp); - } - } - }); - } - - /// - public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) - { - return GetDispatcher().RunTaskAsync(async () => - { - var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(source)); - using (var stream = await file.OpenAsync(FileAccessMode.Read)) - { - return await Load(stream.AsStreamForRead(), desiredWidth, desiredHeight).ConfigureAwait(false); - } - }); - } - - /// - public IBitmap Create(float width, float height) - { - var disp = GetDispatcher().RunTaskAsync(async () => - { - return await Task.FromResult(new WriteableBitmapImageBitmap(new WriteableBitmap((int)width, (int)height))).ConfigureAwait(false); - }); - - return disp.GetAwaiter().GetResult(); - } - - private static CoreDispatcher GetDispatcher() - { - CoreWindow currentThreadWindow = CoreWindow.GetForCurrentThread(); - - return currentThreadWindow is null ? CoreApplication.MainView.CoreWindow.Dispatcher : currentThreadWindow.Dispatcher; - } -} diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs deleted file mode 100644 index e155468b4..000000000 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/WriteableBitmapImageBitmap.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// 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.Runtime.InteropServices.WindowsRuntime; - -using Windows.Foundation; -using Windows.Graphics.Imaging; -using Windows.Storage.Streams; -using Windows.UI.Xaml.Media.Imaging; - -namespace Splat; - -/// -/// A bitmap that wraps a . -/// -internal sealed class WriteableBitmapImageBitmap : IBitmap -{ - public WriteableBitmapImageBitmap(WriteableBitmap bitmap) - { - Inner = bitmap; - } - - /// - public float Width => Inner?.PixelWidth ?? 0; - - /// - public float Height => Inner?.PixelHeight ?? 0; - - /// - /// Gets the platform . - /// - public WriteableBitmap? Inner { get; private set; } - - /// - public async Task Save(CompressedBitmapFormat format, float quality, Stream target) - { - if (Inner is null) - { - return; - } - - // NB: Due to WinRT's brain-dead design, we're copying this image - // like three times. Let Dreams Soar. - using var rwTarget = new InMemoryRandomAccessStream(); - var fmt = format == CompressedBitmapFormat.Jpeg ? BitmapEncoder.JpegEncoderId : BitmapEncoder.PngEncoderId; - var encoder = await BitmapEncoder.CreateAsync(fmt, rwTarget, new[] { new KeyValuePair("ImageQuality", new BitmapTypedValue(quality, PropertyType.Single)) }); - - var pixels = new byte[Inner.PixelBuffer.Length]; - await Inner.PixelBuffer.AsStream().ReadAsync(pixels, 0, (int)Inner.PixelBuffer.Length).ConfigureAwait(true); - - encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, (uint)Inner.PixelWidth, (uint)Inner.PixelHeight, 96, 96, pixels); - await encoder.FlushAsync(); - await rwTarget.AsStream().CopyToAsync(target).ConfigureAwait(false); - } - - /// - public void Dispose() - { - Inner = null; - } -} diff --git a/src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs b/src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs deleted file mode 100644 index da214bef7..000000000 --- a/src/Splat.Drawing/Platforms/WinRT/Colors/ColorExtensions.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// 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 Windows.UI; -using Windows.UI.Xaml.Media; - -namespace Splat.Platforms.WinRT.Colors; - -/// -/// Provides extension methods for interacting with colors, to and from the XAML colors. -/// -public static class ColorExtensions -{ - /// - /// Converts a to a XAML native color. - /// - /// The System.Drawing.Color to convert. - /// A native XAML color. - public static Color ToNative(this System.Drawing.Color value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } - - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value) - { - return new(value.ToNative()); - } - - /// - /// Converts a XAML color into the XAML . - /// - /// The color to convert. - /// The generated. - public static System.Drawing.Color FromNative(this Color value) - { - return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B); - } -} diff --git a/src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs b/src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs deleted file mode 100644 index ab1f963a6..000000000 --- a/src/Splat.Drawing/Platforms/WinRT/Colors/SplatColorExtensions.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// 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 Windows.UI; -using Windows.UI.Xaml.Media; - -namespace Splat.Platforms.WinRT.Colors; - -/// -/// Extension methods associated with the struct. -/// -public static class SplatColorExtensions -{ - /// - /// Converts a into the XAML color. - /// - /// The color to convert. - /// The XAML color generated. - public static Color ToNative(this SplatColor value) - { - return Color.FromArgb(value.A, value.R, value.G, value.B); - } - - /// - /// Converts a into the XAML . - /// - /// The color to convert. - /// The generated. - public static SolidColorBrush ToNativeBrush(this SplatColor value) - { - return new(value.ToNative()); - } - - /// - /// Converts a XAML color into the XAML . - /// - /// The color to convert. - /// The generated. - public static SplatColor FromNative(this Color value) - { - return SplatColor.FromArgb(value.A, value.R, value.G, value.B); - } -} diff --git a/src/Splat.Drawing/Splat.Drawing.csproj b/src/Splat.Drawing/Splat.Drawing.csproj index 5b5fbd01c..8d0f74008 100644 --- a/src/Splat.Drawing/Splat.Drawing.csproj +++ b/src/Splat.Drawing/Splat.Drawing.csproj @@ -2,7 +2,7 @@ MonoAndroid12.0;MonoAndroid12.1;MonoAndroid13.0;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;Xamarin.WatchOS10;tizen40;netstandard2.0;net6.0;net6.0-android;net6.0-ios;net6.0-tvos;net6.0-macos;net6.0-maccatalyst;net7.0;net7.0-android;net7.0-ios;net7.0-tvos;net7.0-macos;net7.0-maccatalyst - $(TargetFrameworks);net462;net472;uap10.0.17763;net6.0-windows;net7.0-windows + $(TargetFrameworks);net462;net472;net6.0-windows;net7.0-windows Splat .NET Foundation and Contributors A library to make things cross-platform that should be @@ -72,12 +72,6 @@ - - - - - - diff --git a/src/Splat.DryIoc/Splat.DryIoc.csproj b/src/Splat.DryIoc/Splat.DryIoc.csproj index 44e825f37..c30a5d9de 100644 --- a/src/Splat.DryIoc/Splat.DryIoc.csproj +++ b/src/Splat.DryIoc/Splat.DryIoc.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;net6.0;net7.0 $(TargetFrameworks);net462 diff --git a/src/Splat/Logging/LocalizableAttribute.cs b/src/Splat/Logging/LocalizableAttribute.cs index 4a3aab0cb..c5133e6fe 100644 --- a/src/Splat/Logging/LocalizableAttribute.cs +++ b/src/Splat/Logging/LocalizableAttribute.cs @@ -5,7 +5,7 @@ namespace Splat; -#if PORTABLE || WINDOWS_PHONE || NETFX_CORE +#if PORTABLE || WINDOWS_PHONE /// /// Specifies whether a property should be localized. /// From 4a43b9e66305aba050a86c917be3ecf763979838 Mon Sep 17 00:00:00 2001 From: Glenn Watson <5834289+glennawatson@users.noreply.github.com> Date: Wed, 7 Dec 2022 12:05:09 +1100 Subject: [PATCH 4/4] Bump version number --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 850795947..8fcc9e872 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "14.5", + "version": "14.6", "publicReleaseRefSpec": [ "^refs/heads/main$", // we release out of master "^refs/heads/preview/.*", // we release previews