Install
dotnet add package Meziantou.Polyfill --version 1.0.37
| Product | Versions |
|---|---|
| .NET Standard |
README
Meziantou.Polyfill
Source Generator that adds polyfill methods and types. This helps working with multi-targeted projects.
Read more about the project: Polyfills in .NET to ease multi-targeting
Installation
dotnet add package Meziantou.Polyfill
Then, you should see the generated types in the solution explorer

Customization
By default, all needed polyfills are generated. You can configure which polyfills should be generated by editing the .csproj file and adding the following properties:
<PropertyGroup>
<!-- semicolon-separated or pipe-separated list of name prefix -->
<!-- Tip: The name of the generated polyfills are available in the generated "Debug.g.cs" file -->
<MeziantouPolyfill_IncludedPolyfills>T:Type1|T:Type2|M:Member1</MeziantouPolyfill_IncludedPolyfills>
<MeziantouPolyfill_ExcludedPolyfills>M:System.Diagnostics.</MeziantouPolyfill_ExcludedPolyfills>
<!-- Optional: Output the generated files to the obj\GeneratedFiles folder -->
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
Supported polyfills
Types
System.Collections.Generic.PriorityQueue<TElement, TPriority>System.Collections.Generic.ReferenceEqualityComparerSystem.Diagnostics.CodeAnalysis.AllowNullAttributeSystem.Diagnostics.CodeAnalysis.DisallowNullAttributeSystem.Diagnostics.CodeAnalysis.DoesNotReturnAttributeSystem.Diagnostics.CodeAnalysis.DoesNotReturnIfAttributeSystem.Diagnostics.CodeAnalysis.DynamicDependencyAttributeSystem.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypesSystem.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttributeSystem.Diagnostics.CodeAnalysis.ExperimentalAttributeSystem.Diagnostics.CodeAnalysis.MaybeNullAttributeSystem.Diagnostics.CodeAnalysis.MaybeNullWhenAttributeSystem.Diagnostics.CodeAnalysis.MemberNotNullAttributeSystem.Diagnostics.CodeAnalysis.MemberNotNullWhenAttributeSystem.Diagnostics.CodeAnalysis.NotNullAttributeSystem.Diagnostics.CodeAnalysis.NotNullIfNotNullAttributeSystem.Diagnostics.CodeAnalysis.NotNullWhenAttributeSystem.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttributeSystem.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttributeSystem.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttributeSystem.Diagnostics.CodeAnalysis.SetsRequiredMembersAttributeSystem.Diagnostics.CodeAnalysis.StringSyntaxAttributeSystem.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttributeSystem.Diagnostics.CodeAnalysis.UnscopedRefAttributeSystem.Diagnostics.StackTraceHiddenAttributeSystem.HashCodeSystem.IndexSystem.Net.Http.ReadOnlyMemoryContentSystem.RangeSystem.Runtime.CompilerServices.AsyncMethodBuilderAttributeSystem.Runtime.CompilerServices.CallerArgumentExpressionAttributeSystem.Runtime.CompilerServices.CollectionBuilderAttributeSystem.Runtime.CompilerServices.CompilerFeatureRequiredAttributeSystem.Runtime.CompilerServices.DisableRuntimeMarshallingAttributeSystem.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttributeSystem.Runtime.CompilerServices.InterpolatedStringHandlerAttributeSystem.Runtime.CompilerServices.IsExternalInitSystem.Runtime.CompilerServices.ModuleInitializerAttributeSystem.Runtime.CompilerServices.RequiredMemberAttributeSystem.Runtime.CompilerServices.SkipLocalsInitAttributeSystem.Runtime.CompilerServices.TupleElementNamesAttributeSystem.Runtime.InteropServices.SuppressGCTransitionAttributeSystem.Runtime.InteropServices.UnmanagedCallersOnlyAttributeSystem.Runtime.Versioning.ObsoletedOSPlatformAttributeSystem.Runtime.Versioning.RequiresPreviewFeaturesAttributeSystem.Runtime.Versioning.SupportedOSPlatformAttributeSystem.Runtime.Versioning.SupportedOSPlatformGuardAttributeSystem.Runtime.Versioning.TargetPlatformAttributeSystem.Runtime.Versioning.UnsupportedOSPlatformAttributeSystem.Runtime.Versioning.UnsupportedOSPlatformGuardAttributeSystem.Threading.Tasks.TaskToAsyncResultSystem.ValueTupleSystem.ValueTupleSystem.ValueTuple<T1, T2>System.ValueTuple<T1, T2, T3>System.ValueTuple<T1, T2, T3, T4>System.ValueTuple<T1, T2, T3, T4, T5>System.ValueTuple<T1, T2, T3, T4, T5, T6>System.ValueTuple<T1, T2, T3, T4, T5, T6, T7>System.ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> where TRest : structSystem.ITupleInternal
Methods
System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.GetOrAdd(TKey key, System.Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument)System.Collections.Generic.CollectionExtensions.GetValueOrDefault<TKey, TValue>(this System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)System.Collections.Generic.CollectionExtensions.GetValueOrDefault<TKey, TValue>(this System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)System.Collections.Generic.KeyValuePair<TKey, TValue>.Deconstruct(out TKey key, out TValue value)System.Collections.Generic.Queue.TryDequeue(out T result)System.Collections.Immutable.ImmutableArray.AsSpan(System.Int32 start, System.Int32 length)System.Collections.Immutable.ImmutableArray.AsSpan(System.Range range)System.Diagnostics.Process.WaitForExitAsync([System.Threading.CancellationToken cancellationToken = default])System.IO.Stream.Read(System.Span<System.Byte> buffer)System.IO.Stream.ReadAsync(System.Memory<System.Byte> buffer, [System.Threading.CancellationToken cancellationToken = default])System.IO.Stream.ReadAtLeast(System.Span<System.Byte> buffer, System.Int32 minimumBytes, [System.Boolean throwOnEndOfStream = true])System.IO.Stream.ReadAtLeastAsync(System.Memory<System.Byte> buffer, System.Int32 minimumBytes, [System.Boolean throwOnEndOfStream = true], [System.Threading.CancellationToken cancellationToken = default])System.IO.Stream.Write(System.ReadOnlySpan<System.Byte> buffer)System.IO.Stream.WriteAsync(System.ReadOnlyMemory<System.Byte> buffer, [System.Threading.CancellationToken cancellationToken = default])System.IO.StreamReader.ReadLineAsync()System.IO.StreamReader.ReadLineAsync(System.Threading.CancellationToken cancellationToken)System.IO.TextReader.ReadAsync(System.Memory<System.Char> buffer, [System.Threading.CancellationToken cancellationToken = default])System.IO.TextReader.ReadToEndAsync(System.Threading.CancellationToken cancellationToken)System.IO.TextWriter.WriteAsync(System.ReadOnlyMemory<System.Char> buffer, [System.Threading.CancellationToken cancellationToken = default])System.Linq.Enumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector, System.Func<TKey, TAccumulate> seedSelector, System.Func<TAccumulate, TSource, TAccumulate> func, [System.Collections.Generic.IEqualityComparer? keyComparer = null]) where TKey : notnullSystem.Linq.Enumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector, TAccumulate seed, System.Func<TAccumulate, TSource, TAccumulate> func, [System.Collections.Generic.IEqualityComparer? keyComparer = null]) where TKey : notnullSystem.Linq.Enumerable.CountBy<TSource, TKey>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector, [System.Collections.Generic.IEqualityComparer? keyComparer = null]) where TKey : notnullSystem.Linq.Enumerable.DistinctBy<TSource, TKey>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector)System.Linq.Enumerable.DistinctBy<TSource, TKey>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector, System.Collections.Generic.IEqualityComparer? comparer)System.Linq.Enumerable.Index(this System.Collections.Generic.IEnumerable source)System.Linq.Enumerable.MaxBy<TSource, TKey>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector)System.Linq.Enumerable.MaxBy<TSource, TKey>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector, System.Collections.Generic.IComparer? comparer)System.Linq.Enumerable.MinBy<TSource, TKey>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector)System.Linq.Enumerable.MinBy<TSource, TKey>(this System.Collections.Generic.IEnumerable source, System.Func<TSource, TKey> keySelector, System.Collections.Generic.IComparer? comparer)System.Linq.Enumerable.OrderDescending(this System.Collections.Generic.IEnumerable source)System.Linq.Enumerable.OrderDescending(this System.Collections.Generic.IEnumerable source, System.Collections.Generic.IComparer? comparer)System.Linq.Enumerable.Order(this System.Collections.Generic.IEnumerable source)System.Linq.Enumerable.Order(this System.Collections.Generic.IEnumerable source, System.Collections.Generic.IComparer? comparer)System.Linq.Enumerable.ToHashSet(this System.Collections.Generic.IEnumerable source)System.Linq.Enumerable.ToHashSet(this System.Collections.Generic.IEnumerable source, System.Collections.Generic.IEqualityComparer? comparer)System.Linq.Enumerable.Zip<TFirst, TSecond>(this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second)System.MemoryExtensions.AsSpan(this System.String? text, System.Int32 start, System.Int32 length)System.MemoryExtensions.CommonPrefixLength(this System.ReadOnlySpan span, System.ReadOnlySpan other)System.MemoryExtensions.CommonPrefixLength(this System.ReadOnlySpan span, System.ReadOnlySpan other, System.Collections.Generic.IEqualityComparer? comparer)System.MemoryExtensions.CommonPrefixLength(this System.Span span, System.ReadOnlySpan other)System.MemoryExtensions.CommonPrefixLength(this System.Span span, System.ReadOnlySpan other, System.Collections.Generic.IEqualityComparer? comparer)System.MemoryExtensions.ContainsAnyExcept(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable?System.MemoryExtensions.ContainsAnyExcept(this System.ReadOnlySpan span, T value) where T : System.IEquatable?System.MemoryExtensions.ContainsAnyExcept(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable?System.MemoryExtensions.ContainsAnyExcept(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable?System.MemoryExtensions.ContainsAnyExcept(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable?System.MemoryExtensions.ContainsAnyExcept(this System.Span span, T value) where T : System.IEquatable?System.MemoryExtensions.ContainsAnyExcept(this System.Span span, T value0, T value1) where T : System.IEquatable?System.MemoryExtensions.ContainsAnyExcept(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable?System.MemoryExtensions.ContainsAny(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable?System.MemoryExtensions.ContainsAny(this System.Span span, T value0, T value1) where T : System.IEquatable?System.MemoryExtensions.ContainsAny(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable?System.MemoryExtensions.Contains(this System.ReadOnlySpan span, T value) where T : System.IEquatable?System.MemoryExtensions.Contains(this System.Span span, T value) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.ReadOnlySpan span, System.ReadOnlySpan values) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.ReadOnlySpan span, T value) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.ReadOnlySpan span, T value0, T value1, T value2) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.Span span, System.ReadOnlySpan values) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.Span span, T value) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.Span span, T value0, T value1) where T : System.IEquatable?System.MemoryExtensions.IndexOfAnyExcept(this System.Span span, T value0, T value1, T value2) where T : System.IEquatable?System.Net.Http.HttpContent.CopyTo(System.IO.Stream stream, System.Net.TransportContext? context, System.Threading.CancellationToken cancellationToken)System.Net.Http.HttpContent.CopyToAsync(System.IO.Stream stream)System.Net.Http.HttpContent.CopyToAsync(System.IO.Stream stream, System.Net.TransportContext? context)System.Net.Http.HttpContent.CopyToAsync(System.IO.Stream stream, System.Net.TransportContext? context, System.Threading.CancellationToken cancellationToken)System.Net.Http.HttpContent.CopyToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken)System.Net.Http.HttpContent.ReadAsStream(System.Threading.CancellationToken cancellationToken)System.Net.Http.HttpContent.ReadAsStream()System.Net.Sockets.UdpClient.Send(System.ReadOnlySpan<System.Byte> datagram, System.Net.IPEndPoint? endPoint)System.Net.Sockets.UdpClient.Send(System.ReadOnlySpan<System.Byte> datagram, System.String? hostname, System.Int32 port)System.String.Contains(System.Char value)System.String.Contains(System.Char value, System.StringComparison comparisonType)System.String.Contains(System.String value, System.StringComparison comparisonType)System.String.CopyTo(System.Span<System.Char> destination)System.String.EndsWith(System.Char value)System.String.GetHashCode(System.StringComparison comparisonType)System.String.IndexOf(System.Char value, System.StringComparison comparisonType)System.String.Replace(System.String oldValue, System.String? newValue, System.StringComparison comparisonType)System.String.ReplaceLineEndings(System.String replacementText)System.String.ReplaceLineEndings()System.String.Split(System.Char separator, System.Int32 count, [System.StringSplitOptions options = System.StringSplitOptions.None])System.String.Split(System.Char separator, [System.StringSplitOptions options = System.StringSplitOptions.None])System.String.StartsWith(System.Char value)System.String.TryCopyTo(System.Span<System.Char> destination)System.Text.Encoding.GetString(System.ReadOnlySpan<System.Byte> bytes)System.Text.StringBuilder.Append(System.ReadOnlyMemory<System.Char> value)System.Text.StringBuilder.Append(System.ReadOnlySpan<System.Char> value)System.Text.StringBuilder.AppendJoin(System.Char separator, params System.Object?[] values)System.Text.StringBuilder.AppendJoin(System.Char separator, params System.String?[] values)System.Text.StringBuilder.AppendJoin(System.String? separator, params System.Object?[] values)System.Text.StringBuilder.AppendJoin(System.String? separator, params System.String?[] values)System.Text.StringBuilder.AppendJoin(System.Char separator, System.Collections.Generic.IEnumerable values)System.Text.StringBuilder.AppendJoin(System.String? separator, System.Collections.Generic.IEnumerable values)System.Text.StringBuilder.Replace(System.ReadOnlySpan<System.Char> oldValue, System.ReadOnlySpan<System.Char> newValue)System.Text.StringBuilder.Replace(System.ReadOnlySpan<System.Char> oldValue, System.ReadOnlySpan<System.Char> newValue, System.Int32 startIndex, System.Int32 count)System.Threading.CancellationTokenSource.CancelAsync()System.Threading.Tasks.Task.WaitAsync(System.Threading.CancellationToken cancellationToken)System.Type.IsAssignableTo(System.Type? targetType)
Contribution
How to add a new polyfill
- Create a new file named
.csin the projectMeziantou.Polyfill.Editor - Run
Meziantou.Polyfill.Generator
Notes:
- All files must be self contained. Use a
file classif needed. - If you need to generate a file only when another polyfill is generated, add
// whenin the file
Changes from Previous Version
No structural changes between v1.0.36 and v1.0.37.
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Compatibility metadata lists 1 target framework; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.