Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meziantou/Meziantou.Polyfill
https://github.com/meziantou/Meziantou.Polyfill
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/meziantou/Meziantou.Polyfill
- Owner: meziantou
- License: mit
- Created: 2023-06-07T03:14:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-09T02:05:22.000Z (2 months ago)
- Last Synced: 2024-10-09T02:35:53.575Z (2 months ago)
- Language: C#
- Size: 408 KB
- Stars: 41
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
- RSCG_Examples - https://github.com/meziantou/Meziantou.Polyfill
README
# Meziantou.Polyfill
[![NuGet](https://img.shields.io/nuget/v/Meziantou.Polyfill.svg)](https://www.nuget.org/packages/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](https://www.meziantou.net/polyfills-in-dotnet-to-ease-multi-targeting.htm)
## Installation
````bash
dotnet add package Meziantou.Polyfill
````Then, you should see the generated types in the solution explorer
![Generated files in the Visual Studio's Solution Explorer](docs/solutionexplorer-polyfill.png)
## 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:
````xml
T:Type1|T:Type2|M:Member1
M:System.Diagnostics.
True
$(BaseIntermediateOutputPath)\GeneratedFiles````
## Supported polyfills
### Types
- `System.Collections.Generic.PriorityQueue`
- `System.Collections.Generic.ReferenceEqualityComparer`
- `System.Diagnostics.CodeAnalysis.AllowNullAttribute`
- `System.Diagnostics.CodeAnalysis.DisallowNullAttribute`
- `System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute`
- `System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute`
- `System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute`
- `System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes`
- `System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute`
- `System.Diagnostics.CodeAnalysis.ExperimentalAttribute`
- `System.Diagnostics.CodeAnalysis.MaybeNullAttribute`
- `System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute`
- `System.Diagnostics.CodeAnalysis.MemberNotNullAttribute`
- `System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute`
- `System.Diagnostics.CodeAnalysis.NotNullAttribute`
- `System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute`
- `System.Diagnostics.CodeAnalysis.NotNullWhenAttribute`
- `System.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute`
- `System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute`
- `System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute`
- `System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute`
- `System.Diagnostics.CodeAnalysis.StringSyntaxAttribute`
- `System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute`
- `System.Diagnostics.CodeAnalysis.UnscopedRefAttribute`
- `System.Diagnostics.StackTraceHiddenAttribute`
- `System.HashCode`
- `System.Index`
- `System.Net.Http.ReadOnlyMemoryContent`
- `System.Range`
- `System.Runtime.CompilerServices.AsyncMethodBuilderAttribute`
- `System.Runtime.CompilerServices.CallerArgumentExpressionAttribute`
- `System.Runtime.CompilerServices.CollectionBuilderAttribute`
- `System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute`
- `System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute`
- `System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute`
- `System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute`
- `System.Runtime.CompilerServices.IsExternalInit`
- `System.Runtime.CompilerServices.ModuleInitializerAttribute`
- `System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute`
- `System.Runtime.CompilerServices.RequiredMemberAttribute`
- `System.Runtime.CompilerServices.SkipLocalsInitAttribute`
- `System.Runtime.CompilerServices.TupleElementNamesAttribute`
- `System.Runtime.InteropServices.SuppressGCTransitionAttribute`
- `System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute`
- `System.Runtime.Versioning.ObsoletedOSPlatformAttribute`
- `System.Runtime.Versioning.RequiresPreviewFeaturesAttribute`
- `System.Runtime.Versioning.SupportedOSPlatformAttribute`
- `System.Runtime.Versioning.SupportedOSPlatformGuardAttribute`
- `System.Runtime.Versioning.TargetPlatformAttribute`
- `System.Runtime.Versioning.UnsupportedOSPlatformAttribute`
- `System.Runtime.Versioning.UnsupportedOSPlatformGuardAttribute`
- `System.Threading.Tasks.TaskToAsyncResult`
- `System.ValueTuple`
- `System.ValueTuple`
- `System.ValueTuple`
- `System.ValueTuple`
- `System.ValueTuple`
- `System.ValueTuple`
- `System.ValueTuple`
- `System.ValueTuple`
- `System.ValueTuple where TRest : struct`
- `System.ITupleInternal`### Methods
- `System.Collections.Concurrent.ConcurrentDictionary.GetOrAdd(TKey key, System.Func valueFactory, TArg factoryArgument) where TArg : allows ref struct`
- `System.Collections.Generic.CollectionExtensions.GetValueOrDefault(this System.Collections.Generic.IReadOnlyDictionary dictionary, TKey key)`
- `System.Collections.Generic.CollectionExtensions.GetValueOrDefault(this System.Collections.Generic.IReadOnlyDictionary dictionary, TKey key, TValue defaultValue)`
- `System.Collections.Generic.KeyValuePair.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 buffer)`
- `System.IO.Stream.ReadAsync(System.Memory buffer, [System.Threading.CancellationToken cancellationToken = default])`
- `System.IO.Stream.ReadAtLeast(System.Span buffer, System.Int32 minimumBytes, [System.Boolean throwOnEndOfStream = true])`
- `System.IO.Stream.ReadAtLeastAsync(System.Memory buffer, System.Int32 minimumBytes, [System.Boolean throwOnEndOfStream = true], [System.Threading.CancellationToken cancellationToken = default])`
- `System.IO.Stream.Write(System.ReadOnlySpan buffer)`
- `System.IO.Stream.WriteAsync(System.ReadOnlyMemory buffer, [System.Threading.CancellationToken cancellationToken = default])`
- `System.IO.StreamReader.ReadLineAsync()`
- `System.IO.StreamReader.ReadLineAsync(System.Threading.CancellationToken cancellationToken)`
- `System.IO.TextReader.ReadAsync(System.Memory buffer, [System.Threading.CancellationToken cancellationToken = default])`
- `System.IO.TextReader.ReadToEndAsync(System.Threading.CancellationToken cancellationToken)`
- `System.IO.TextWriter.WriteAsync(System.ReadOnlyMemory buffer, [System.Threading.CancellationToken cancellationToken = default])`
- `System.Linq.Enumerable.AggregateBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector, System.Func seedSelector, System.Func func, [System.Collections.Generic.IEqualityComparer? keyComparer = null]) where TKey : notnull`
- `System.Linq.Enumerable.AggregateBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector, TAccumulate seed, System.Func func, [System.Collections.Generic.IEqualityComparer? keyComparer = null]) where TKey : notnull`
- `System.Linq.Enumerable.CountBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector, [System.Collections.Generic.IEqualityComparer? keyComparer = null]) where TKey : notnull`
- `System.Linq.Enumerable.DistinctBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector)`
- `System.Linq.Enumerable.DistinctBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector, System.Collections.Generic.IEqualityComparer? comparer)`
- `System.Linq.Enumerable.Index(this System.Collections.Generic.IEnumerable source)`
- `System.Linq.Enumerable.MaxBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector)`
- `System.Linq.Enumerable.MaxBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector, System.Collections.Generic.IComparer? comparer)`
- `System.Linq.Enumerable.MinBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector)`
- `System.Linq.Enumerable.MinBy(this System.Collections.Generic.IEnumerable source, System.Func 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(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 datagram, System.Net.IPEndPoint? endPoint)`
- `System.Net.Sockets.UdpClient.Send(System.ReadOnlySpan datagram, System.String? hostname, System.Int32 port)`
- `System.Net.Sockets.UdpClient.SendAsync(System.ReadOnlyMemory datagram, System.Net.IPEndPoint? endPoint, [System.Threading.CancellationToken cancellationToken = default])`
- `System.Net.Sockets.UdpClient.SendAsync(System.ReadOnlyMemory datagram, System.String? hostname, System.Int32 port, [System.Threading.CancellationToken cancellationToken = default])`
- `System.Net.Sockets.UdpClient.SendAsync(System.ReadOnlyMemory datagram, [System.Threading.CancellationToken cancellationToken = default])`
- `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 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 destination)`
- `System.Text.Encoding.GetString(System.ReadOnlySpan bytes)`
- `System.Text.StringBuilder.Append(System.ReadOnlyMemory value)`
- `System.Text.StringBuilder.Append(System.ReadOnlySpan 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 oldValue, System.ReadOnlySpan newValue)`
- `System.Text.StringBuilder.Replace(System.ReadOnlySpan oldValue, System.ReadOnlySpan newValue, System.Int32 startIndex, System.Int32 count)`
- `System.Threading.CancellationTokenSource.CancelAsync()`
- `System.Threading.Tasks.Task.WaitAsync(System.Threading.CancellationToken cancellationToken)`
- `System.Threading.Tasks.TaskAsyncEnumerableExtensions.ToBlockingEnumerable(this System.Collections.Generic.IAsyncEnumerable source, [System.Threading.CancellationToken cancellationToken = default])`
- `System.Type.IsAssignableTo(System.Type? targetType)`## Contribution
#### How to add a new polyfill
- Create a new file named `.cs` in the project `Meziantou.Polyfill.Editor`
- Run `Meziantou.Polyfill.Generator`Notes:
- All files must be self contained. Use a `file class` if needed.
- If you need to generate a file only when another polyfill is generated, add `// when ` in the file