From 7a1bb6702b12bb1e383f948862557ddf78628d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Tue, 10 May 2022 23:52:39 +0200 Subject: [PATCH] Fix ReSharper/Rider inspection warnings The `serilog-settings-configuration.sln.DotSettings` file defines many custom inspection severities as error rendering the solution with many red squiggly lines when opened in Rider or in Visual Studio with ReSharper. --- .../Configuration/ConfigurationReader.cs | 1 - .../Configuration/ObjectArgumentValue.cs | 6 ++--- .../DllScanningAssemblyFinderTests.cs | 23 +++++++------------ .../LoggerConfigurationExtensionsTests.cs | 16 ++++++------- test/TestDummies/DummyThreadIdEnricher.cs | 4 ---- 5 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index 0702b36..d784562 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using Microsoft.Extensions.Configuration; diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs index c99598f..fb8582b 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs @@ -88,12 +88,12 @@ bool TryCreateContainer(out object result) var configurationElements = _section.GetChildren().ToArray(); result = Activator.CreateInstance(toType); - + for (int i = 0; i < configurationElements.Length; ++i) { var argumentValue = ConfigurationReader.GetArgumentValue(configurationElements[i], _configurationAssemblies); var value = argumentValue.ConvertTo(elementType, resolutionContext); - addMethod.Invoke(result, new object[] { value }); + addMethod.Invoke(result, new[] { value }); } return true; @@ -164,7 +164,7 @@ where gr.All(z => z.argumentBindResult.success) { return false; } - + var ctorArguments = new List(); foreach (var argumentValue in ctor.ArgumentValues) { diff --git a/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs b/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs index be937a2..ab6378b 100644 --- a/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs @@ -13,20 +13,6 @@ public class DllScanningAssemblyFinderTests : IDisposable const string BinDir2 = "bin2"; const string BinDir3 = "bin3"; - readonly string _privateBinPath; - - public DllScanningAssemblyFinderTests() - { - var d1 = GetOrCreateDirectory(BinDir1); - var d2 = GetOrCreateDirectory(BinDir2); - var d3 = GetOrCreateDirectory(BinDir3); - - _privateBinPath = $"{d1.Name};{d2.FullName};{d3.Name}"; - - DirectoryInfo GetOrCreateDirectory(string name) - => Directory.Exists(name) ? new DirectoryInfo(name) : Directory.CreateDirectory(name); - } - public void Dispose() { Directory.Delete(BinDir1, true); @@ -45,6 +31,13 @@ public void ShouldProbeCurrentDirectory() [Fact] public void ShouldProbePrivateBinPath() { + var d1 = GetOrCreateDirectory(BinDir1); + var d2 = GetOrCreateDirectory(BinDir2); + var d3 = GetOrCreateDirectory(BinDir3); + + DirectoryInfo GetOrCreateDirectory(string name) + => Directory.Exists(name) ? new DirectoryInfo(name) : Directory.CreateDirectory(name); + File.Copy("testdummies.dll", $"{BinDir1}/customSink1.dll", true); File.Copy("testdummies.dll", $"{BinDir2}/customSink2.dll", true); File.Copy("testdummies.dll", $"{BinDir3}/thirdpartydependency.dll", true); @@ -53,7 +46,7 @@ public void ShouldProbePrivateBinPath() new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, - PrivateBinPath = _privateBinPath + PrivateBinPath = $"{d1.Name};{d2.FullName};{d3.Name}" }); try diff --git a/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs b/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs index e2f679e..f7eee44 100644 --- a/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs @@ -24,7 +24,7 @@ public void ReadFromConfigurationSectionReadsFromAnArbitrarySection() LogEvent evt = null; var json = @"{ - ""NotSerilog"": { + ""NotSerilog"": { ""Properties"": { ""App"": ""Test"" } @@ -53,12 +53,12 @@ public void ReadFromConfigurationSectionReadsFromAnArbitrarySection() public void ReadFromConfigurationSectionThrowsWhenTryingToCallConfigurationMethodWithIConfigurationParam() { var json = @"{ - ""NotSerilog"": { + ""NotSerilog"": { ""Using"": [""TestDummies""], ""WriteTo"": [{ ""Name"": ""DummyWithConfiguration"", ""Args"": {} - }] + }] } }"; @@ -84,12 +84,12 @@ public void ReadFromConfigurationSectionThrowsWhenTryingToCallConfigurationMetho public void ReadFromConfigurationDoesNotThrowWhenTryingToCallConfigurationMethodWithIConfigurationParam() { var json = @"{ - ""NotSerilog"": { + ""NotSerilog"": { ""Using"": [""TestDummies""], ""WriteTo"": [{ ""Name"": ""DummyWithConfiguration"", ""Args"": {} - }] + }] } }"; @@ -97,7 +97,7 @@ public void ReadFromConfigurationDoesNotThrowWhenTryingToCallConfigurationMethod .AddJsonString(json) .Build(); - var exception = new LoggerConfiguration() + _ = new LoggerConfiguration() .ReadFrom.Configuration(config, "NotSerilog") .CreateLogger(); @@ -108,12 +108,12 @@ public void ReadFromConfigurationDoesNotThrowWhenTryingToCallConfigurationMethod public void ReadFromConfigurationSectionDoesNotThrowWhenTryingToCallConfigurationMethodWithOptionalIConfigurationParam() { var json = @"{ - ""NotSerilog"": { + ""NotSerilog"": { ""Using"": [""TestDummies""], ""WriteTo"": [{ ""Name"": ""DummyWithOptionalConfiguration"", ""Args"": {} - }] + }] } }"; diff --git a/test/TestDummies/DummyThreadIdEnricher.cs b/test/TestDummies/DummyThreadIdEnricher.cs index 3460d14..a640d55 100644 --- a/test/TestDummies/DummyThreadIdEnricher.cs +++ b/test/TestDummies/DummyThreadIdEnricher.cs @@ -5,10 +5,6 @@ namespace TestDummies { public class DummyThreadIdEnricher : ILogEventEnricher { - static DummyThreadIdEnricher() - { - } - public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { logEvent.AddPropertyIfAbsent(propertyFactory