-
Notifications
You must be signed in to change notification settings - Fork 674
Build ServiceDiscovery library and tests against .NET Framework #10470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
17f3a62
8a61d6f
13992a3
c315b31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
<TargetFrameworks>net462;$(DefaultTargetFramework)</TargetFrameworks> | ||
<IsPackable>true</IsPackable> | ||
<IsAotCompatible>true</IsAotCompatible> | ||
<IsAotCompatible Condition=" '$(TargetFramework)' != 'net462' ">true</IsAotCompatible> | ||
<Description>Provides extensions to HttpClient that enable service discovery based on configuration.</Description> | ||
<PackageIconFullPath>$(DefaultDotnetIconFullPath)</PackageIconFullPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Http" /> | ||
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Tests"/> | ||
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Dns.Tests"/> | ||
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Tests" /> | ||
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Dns.Tests" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.Extensions.ServiceDiscovery.Abstractions\Microsoft.Extensions.ServiceDiscovery.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' "> | ||
<PackageReference Include="Microsoft.Bcl.TimeProvider" /> | ||
</ItemGroup> | ||
|
||
<Import Condition=" '$(TargetFramework)' == 'net462' " Project="$(SharedDir)FxPolyfills\FxPolyfills.targets" /> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System; | ||
|
||
internal static partial class FxPolyfillArgumentException | ||
{ | ||
extension(ArgumentException) | ||
{ | ||
public static void ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null) | ||
{ | ||
if (string.IsNullOrEmpty(argument)) | ||
{ | ||
ThrowNullOrEmptyException(argument, paramName); | ||
} | ||
} | ||
} | ||
|
||
[DoesNotReturn] | ||
private static void ThrowNullOrEmptyException(string? argument, string? paramName) | ||
{ | ||
ArgumentNullException.ThrowIfNull(argument, paramName); | ||
throw new ArgumentException("The value cannot be an empty string.", paramName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System; | ||
|
||
internal static partial class FxPolyfillArgumentNullException | ||
{ | ||
extension(ArgumentNullException) | ||
{ | ||
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null) | ||
{ | ||
if (argument is null) | ||
{ | ||
Throw(paramName); | ||
} | ||
} | ||
} | ||
|
||
[DoesNotReturn] | ||
internal static void Throw(string? paramName) => throw new ArgumentNullException(paramName); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Runtime.CompilerServices; | ||
|
||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] | ||
internal sealed class CallerArgumentExpressionAttribute(string parameterName) : Attribute | ||
{ | ||
public string ParameterName => parameterName; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Collections.Concurrent; | ||
|
||
internal static partial class FxPolyfillConcurrentDictionary | ||
{ | ||
extension<TKey, TValue>(ConcurrentDictionary<TKey, TValue> dictionary) | ||
{ | ||
public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory) | ||
{ | ||
if (dictionary.TryGetValue(key, out var existing)) | ||
{ | ||
return existing; | ||
} | ||
|
||
return dictionary.GetOrAdd(key, valueFactory(key)); | ||
} | ||
|
||
public TValue GetOrAdd<TState>(TKey key, Func<TKey, TState, TValue> valueFactory, TState state) | ||
{ | ||
if (dictionary.TryGetValue(key, out var existing)) | ||
{ | ||
return existing; | ||
} | ||
|
||
return dictionary.GetOrAdd(key, valueFactory(key, state)); | ||
} | ||
|
||
public void TryRemove(TKey key) | ||
{ | ||
dictionary.TryRemove(key, out _); | ||
} | ||
|
||
public void TryRemove(KeyValuePair<TKey, TValue> pair) | ||
{ | ||
if (dictionary.TryRemove(pair.Key, out var existing) && !EqualityComparer<TValue>.Default.Equals(existing, pair.Value)) | ||
{ | ||
dictionary.TryAdd(pair.Key, pair.Value); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.ExceptionServices; | ||
|
||
internal static partial class FxPolyfillExceptionDispatchInfo | ||
{ | ||
extension(ExceptionDispatchInfo) | ||
{ | ||
[DoesNotReturn] | ||
public static void Throw(Exception ex) | ||
{ | ||
ExceptionDispatchInfo.Capture(ex).Throw(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<SharedFxPolyfillsDir>$(MSBuildThisFileDirectory)</SharedFxPolyfillsDir> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Net.Http" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: should this go directly into projects that need it as opposed to globally? It helps with readability when references are all in the same project file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put it here because these are usings that are already automatically added to the projects for .net 8/9, so it continues to be transparent to the consuming library. |
||
|
||
<Using Include="System.Net.Http" /> | ||
<Using Include="System.Threading.Tasks" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
twsouthwick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ExcludedFrameworkPolyfills | ||
Condition="'@(PackageReference->WithMetadataValue('Identity', 'Microsoft.Bcl.TimeProvider'))' == ''" | ||
Include="$(SharedFxPolyfillsDir)Task.TimeProvider.cs" /> | ||
|
||
<Compile Include="$(SharedFxPolyfillsDir)*.cs" | ||
Exclude="@(ExcludedFrameworkPolyfills)" | ||
Link="FxPolyfills/%(Filename).cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Globalization; | ||
|
||
namespace System.Net; | ||
|
||
internal static partial class FxPolyfillIPEndPoint | ||
{ | ||
extension(IPEndPoint) | ||
{ | ||
public static IPEndPoint Parse(string endpoint) | ||
{ | ||
if (TryParse(endpoint.AsSpan(), out var result)) | ||
{ | ||
return result; | ||
} | ||
|
||
throw new FormatException("The endpoint format is invalid."); | ||
} | ||
|
||
public static bool TryParse(ReadOnlySpan<char> s, out IPEndPoint? result) | ||
{ | ||
const int MaxPort = 0x0000FFFF; | ||
|
||
int addressLength = s.Length; // If there's no port then send the entire string to the address parser | ||
int lastColonPos = s.LastIndexOf(':'); | ||
|
||
// Look to see if this is an IPv6 address with a port. | ||
if (lastColonPos > 0) | ||
{ | ||
if (s[lastColonPos - 1] == ']') | ||
{ | ||
addressLength = lastColonPos; | ||
} | ||
// Look to see if this is IPv4 with a port (IPv6 will have another colon) | ||
else if (s.Slice(0, lastColonPos).LastIndexOf(':') == -1) | ||
{ | ||
addressLength = lastColonPos; | ||
} | ||
} | ||
|
||
if (IPAddress.TryParse(s.Slice(0, addressLength).ToString(), out IPAddress? address)) | ||
{ | ||
uint port = 0; | ||
if (addressLength == s.Length || | ||
(uint.TryParse(s.Slice(addressLength + 1).ToString(), NumberStyles.None, CultureInfo.InvariantCulture, out port) && port <= MaxPort)) | ||
|
||
{ | ||
result = new IPEndPoint(address, (int)port); | ||
return true; | ||
} | ||
} | ||
|
||
result = null; | ||
return false; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.