Skip to content

Commit 5f1c74f

Browse files
authored
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.
1 parent 1232456 commit 5f1c74f

25 files changed

+64
-17
lines changed

src/Common/Polyfills/System/Collections/Generic/CollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !NET
12
using ModelContextProtocol;
23

34
namespace System.Collections.Generic;
@@ -18,4 +19,5 @@ public static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TK
1819

1920
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source) =>
2021
source.ToDictionary(kv => kv.Key, kv => kv.Value);
21-
}
22+
}
23+
#endif

src/Common/Polyfills/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMemberTypes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#if !NET
45
namespace System.Diagnostics.CodeAnalysis;
56

67
/// <summary>
@@ -162,3 +163,4 @@ internal enum DynamicallyAccessedMemberTypes
162163
/// </summary>
163164
All = ~None
164165
}
166+
#endif

src/Common/Polyfills/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMembersAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#if !NET
45
namespace System.Diagnostics.CodeAnalysis;
56

67
/// <summary>
@@ -48,3 +49,4 @@ public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes member
4849
/// </summary>
4950
public DynamicallyAccessedMemberTypes MemberTypes { get; }
5051
}
52+
#endif

src/Common/Polyfills/System/Diagnostics/CodeAnalysis/NullableAttributes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#if !NET
45
namespace System.Diagnostics.CodeAnalysis
56
{
67
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
@@ -137,3 +138,4 @@ public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
137138
public string[] Members { get; }
138139
}
139140
}
141+
#endif

src/Common/Polyfills/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#if !NET
45
namespace System.Diagnostics.CodeAnalysis;
56

67
/// <summary>
@@ -36,3 +37,4 @@ public RequiresDynamicCodeAttribute(string message)
3637
/// </summary>
3738
public string? Url { get; set; }
3839
}
40+
#endif

src/Common/Polyfills/System/Diagnostics/CodeAnalysis/RequiresUnreferencedCode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#if !NET
45
namespace System.Diagnostics.CodeAnalysis;
56

67
/// <summary>
@@ -37,3 +38,4 @@ public RequiresUnreferencedCodeAttribute(string message)
3738
/// </summary>
3839
public string? Url { get; set; }
3940
}
41+
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#if !NET
12
namespace System.Diagnostics.CodeAnalysis
23
{
34
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
45
internal sealed class SetsRequiredMembersAttribute : Attribute;
56
}
7+
#endif

src/Common/Polyfills/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#if !NET
45
namespace System.Diagnostics.CodeAnalysis;
56

67
/// <summary>Specifies the syntax used in a string.</summary>
@@ -65,4 +66,5 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments)
6566

6667
/// <summary>The syntax identifier for strings containing XML.</summary>
6768
public const string Xml = nameof(Xml);
68-
}
69+
}
70+
#endif

src/Common/Polyfills/System/Diagnostics/CodeAnalysis/UnconditionalSuppressMessageAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#if !NET
45
namespace System.Diagnostics.CodeAnalysis;
56

67
/// <summary>
@@ -81,4 +82,5 @@ public UnconditionalSuppressMessageAttribute(string category, string checkId)
8182
/// Gets or sets the justification for suppressing the code analysis message.
8283
/// </summary>
8384
public string? Justification { get; set; }
84-
}
85+
}
86+
#endif

src/Common/Polyfills/System/IO/StreamExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.InteropServices;
44
using System.Text;
55

6+
#if !NET
67
namespace System.IO;
78

89
internal static class StreamExtensions
@@ -61,4 +62,5 @@ static async ValueTask<int> ReadAsyncCore(Stream stream, Memory<byte> buffer, Ca
6162
}
6263
}
6364
}
64-
}
65+
}
66+
#endif

0 commit comments

Comments
 (0)