diff --git a/apiCount.include.md b/apiCount.include.md index a95bf691..6f5f185b 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -24,5 +24,5 @@ | `net8.0` | 400 | | `net9.0` | 253 | | `net10.0` | 190 | -| `net11.0` | 58 | +| `net11.0` | 57 | | `uap10.0` | 1071 | diff --git a/readme.md b/readme.md index 0e206798..c772022e 100644 --- a/readme.md +++ b/readme.md @@ -39,7 +39,7 @@ The package targets `netstandard2.0` and is designed to support the following ru | `net8.0` | 400 | | `net9.0` | 253 | | `net10.0` | 190 | -| `net11.0` | 58 | +| `net11.0` | 57 | | `uap10.0` | 1071 | diff --git a/src/Polyfill/StringBuilderPolyfill.cs b/src/Polyfill/StringBuilderPolyfill.cs index 860747ce..60c6eec4 100644 --- a/src/Polyfill/StringBuilderPolyfill.cs +++ b/src/Polyfill/StringBuilderPolyfill.cs @@ -1,4 +1,4 @@ -#if !NET12_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; diff --git a/src/Split/net10.0/StringBuilderPolyfill.cs b/src/Split/net10.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net10.0/StringBuilderPolyfill.cs +++ b/src/Split/net10.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net11.0/StringBuilderPolyfill.cs b/src/Split/net11.0/StringBuilderPolyfill.cs deleted file mode 100644 index cddb85db..00000000 --- a/src/Split/net11.0/StringBuilderPolyfill.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -#pragma warning disable -#if !NET12_0_OR_GREATER -namespace Polyfills; -using System; -using System.Reflection; -using System.Text; -static partial class Polyfill -{ - extension(StringBuilder) - { - /// - /// Creates a new instance initialized to the same state as - /// , and resets to an empty, usable state - /// with no allocated buffers. Ownership of the chunks is transferred in O(1); the underlying - /// character data is not copied. 's - /// is preserved. - /// - public static StringBuilder MoveChunks(StringBuilder source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - var charsField = MoveChunksFields.ChunkChars; - var previousField = MoveChunksFields.ChunkPrevious; - var lengthField = MoveChunksFields.ChunkLength; - var offsetField = MoveChunksFields.ChunkOffset; - var maxCapacity = (int) MoveChunksFields.MaxCapacity.GetValue(source)!; - var destination = new StringBuilder(0, maxCapacity); - charsField.SetValue(destination, charsField.GetValue(source)); - previousField.SetValue(destination, previousField.GetValue(source)); - lengthField.SetValue(destination, lengthField.GetValue(source)); - offsetField.SetValue(destination, offsetField.GetValue(source)); - charsField.SetValue(source, Array.Empty()); - previousField.SetValue(source, null); - lengthField.SetValue(source, 0); - offsetField.SetValue(source, 0); - return destination; - } - } - static class MoveChunksFields - { - internal static readonly FieldInfo ChunkChars = GetField("m_ChunkChars"); - internal static readonly FieldInfo ChunkPrevious = GetField("m_ChunkPrevious"); - internal static readonly FieldInfo ChunkLength = GetField("m_ChunkLength"); - internal static readonly FieldInfo ChunkOffset = GetField("m_ChunkOffset"); - internal static readonly FieldInfo MaxCapacity = GetField("m_MaxCapacity"); - static FieldInfo GetField(string name) => - typeof(StringBuilder).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic) ?? - throw new($"Expected to find field '{name}' on StringBuilder"); - } -} -#endif diff --git a/src/Split/net461/StringBuilderPolyfill.cs b/src/Split/net461/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net461/StringBuilderPolyfill.cs +++ b/src/Split/net461/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net462/StringBuilderPolyfill.cs b/src/Split/net462/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net462/StringBuilderPolyfill.cs +++ b/src/Split/net462/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net47/StringBuilderPolyfill.cs b/src/Split/net47/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net47/StringBuilderPolyfill.cs +++ b/src/Split/net47/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net471/StringBuilderPolyfill.cs b/src/Split/net471/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net471/StringBuilderPolyfill.cs +++ b/src/Split/net471/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net472/StringBuilderPolyfill.cs b/src/Split/net472/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net472/StringBuilderPolyfill.cs +++ b/src/Split/net472/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net48/StringBuilderPolyfill.cs b/src/Split/net48/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net48/StringBuilderPolyfill.cs +++ b/src/Split/net48/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net481/StringBuilderPolyfill.cs b/src/Split/net481/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net481/StringBuilderPolyfill.cs +++ b/src/Split/net481/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net5.0/StringBuilderPolyfill.cs b/src/Split/net5.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net5.0/StringBuilderPolyfill.cs +++ b/src/Split/net5.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net6.0/StringBuilderPolyfill.cs b/src/Split/net6.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net6.0/StringBuilderPolyfill.cs +++ b/src/Split/net6.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net7.0/StringBuilderPolyfill.cs b/src/Split/net7.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net7.0/StringBuilderPolyfill.cs +++ b/src/Split/net7.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net8.0/StringBuilderPolyfill.cs b/src/Split/net8.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net8.0/StringBuilderPolyfill.cs +++ b/src/Split/net8.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/net9.0/StringBuilderPolyfill.cs b/src/Split/net9.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/net9.0/StringBuilderPolyfill.cs +++ b/src/Split/net9.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/netcoreapp2.0/StringBuilderPolyfill.cs b/src/Split/netcoreapp2.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/netcoreapp2.0/StringBuilderPolyfill.cs +++ b/src/Split/netcoreapp2.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/netcoreapp2.1/StringBuilderPolyfill.cs b/src/Split/netcoreapp2.1/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/netcoreapp2.1/StringBuilderPolyfill.cs +++ b/src/Split/netcoreapp2.1/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/netcoreapp2.2/StringBuilderPolyfill.cs b/src/Split/netcoreapp2.2/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/netcoreapp2.2/StringBuilderPolyfill.cs +++ b/src/Split/netcoreapp2.2/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/netcoreapp3.0/StringBuilderPolyfill.cs b/src/Split/netcoreapp3.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/netcoreapp3.0/StringBuilderPolyfill.cs +++ b/src/Split/netcoreapp3.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/netcoreapp3.1/StringBuilderPolyfill.cs b/src/Split/netcoreapp3.1/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/netcoreapp3.1/StringBuilderPolyfill.cs +++ b/src/Split/netcoreapp3.1/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/netstandard2.0/StringBuilderPolyfill.cs b/src/Split/netstandard2.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/netstandard2.0/StringBuilderPolyfill.cs +++ b/src/Split/netstandard2.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/netstandard2.1/StringBuilderPolyfill.cs b/src/Split/netstandard2.1/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/netstandard2.1/StringBuilderPolyfill.cs +++ b/src/Split/netstandard2.1/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Split/uap10.0/StringBuilderPolyfill.cs b/src/Split/uap10.0/StringBuilderPolyfill.cs index cddb85db..09ce3dce 100644 --- a/src/Split/uap10.0/StringBuilderPolyfill.cs +++ b/src/Split/uap10.0/StringBuilderPolyfill.cs @@ -1,6 +1,5 @@ // #pragma warning disable -#if !NET12_0_OR_GREATER namespace Polyfills; using System; using System.Reflection; @@ -51,4 +50,3 @@ static FieldInfo GetField(string name) => throw new($"Expected to find field '{name}' on StringBuilder"); } } -#endif diff --git a/src/Tests/PolyfillTests_StringBuilder.cs b/src/Tests/PolyfillTests_StringBuilder.cs index 3ba5946e..3c47878c 100644 --- a/src/Tests/PolyfillTests_StringBuilder.cs +++ b/src/Tests/PolyfillTests_StringBuilder.cs @@ -128,6 +128,19 @@ public async Task MoveChunks() public async Task MoveChunks_Null_Throws() => await Assert.That(() => StringBuilder.MoveChunks(null!)).Throws(); + // Where the BCL declares StringBuilder.MoveChunks the polyfill must not be compiled: a static + // member of the type always wins over a static extension member, so it would be dead code. + [Test] + public async Task MoveChunks_NotPolyfilledWhereBclHasIt() + { + var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; + Type[] parameters = [typeof(StringBuilder)]; + var inBcl = typeof(StringBuilder).GetMethod("MoveChunks", flags, null, parameters, null) != null; + var inPolyfill = typeof(Polyfills.Polyfill).GetMethod("MoveChunks", flags, null, parameters, null) != null; + + await Assert.That(inBcl && inPolyfill).IsFalse(); + } + [Test] public async Task StringBuilder_Insert_ReadOnlySpan() {