diff --git a/src/.editorconfig b/src/.editorconfig index e1fb38c..3c84748 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -179,7 +179,7 @@ csharp_space_between_parentheses = false csharp_space_between_square_brackets = false # Namespace preference -csharp_style_namespace_declarations = file_scoped:suggestion +csharp_style_namespace_declarations = block_scoped:warning # Types: use keywords instead of BCL types, and permit var only when the type is clear csharp_style_var_for_built_in_types = false:suggestion @@ -206,6 +206,7 @@ csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimenta csharp_style_prefer_pattern_matching = true:silent csharp_style_prefer_not_pattern = true:suggestion csharp_style_prefer_extended_property_pattern = true:suggestion +dotnet_diagnostic.IDE0090.severity = none # Visual Basic files [*.vb] diff --git a/src/SslCertBinding.Net.Tests/CertConfigCmd.cs b/src/SslCertBinding.Net.Tests/CertConfigCmd.cs index 4466fb4..b17c340 100644 --- a/src/SslCertBinding.Net.Tests/CertConfigCmd.cs +++ b/src/SslCertBinding.Net.Tests/CertConfigCmd.cs @@ -51,10 +51,9 @@ public static async Task IpPortIsPresentInConfig(IPEndPoint ipPort) public static Task Add(Options options) { - if (options == null) - throw new ArgumentNullException(nameof(options)); - var sb = new StringBuilder(); + _ = options ?? throw new ArgumentNullException(nameof(options)); + var sb = new StringBuilder(); foreach (FieldInfo optionField in options.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)) { object valObj = optionField.GetValue(options); diff --git a/src/SslCertBinding.Net.Tests/CertificateBindingConfigurationLinuxTests.cs b/src/SslCertBinding.Net.Tests/CertificateBindingConfigurationLinuxTests.cs index 5666b2b..b4fc694 100644 --- a/src/SslCertBinding.Net.Tests/CertificateBindingConfigurationLinuxTests.cs +++ b/src/SslCertBinding.Net.Tests/CertificateBindingConfigurationLinuxTests.cs @@ -1,11 +1,11 @@ -using System; +#if NET5_0_OR_GREATER +#pragma warning disable CA1416 // Validate platform compatibility +using System; using System.Net; using NUnit.Framework; namespace SslCertBinding.Net.Tests { -#if NET5_0_OR_GREATER -#pragma warning disable CA1416 // Validate platform compatibility [TestFixture] [System.Runtime.Versioning.SupportedOSPlatform("linux")] public class CertificateBindingConfigurationLinuxTests @@ -36,6 +36,6 @@ public void BindOnLinuxIsNotSupported() Assert.That(ex, Has.InnerException.TypeOf()); } } +} #pragma warning restore CA1416 // Validate platform compatibility #endif -} diff --git a/src/SslCertBinding.Net/CertificateBindingConfiguration.cs b/src/SslCertBinding.Net/CertificateBindingConfiguration.cs index 5d82acc..3360d34 100644 --- a/src/SslCertBinding.Net/CertificateBindingConfiguration.cs +++ b/src/SslCertBinding.Net/CertificateBindingConfiguration.cs @@ -25,7 +25,6 @@ public void Bind(CertificateBinding binding) HttpApi.CallHttpApi( delegate { - GCHandle sockAddrHandle = SockaddrInterop.CreateSockaddrStructure(binding.IpPort); IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject(); var httpServiceConfigSslKey = new HttpApi.HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort); @@ -109,8 +108,7 @@ public void Delete(IPEndPoint endPoint) public void Delete(IReadOnlyCollection endPoints) { - if (endPoints == null) - throw new ArgumentNullException(nameof(endPoints)); + _ = endPoints ?? throw new ArgumentNullException(nameof(endPoints)); if (endPoints.Count == 0) return; diff --git a/src/SslCertBinding.Net/HttpApi.cs b/src/SslCertBinding.Net/HttpApi.cs index 64922bc..f4f2369 100644 --- a/src/SslCertBinding.Net/HttpApi.cs +++ b/src/SslCertBinding.Net/HttpApi.cs @@ -6,8 +6,6 @@ namespace SslCertBinding.Net { internal class HttpApi { - // ReSharper disable InconsistentNaming - public static void ThrowWin32ExceptionIfError(uint retVal) { if (NOERROR != retVal) @@ -18,9 +16,10 @@ public static void ThrowWin32ExceptionIfError(uint retVal) public static void CallHttpApi(Action body) { + const uint flags = HTTP_INITIALIZE_CONFIG; try { - uint retVal = HttpInitialize(HttpApiVersion, HTTP_INITIALIZE_CONFIG, IntPtr.Zero); + uint retVal = HttpInitialize(HttpApiVersion, flags, IntPtr.Zero); ThrowWin32ExceptionIfError(retVal); } catch (DllNotFoundException ex) @@ -34,9 +33,9 @@ public static void CallHttpApi(Action body) } finally { -#pragma warning disable CA1806 - HttpTerminate(HTTP_INITIALIZE_CONFIG, IntPtr.Zero); -#pragma warning restore CA1806 + + uint retVal = HttpTerminate(flags, IntPtr.Zero); + ThrowWin32ExceptionIfError(retVal); } } @@ -220,6 +219,8 @@ public enum HTTP_SERVICE_CONFIG_SSL_FLAG : uint #endregion +#pragma warning disable IDE1006 // Naming Styles private static readonly HTTPAPI_VERSION HttpApiVersion = new HTTPAPI_VERSION(1, 0); +#pragma warning restore IDE1006 // Naming Styles } }