Ensure IsExternalInit is type forwarded on NET builds (#619)

It's included as internal on netstandard/net472, and the C# compiler may bake a reference to that into a consumer. If that consumer is then used with a net8.0+ build, the IsExternalInit needs to be there and forwarded to the real one.

This switches our polyfill files to always be included but the actual contents ifdef'd out on TFMs that already have the contents. That then makes it easier to do specialized ifdef'ing in the future, as this does for IsExternalInit.
This commit is contained in:
Stephen Toub 2025-07-14 10:30:48 -04:00 • committed by GitHub
commit 5f1c74f1ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 64 additions and 17 deletions

View file

@ -1,3 +1,4 @@
#if !NET
using ModelContextProtocol;
namespace System.Collections.Generic;
@ -18,4 +19,5 @@ internal static class CollectionExtensions
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source) =>
source.ToDictionary(kv => kv.Key, kv => kv.Value);
}
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Diagnostics.CodeAnalysis;
/// <summary>
@ -162,3 +163,4 @@ internal enum DynamicallyAccessedMemberTypes
/// </summary>
All = ~None
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Diagnostics.CodeAnalysis;
/// <summary>
@ -48,3 +49,4 @@ internal sealed class DynamicallyAccessedMembersAttribute : Attribute
/// </summary>
public DynamicallyAccessedMemberTypes MemberTypes { get; }
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
@ -137,3 +138,4 @@ namespace System.Diagnostics.CodeAnalysis
public string[] Members { get; }
}
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Diagnostics.CodeAnalysis;
/// <summary>
@ -36,3 +37,4 @@ internal sealed class RequiresDynamicCodeAttribute : Attribute
/// </summary>
public string? Url { get; set; }
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Diagnostics.CodeAnalysis;
/// <summary>
@ -37,3 +38,4 @@ internal sealed class RequiresUnreferencedCodeAttribute : Attribute
/// </summary>
public string? Url { get; set; }
}
#endif

View file

@ -1,5 +1,7 @@
#if !NET
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute;
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Diagnostics.CodeAnalysis;
/// <summary>Specifies the syntax used in a string.</summary>
@ -65,4 +66,5 @@ internal sealed class StringSyntaxAttribute : Attribute
/// <summary>The syntax identifier for strings containing XML.</summary>
public const string Xml = nameof(Xml);
}
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Diagnostics.CodeAnalysis;
/// <summary>
@ -81,4 +82,5 @@ internal sealed class UnconditionalSuppressMessageAttribute : Attribute
/// Gets or sets the justification for suppressing the code analysis message.
/// </summary>
public string? Justification { get; set; }
}
}
#endif

View file

@ -3,6 +3,7 @@ using System.Buffers;
using System.Runtime.InteropServices;
using System.Text;
#if !NET
namespace System.IO;
internal static class StreamExtensions
@ -61,4 +62,5 @@ internal static class StreamExtensions
}
}
}
}
}
#endif

View file

@ -1,3 +1,4 @@
#if !NET
namespace System.IO;
internal static class TextWriterExtensions
@ -7,4 +8,5 @@ internal static class TextWriterExtensions
cancellationToken.ThrowIfCancellationRequested();
await writer.FlushAsync();
}
}
}
#endif

View file

@ -1,3 +1,4 @@
#if !NET
using ModelContextProtocol;
namespace System.Net.Http;
@ -19,4 +20,5 @@ internal static class HttpClientExtensions
cancellationToken.ThrowIfCancellationRequested();
return await content.ReadAsStringAsync();
}
}
}
#endif

View file

@ -5,6 +5,7 @@
// https://github.com/dotnet/runtime/blob/d2650b6ae7023a2d9d2c74c56116f1f18472ab04/src/libraries/System.Private.CoreLib/src/System/PasteArguments.cs
// and changed from using ValueStringBuilder to StringBuilder.
#if !NET
using System.Text;
namespace System;
@ -98,4 +99,5 @@ internal static partial class PasteArguments
private const char Quote = '\"';
private const char Backslash = '\\';
}
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Runtime.CompilerServices;
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
@ -13,3 +14,4 @@ internal sealed class CallerArgumentExpressionAttribute : Attribute
public string ParameterName { get; }
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
namespace System.Runtime.CompilerServices
{
/// <summary>
@ -30,3 +31,4 @@ namespace System.Runtime.CompilerServices
public const string RequiredMembers = nameof(RequiredMembers);
}
}
#endif

View file

@ -5,6 +5,7 @@
// https://github.com/dotnet/runtime/blob/dd75c45c123055baacd7aa4418f425f412797a29/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/DefaultInterpolatedStringHandler.cs
// and then modified to build on netstandard2.0.
#if !NET
using System.Buffers;
using System.Diagnostics;
using System.Globalization;
@ -614,4 +615,5 @@ namespace System.Runtime.CompilerServices
return value;
}
}
}
}
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
using System.ComponentModel;
namespace System.Runtime.CompilerServices
@ -12,3 +13,8 @@ namespace System.Runtime.CompilerServices
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit;
}
#else
// The compiler emits a reference to the internal copy of this type in the non-.NET builds,
// so we must include a forward to be compatible.
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsExternalInit))]
#endif

View file

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if !NET
using System.ComponentModel;
namespace System.Runtime.CompilerServices
@ -10,3 +11,4 @@ namespace System.Runtime.CompilerServices
[EditorBrowsable(EditorBrowsableState.Never)]
internal sealed class RequiredMemberAttribute : Attribute;
}
#endif

View file

@ -1,3 +1,4 @@
#if !NET
using ModelContextProtocol;
namespace System.Threading.Tasks;
@ -11,4 +12,5 @@ internal static class CancellationTokenSourceExtensions
cancellationTokenSource.Cancel();
return Task.CompletedTask;
}
}
}
#endif

View file

@ -1,3 +1,4 @@
#if !NET
using System.Runtime.CompilerServices;
namespace System.Threading.Channels;
@ -14,4 +15,5 @@ internal static class ChannelExtensions
}
}
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show more