cleanup some #if for NETSTANDARD1_3

This commit is contained in:
Stef Heyenrath
2025-08-31 11:07:25 +02:00
parent 5c221ff4fa
commit bb561c94d0
17 changed files with 67 additions and 65 deletions

View File

@@ -44,18 +44,16 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentBuilder" Version="0.12.0"> <PackageReference Include="FluentBuilder" Version="0.13.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Polyfill" Version="8.8.0">
<!-- Keep at 6.14.0 -->
<PackageReference Include="Polyfill" Version="6.14.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<!--<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>-->
</ItemGroup> </ItemGroup>
<!--<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard')) and '$(TargetFramework)' != 'netstandard1.0'"> <!--<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard')) and '$(TargetFramework)' != 'netstandard1.0'">

View File

@@ -1,6 +1,6 @@
// Copyright © WireMock.Net // Copyright © WireMock.Net
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
@@ -112,4 +112,4 @@ internal class AzureADAuthenticationMatcher : IStringMatcher
return false; return false;
} }
} }
#endif //#endif

View File

@@ -1,6 +1,6 @@
// Copyright © WireMock.Net // Copyright © WireMock.Net
#if NET451 || NET452 || NET46 || NET461 || NET48 || NETSTANDARD1_3 || NETSTANDARD2_0 #if NET48
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using WireMock.Constants; using WireMock.Constants;

View File

@@ -56,10 +56,10 @@ internal static class HttpClientBuilder
} }
} }
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = (message, cert, chain, errors) => true; ServicePointManager.ServerCertificateValidationCallback = (message, cert, chain, errors) => true;
#endif //#endif
return HttpClientFactory2.Create(handler); return HttpClientFactory2.Create(handler);
} }

View File

@@ -11,9 +11,9 @@ using WireMock.Models;
using Stef.Validation; using Stef.Validation;
using WireMock.Admin.Mappings; using WireMock.Admin.Mappings;
using WireMock.Util; using WireMock.Util;
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
using Wmhelp.XPath2; using Wmhelp.XPath2;
#endif //#endif
namespace WireMock.Matchers; namespace WireMock.Matchers;
@@ -151,18 +151,18 @@ public class XPathMatcher : IStringMatcher
var xmlNamespaceManager = GetXmlNamespaceManager(xmlNamespaceMap); var xmlNamespaceManager = GetXmlNamespaceManager(xmlNamespaceMap);
if (xmlNamespaceManager == null) if (xmlNamespaceManager == null)
{ {
#if NETSTANDARD1_3 //#if NETSTANDARD1_3
return navigator.Evaluate(xpath); //return navigator.Evaluate(xpath);
#else //#else
return navigator.XPath2Evaluate(xpath); return navigator.XPath2Evaluate(xpath);
#endif //#endif
} }
#if NETSTANDARD1_3 //#if NETSTANDARD1_3
return navigator.Evaluate(xpath, xmlNamespaceManager); //return navigator.Evaluate(xpath, xmlNamespaceManager);
#else //#else
return navigator.XPath2Evaluate(xpath, xmlNamespaceManager); return navigator.XPath2Evaluate(xpath, xmlNamespaceManager);
#endif //#endif
} }
private XmlNamespaceManager? GetXmlNamespaceManager(IEnumerable<XmlNamespace>? xmlNamespaceMap) private XmlNamespaceManager? GetXmlNamespaceManager(IEnumerable<XmlNamespace>? xmlNamespaceMap)

View File

@@ -136,17 +136,17 @@ internal partial class AspNetCoreSelfHost : IOwinSelfHost
#if NET8_0 #if NET8_0
_logger.Info("Server using .NET 8.0"); _logger.Info("Server using .NET 8.0");
#elif NET48 #elif NET48
_logger.Info("Server using .NET Framework 4.6.1 or higher"); _logger.Info("Server using .NET Framework 4.8");
#endif #endif
#if NETSTANDARD1_3 //#if NETSTANDARD1_3
return Task.Run(() => // return Task.Run(() =>
{ // {
_host.Run(token); // _host.Run(token);
}); // });
#else //#else
return _host.RunAsync(token); return _host.RunAsync(token);
#endif //#endif
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -541,15 +541,15 @@ public partial class WireMockServer : IWireMockServer
Guard.NotNull(tenant); Guard.NotNull(tenant);
Guard.NotNull(audience); Guard.NotNull(audience);
#if NETSTANDARD1_3 //#if NETSTANDARD1_3
throw new NotSupportedException("AzureADAuthentication is not supported for NETStandard 1.3"); // throw new NotSupportedException("AzureADAuthentication is not supported for NETStandard 1.3");
#else //#else
_options.AuthenticationMatcher = new AzureADAuthenticationMatcher( _options.AuthenticationMatcher = new AzureADAuthenticationMatcher(
new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler(), new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler(),
new Microsoft.IdentityModel.Protocols.ConfigurationManager<Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration>($"https://login.microsoftonline.com/{tenant}/.well-known/openid-configuration", new Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever()), new Microsoft.IdentityModel.Protocols.ConfigurationManager<Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration>($"https://login.microsoftonline.com/{tenant}/.well-known/openid-configuration", new Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever()),
tenant, tenant,
audience); audience);
#endif //#endif
} }
/// <inheritdoc cref="IWireMockServer.SetBasicAuthentication(string, string)" /> /// <inheritdoc cref="IWireMockServer.SetBasicAuthentication(string, string)" />

