diff --git a/.editorconfig b/.editorconfig index bb2905e0e..1ae715381 100644 --- a/.editorconfig +++ b/.editorconfig @@ -391,6 +391,8 @@ dotnet_diagnostic.SA1210.severity = suggestion dotnet_diagnostic.CA1308.severity = none # CS1587: XML comment is not placed on a valid language element dotnet_diagnostic.CS1587.severity = none +# CA1859: Use concrete types when possible for improved performance +dotnet_diagnostic.CA1859.severity = none # VSTHRD110: This one is bugged: https://github.com/microsoft/vs-threading/issues/899 dotnet_diagnostic.VSTHRD110.severity = none diff --git a/src/app/ApplicationTemplate.Business/KillSwitch/KillSwitchService.cs b/src/app/ApplicationTemplate.Business/KillSwitch/KillSwitchService.cs index 89d40584b..e1de08efd 100644 --- a/src/app/ApplicationTemplate.Business/KillSwitch/KillSwitchService.cs +++ b/src/app/ApplicationTemplate.Business/KillSwitch/KillSwitchService.cs @@ -26,5 +26,5 @@ public KillSwitchService(IKillSwitchRepository killSwitchRepository, ILogger public IObservable ObserveKillSwitchActivation() => _killSwitchRepository.ObserveKillSwitchActivation() - .Do(isActive => _logger.LogInformation("Kill switch is now {isActive}.", isActive)); + .Do(isActive => _logger.LogInformation("Kill switch is now {IsActive}.", isActive)); } diff --git a/src/app/ApplicationTemplate.Presentation/Configuration/ConfigurationConfiguration.cs b/src/app/ApplicationTemplate.Presentation/Configuration/ConfigurationConfiguration.cs index 239ea298a..36c244517 100644 --- a/src/app/ApplicationTemplate.Presentation/Configuration/ConfigurationConfiguration.cs +++ b/src/app/ApplicationTemplate.Presentation/Configuration/ConfigurationConfiguration.cs @@ -29,10 +29,7 @@ public static class ConfigurationConfiguration /// The environment manager. public static IHostBuilder AddConfiguration(this IHostBuilder hostBuilder, string folderPath, IEnvironmentManager environmentManager) { - if (hostBuilder is null) - { - throw new ArgumentNullException(nameof(hostBuilder)); - } + ArgumentNullException.ThrowIfNull(hostBuilder); return hostBuilder .AddConfiguration(environmentManager) @@ -124,10 +121,7 @@ private static IConfigurationBuilder AddUserOverrideConfiguration(this IConfigur /// The environment manager. private static IHostBuilder AddConfiguration(this IHostBuilder hostBuilder, IEnvironmentManager environmentManager) { - if (hostBuilder is null) - { - throw new ArgumentNullException(nameof(hostBuilder)); - } + ArgumentNullException.ThrowIfNull(hostBuilder); return hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) => serviceCollection .AddSingleton(serviceProvider => hostBuilderContext.Configuration) @@ -136,7 +130,7 @@ private static IHostBuilder AddConfiguration(this IHostBuilder hostBuilder, IEnv ); } - public class AppSettingsFile + public sealed class AppSettingsFile { private static AppSettingsFile[] _appSettingsFiles; diff --git a/src/app/ApplicationTemplate.Presentation/Configuration/EnvironmentManager.cs b/src/app/ApplicationTemplate.Presentation/Configuration/EnvironmentManager.cs index 79b693df0..24de1263b 100644 --- a/src/app/ApplicationTemplate.Presentation/Configuration/EnvironmentManager.cs +++ b/src/app/ApplicationTemplate.Presentation/Configuration/EnvironmentManager.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using static ApplicationTemplate.ConfigurationConfiguration; namespace ApplicationTemplate; @@ -10,7 +8,7 @@ namespace ApplicationTemplate; /// /// This implementation of uses local files to support the override features. /// -public class EnvironmentManager : IEnvironmentManager +public sealed class EnvironmentManager : IEnvironmentManager { //-:cnd:noEmit #if PRODUCTION @@ -58,10 +56,7 @@ public void ClearOverride() public void Override(string environment) { - if (environment == null) - { - throw new ArgumentNullException(nameof(environment)); - } + ArgumentNullException.ThrowIfNull(environment); environment = environment.ToUpperInvariant(); diff --git a/src/app/ApplicationTemplate.Presentation/Framework/DynamicData/IChangeSet.Extensions.cs b/src/app/ApplicationTemplate.Presentation/Framework/DynamicData/IChangeSet.Extensions.cs index c1a6aa987..dd5d85d84 100644 --- a/src/app/ApplicationTemplate.Presentation/Framework/DynamicData/IChangeSet.Extensions.cs +++ b/src/app/ApplicationTemplate.Presentation/Framework/DynamicData/IChangeSet.Extensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; namespace DynamicData; @@ -8,10 +7,7 @@ public static class ChangeSetExtensions { public static IEnumerable GetAddedItems(this IChangeSet changeSet) { - if (changeSet is null) - { - throw new ArgumentNullException(nameof(changeSet)); - } + ArgumentNullException.ThrowIfNull(changeSet); foreach (var change in changeSet) { @@ -38,10 +34,7 @@ public static IEnumerable GetAddedItems(this IChangeSet changeSet) public static IEnumerable GetRemovedItems(this IChangeSet changeSet) { - if (changeSet is null) - { - throw new ArgumentNullException(nameof(changeSet)); - } + ArgumentNullException.ThrowIfNull(changeSet); foreach (var change in changeSet) { diff --git a/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/IViewModel.Extensions.PropertyFromDynamicProperty.cs b/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/IViewModel.Extensions.PropertyFromDynamicProperty.cs index 55901a91c..9753fea4a 100644 --- a/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/IViewModel.Extensions.PropertyFromDynamicProperty.cs +++ b/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/IViewModel.Extensions.PropertyFromDynamicProperty.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Text; -using Chinook.DynamicMvvm; -using Chinook.DynamicMvvm.Implementations; namespace Chinook.DynamicMvvm; @@ -20,10 +16,7 @@ public static class ChinookViewModelExtensionsForPropertiesFromDynamicProperty /// The property's value. public static T GetFromDynamicProperty(this IViewModel viewModel, IDynamicProperty source, [CallerMemberName] string name = null) { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); return viewModel.Get(viewModel.GetOrCreateDynamicProperty(name, n => new ValueChangedOnBackgroundTaskDynamicPropertyFromDynamicProperty(name, source, viewModel, source.Value))); } @@ -41,10 +34,7 @@ public static T GetFromDynamicProperty(this IViewModel viewModel, IDynamicPro /// The property's value. public static TResult GetFromDynamicProperty(this IViewModel viewModel, IDynamicProperty source, Func selector, [CallerMemberName] string name = null) { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); return viewModel.Get(viewModel.GetOrCreateDynamicProperty(name, n => new ValueChangedOnBackgroundTaskDynamicPropertyFromDynamicProperty(name, source, viewModel, selector, selector(source.Value)))); diff --git a/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/ValueChangedOnBackgroundTaskDynamicPropertyFromDynamicProperty.cs b/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/ValueChangedOnBackgroundTaskDynamicPropertyFromDynamicProperty.cs index 07124fef0..3b71eff63 100644 --- a/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/ValueChangedOnBackgroundTaskDynamicPropertyFromDynamicProperty.cs +++ b/src/app/ApplicationTemplate.Presentation/Framework/ViewModels/ValueChangedOnBackgroundTaskDynamicPropertyFromDynamicProperty.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using Chinook.DynamicMvvm.Implementations; namespace Chinook.DynamicMvvm; @@ -35,10 +33,7 @@ public override object Value get => base.Value; set { - if (_isDisposed) - { - throw new ObjectDisposedException(Name); - } + ObjectDisposedException.ThrowIf(_isDisposed, this); if (!Equals(value, base.Value)) { diff --git a/src/app/ApplicationTemplate.Presentation/ViewModels/DadJokes/DadJokesPageViewModel.cs b/src/app/ApplicationTemplate.Presentation/ViewModels/DadJokes/DadJokesPageViewModel.cs index b17138e27..8d705115f 100644 --- a/src/app/ApplicationTemplate.Presentation/ViewModels/DadJokes/DadJokesPageViewModel.cs +++ b/src/app/ApplicationTemplate.Presentation/ViewModels/DadJokes/DadJokesPageViewModel.cs @@ -14,7 +14,7 @@ namespace ApplicationTemplate.Presentation; -public partial class DadJokesPageViewModel : ViewModel +public sealed partial class DadJokesPageViewModel : ViewModel { [Inject] private IDadJokesService _dadJokesService; [Inject] private ISectionsNavigator _sectionsNavigator; @@ -67,7 +67,7 @@ private async Task SetupFavoritesUpdate(CancellationToken ct) void UpdateItemViewModels(IChangeSet changeSet) { var quotesVMs = Jokes.State.Data; - if (quotesVMs != null && quotesVMs.Any()) + if (quotesVMs != null && quotesVMs.Length != 0) { var addedItems = changeSet.GetAddedItems(); var removedItems = changeSet.GetRemovedItems(); diff --git a/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/DiagnosticsCountersService.cs b/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/DiagnosticsCountersService.cs index 2c0afd4c0..d2e44aafa 100644 --- a/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/DiagnosticsCountersService.cs +++ b/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/DiagnosticsCountersService.cs @@ -4,7 +4,7 @@ namespace ApplicationTemplate.Presentation; -public class DiagnosticsCountersService +public sealed class DiagnosticsCountersService { public event EventHandler CountersChanged; @@ -92,7 +92,7 @@ private void OnCommandNotification(KeyValuePair notification) } } -public partial class CountersData +public sealed partial class CountersData { public CountersData() { @@ -100,10 +100,7 @@ public CountersData() public CountersData(CountersData source) { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); CreatedViewModels = source.CreatedViewModels; DisposedViewModels = source.DisposedViewModels; diff --git a/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/HttpDebugger/HttpDebuggerViewModel.cs b/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/HttpDebugger/HttpDebuggerViewModel.cs index 49f2f3c7b..9725dc815 100644 --- a/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/HttpDebugger/HttpDebuggerViewModel.cs +++ b/src/app/ApplicationTemplate.Presentation/ViewModels/Diagnostics/HttpDebugger/HttpDebuggerViewModel.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Reactive.Concurrency; @@ -9,7 +8,6 @@ using System.Text.Json; using ApplicationTemplate.DataAccess; using Chinook.DynamicMvvm; -using Chinook.DynamicMvvm.Deactivation; using DynamicData; using Uno; using Uno.Extensions; @@ -18,6 +16,8 @@ namespace ApplicationTemplate.Presentation; public sealed partial class HttpDebuggerViewModel : TabViewModel { + private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true }; + [Inject] private IHttpDebuggerService _httpDebuggerService; public HttpDebuggerViewModel() @@ -261,7 +261,7 @@ private static string TryFormatContent(string content, bool indentJson) var reader = new Utf8JsonReader(Encoding.UTF8.GetBytes(content)); if (JsonDocument.TryParseValue(ref reader, out var jsonDoc)) { - return JsonSerializer.Serialize(jsonDoc, new JsonSerializerOptions { WriteIndented = true }); + return JsonSerializer.Serialize(jsonDoc, _jsonSerializerOptions); } } diff --git a/src/app/ApplicationTemplate.Tests.Functional/FunctionalTestBase.cs b/src/app/ApplicationTemplate.Tests.Functional/FunctionalTestBase.cs index 7edb9625b..062bbba10 100644 --- a/src/app/ApplicationTemplate.Tests.Functional/FunctionalTestBase.cs +++ b/src/app/ApplicationTemplate.Tests.Functional/FunctionalTestBase.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Reactive.Concurrency; using System.Reactive.Linq; using System.Threading; @@ -180,7 +181,7 @@ private void ConfigureLogging(HostBuilderContext hostBuilderContext, ILoggingBui var serilogConfiguration = new LoggerConfiguration() .ReadFrom.Configuration(hostBuilderContext.Configuration) .Enrich.With(new ThreadIdEnricher()) - .WriteTo.TestOutput(_output, outputTemplate: "{Timestamp:HH:mm:ss.fff} Thread:{ThreadId} {Level:u1}/{SourceContext}: {Message:lj} {Exception}{NewLine}"); + .WriteTo.TestOutput(_output, outputTemplate: "{Timestamp:HH:mm:ss.fff} Thread:{ThreadId} {Level:u1}/{SourceContext}: {Message:lj} {Exception}{NewLine}", formatProvider: CultureInfo.InvariantCulture); var logger = serilogConfiguration.CreateLogger(); loggingBuilder.AddSerilog(logger); @@ -209,7 +210,6 @@ protected virtual IServiceCollection ReplaceWithMock(IServiceCollectio return services.Replace(ServiceDescriptor.Singleton(mockedService)); } - /// /// Gets the application settings to use for this test. ///