Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
segor committed Feb 15, 2024
1 parent dc9f846 commit f45cdd0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions src/SslCertBinding.Net.Tests/CertConfigCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ public static async Task<bool> IpPortIsPresentInConfig(IPEndPoint ipPort)

public static Task<CommandResult> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,6 +36,6 @@ public void BindOnLinuxIsNotSupported()
Assert.That(ex, Has.InnerException.TypeOf<DllNotFoundException>());
}
}
}
#pragma warning restore CA1416 // Validate platform compatibility
#endif
}
4 changes: 1 addition & 3 deletions src/SslCertBinding.Net/CertificateBindingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -109,8 +108,7 @@ public void Delete(IPEndPoint endPoint)

public void Delete(IReadOnlyCollection<IPEndPoint> endPoints)
{
if (endPoints == null)
throw new ArgumentNullException(nameof(endPoints));
_ = endPoints ?? throw new ArgumentNullException(nameof(endPoints));
if (endPoints.Count == 0)
return;

Expand Down
13 changes: 7 additions & 6 deletions src/SslCertBinding.Net/HttpApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace SslCertBinding.Net
{
internal class HttpApi
{
// ReSharper disable InconsistentNaming

public static void ThrowWin32ExceptionIfError(uint retVal)
{
if (NOERROR != retVal)
Expand All @@ -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)
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit f45cdd0

Please sign in to comment.