View File

@@ -24,7 +24,7 @@ internal static class WireMockHandlebarsHelpers
GetBaseDirectory(), GetBaseDirectory(),
}; };
#if !NETSTANDARD1_3_OR_GREATER //#if !NETSTANDARD1_3_OR_GREATER
void Add(string? path, ICollection<string> customHelperPaths) void Add(string? path, ICollection<string> customHelperPaths)
{ {
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
@@ -36,7 +36,7 @@ internal static class WireMockHandlebarsHelpers
Add(Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location), paths); Add(Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location), paths);
Add(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), paths); Add(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), paths);
Add(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName), paths); Add(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName), paths);
#endif //#endif
o.CustomHelperPaths = paths; o.CustomHelperPaths = paths;
o.CustomHelpers = new Dictionary<string, IHelpers>(); o.CustomHelpers = new Dictionary<string, IHelpers>();
@@ -49,7 +49,7 @@ internal static class WireMockHandlebarsHelpers
private static string GetBaseDirectory() private static string GetBaseDirectory()
{ {
#if NETSTANDARD1_3_OR_GREATER || NET6_0_OR_GREATER #if NET8_0_OR_GREATER
return AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar); return AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
#else #else
return AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar); return AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);

View File

@@ -18,12 +18,12 @@ internal static class CultureInfoUtils
try try
{ {
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
if (int.TryParse(value, out var culture)) if (int.TryParse(value, out var culture))
{ {
return new CultureInfo(culture); return new CultureInfo(culture);
} }
#endif //#endif
if (string.Equals(value, nameof(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase)) if (string.Equals(value, nameof(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase))
{ {
return CultureInfo.CurrentCulture; return CultureInfo.CurrentCulture;

View File

@@ -37,9 +37,9 @@ internal static class PortUtils
} }
finally finally
{ {
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
portSocket.Close(); portSocket.Close();
#endif //#endif
portSocket.Dispose(); portSocket.Dispose();
} }
} }
@@ -75,9 +75,9 @@ internal static class PortUtils
{ {
foreach (var socket in sockets) foreach (var socket in sockets)
{ {
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
socket.Close(); socket.Close();
#endif //#endif
socket.Dispose(); socket.Dispose();
} }
} }

View File

@@ -24,10 +24,13 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polyfill" Version="8.8.0">
<!-- Keep at 6.14.0 -->
<PackageReference Include="Polyfill" Version="6.14.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="RamlToOpenApiConverter.SourceOnly" Version="0.9.0" /> <PackageReference Include="RamlToOpenApiConverter.SourceOnly" Version="0.9.0" />
<PackageReference Include="YamlDotNet" Version="16.3.0" /> <PackageReference Include="YamlDotNet" Version="16.3.0" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.19.1" /> <PackageReference Include="RandomDataGenerator.Net" Version="1.0.19.1" />

View File

@@ -10,9 +10,9 @@ namespace WireMock.RegularExpressions;
/// <summary> /// <summary>
/// Extension to the <see cref="Regex"/> object, adding support for GUID tokens for matching on. /// Extension to the <see cref="Regex"/> object, adding support for GUID tokens for matching on.
/// </summary> /// </summary>
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
[Serializable] [Serializable]
#endif //#endif
internal class RegexExtended : Regex internal class RegexExtended : Regex
{ {
/// <inheritdoc cref="Regex"/> /// <inheritdoc cref="Regex"/>
@@ -32,7 +32,7 @@ internal class RegexExtended : Regex
{ {
} }
#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER #if !NET8_0_OR_GREATER
/// <inheritdoc cref="Regex"/> /// <inheritdoc cref="Regex"/>
protected RegexExtended(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : protected RegexExtended(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) :
base(info, context) base(info, context)

View File

@@ -23,9 +23,9 @@ internal static class CompressionUtils
using var zipStream = Create(contentEncoding, compressedStream, CompressionMode.Compress); using var zipStream = Create(contentEncoding, compressedStream, CompressionMode.Compress);
zipStream.Write(data, 0, data.Length); zipStream.Write(data, 0, data.Length);
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
zipStream.Close(); zipStream.Close();
#endif //#endif
return compressedStream.ToArray(); return compressedStream.ToArray();
} }

View File

@@ -142,16 +142,16 @@ internal static class TypeLoader
private static bool TryFindTypeInDlls<TInterface>(string? implementationTypeFullName, [NotNullWhen(true)] out Type? pluginType) where TInterface : class private static bool TryFindTypeInDlls<TInterface>(string? implementationTypeFullName, [NotNullWhen(true)] out Type? pluginType) where TInterface : class
{ {
#if NETSTANDARD1_3 //#if NETSTANDARD1_3
var directoriesToSearch = new[] { AppContext.BaseDirectory }; // var directoriesToSearch = new[] { AppContext.BaseDirectory };
#else //#else
var processDirectory = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName); var processDirectory = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName);
var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var directoriesToSearch = new[] { processDirectory, assemblyDirectory } var directoriesToSearch = new[] { processDirectory, assemblyDirectory }
.Where(d => !string.IsNullOrEmpty(d)) .Where(d => !string.IsNullOrEmpty(d))
.Distinct() .Distinct()
.ToArray(); .ToArray();
#endif //#endif
foreach (var directory in directoriesToSearch) foreach (var directory in directoriesToSearch)
{ {
foreach (var file in Directory.GetFiles(directory!, "*.dll")) foreach (var file in Directory.GetFiles(directory!, "*.dll"))

View File

@@ -43,7 +43,8 @@
</PropertyGroup>--> </PropertyGroup>-->
<ItemGroup> <ItemGroup>
<PackageReference Include="Polyfill" Version="8.8.0"> <!-- Keep at 6.14.0 -->
<PackageReference Include="Polyfill" Version="6.14.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>

View File

@@ -1,7 +1,7 @@
// Copyright © WireMock.Net // Copyright © WireMock.Net
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; //using System.Xml;
using NFluent; using NFluent;
using WireMock.Models; using WireMock.Models;
using WireMock.ResponseBuilders; using WireMock.ResponseBuilders;
@@ -12,9 +12,9 @@ using Xunit;
using Moq; using Moq;
using WireMock.Handlers; using WireMock.Handlers;
using FluentAssertions; using FluentAssertions;
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
using Wmhelp.XPath2; //using Wmhelp.XPath2;
#endif //#endif
namespace WireMock.Net.Tests.ResponseBuilders; namespace WireMock.Net.Tests.ResponseBuilders;
@@ -57,7 +57,7 @@ public class ResponseWithHandlebarsXPathTests
.WithTransformer(); .WithTransformer();
// Act // Act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false); var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings);
// Assert // Assert
response.Message.BodyData!.BodyAsString.Should().Be("<response>abc</response>"); response.Message.BodyData!.BodyAsString.Should().Be("<response>abc</response>");
@@ -85,7 +85,7 @@ public class ResponseWithHandlebarsXPathTests
.WithTransformer(); .WithTransformer();
// Act // Act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false); var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings);
// Assert // Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("abc"); Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("abc");
@@ -113,7 +113,7 @@ public class ResponseWithHandlebarsXPathTests
.WithTransformer(); .WithTransformer();
// Act // Act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false); var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings);
// Assert // Assert
response.Message.BodyData!.BodyAsString.Should().Be("<response>abc,def,xyz</response>"); response.Message.BodyData!.BodyAsString.Should().Be("<response>abc,def,xyz</response>");
@@ -169,7 +169,7 @@ public class ResponseWithHandlebarsXPathTests
.WithTransformer(); .WithTransformer();
// Act // Act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false); var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings);
// Assert // Assert
response.Message.BodyData!.BodyAsString.Should().Be("<response>0000083256</response>"); response.Message.BodyData!.BodyAsString.Should().Be("<response>0000083256</response>");
@@ -197,7 +197,7 @@ public class ResponseWithHandlebarsXPathTests
.WithTransformer(); .WithTransformer();
// Act // Act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false); var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings);
// Assert // Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualIgnoringCase("True"); Check.That(response.Message.BodyData.BodyAsString).IsEqualIgnoringCase("True");
@@ -225,7 +225,7 @@ public class ResponseWithHandlebarsXPathTests
.WithTransformer(); .WithTransformer();
// Act // Act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false); var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings);
// Assert // Assert
Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("a1"); Check.That(response.Message.BodyData.BodyAsString).IsEqualTo("a1");

View File

@@ -39,7 +39,7 @@ public class CultureInfoUtilsTests
result.Should().Be(expectedCulture); result.Should().Be(expectedCulture);
} }
#if !NETSTANDARD1_3 //#if !NETSTANDARD1_3
[Fact] [Fact]
public void Parse_IntegerInput_ReturnsExpectedCultureInfo() public void Parse_IntegerInput_ReturnsExpectedCultureInfo()
{ {
@@ -53,7 +53,7 @@ public class CultureInfoUtilsTests
// Assert // Assert
result.Should().Be(expectedCulture); result.Should().Be(expectedCulture);
} }
#endif //#endif
[Fact] [Fact]
public void Parse_CurrentCultureInput_ReturnsCurrentCulture() public void Parse_CurrentCultureInput_ReturnsCurrentCulture()