Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions src/Polyfill/OperatingSystemPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Polyfills;

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

Expand Down Expand Up @@ -86,6 +87,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
/// Indicates whether the current application is running on the specified platform.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isosplatform?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsOSPlatform(string platform) =>
RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform));

Expand Down
4 changes: 4 additions & 0 deletions src/Split/net10.0/ConsolePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Polyfills;
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32.SafeHandles;
static partial class Polyfill
{
Expand All @@ -12,16 +13,19 @@ static partial class Polyfill
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard input.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardInputHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput);
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard output.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardOutputHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput);
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard error.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardErrorHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Split/net11.0/ConsolePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Polyfills;
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32.SafeHandles;
static partial class Polyfill
{
Expand All @@ -12,16 +13,19 @@ static partial class Polyfill
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard input.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardInputHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput);
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard output.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardOutputHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput);
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard error.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardErrorHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Split/net461/ConsolePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Polyfills;
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32.SafeHandles;
static partial class Polyfill
{
Expand All @@ -12,16 +13,19 @@ static partial class Polyfill
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard input.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardInputHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput);
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard output.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardOutputHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput);
/// <summary>
/// Gets a <see cref="SafeFileHandle"/> that wraps the operating system handle for standard error.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SafeFileHandle OpenStandardErrorHandle() =>
StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Split/net461/ConvertPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma warning disable
namespace Polyfills;
using System;
using System.Runtime.CompilerServices;
static partial class Polyfill
{
extension(Convert)
Expand All @@ -10,22 +11,26 @@ static partial class Polyfill
/// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters.
/// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexString(byte[] inArray, int offset, int length) =>
ToHexString(inArray, offset, length, "X2");
/// <summary>
/// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters.
/// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexStringLower(byte[] inArray, int offset, int length) =>
ToHexString(inArray, offset, length, "x2");
/// <summary>
/// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexStringLower(byte[] inArray) =>
Polyfill.ToHexStringLower(inArray, 0, inArray.Length);
/// <summary>
/// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexString(byte[] inArray) =>
Polyfill.ToHexString(inArray, 0, inArray.Length);
/// <summary>
Expand Down Expand Up @@ -54,16 +59,19 @@ static int GetHexValue(char hex) =>
/// <summary>
/// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte[] FromHexString(ReadOnlySpan<char> chars) =>
Polyfill.FromHexString(chars.ToString());
/// <summary>
/// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexString(ReadOnlySpan<byte> bytes) =>
Polyfill.ToHexString(bytes.ToArray());
/// <summary>
/// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexStringLower(ReadOnlySpan<byte> bytes) =>
Polyfill.ToHexStringLower(bytes.ToArray());
/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Split/net461/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Polyfills;
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
static partial class Polyfill
{
extension(DateTimeOffset target)
Expand All @@ -30,32 +31,38 @@ long TicksComponent()
/// <summary>
/// Tries to parse a string into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) =>
DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result);
#if FeatureMemory
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out DateTimeOffset result) =>
DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> input, out DateTimeOffset result) =>
DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) =>
DateTimeOffset.TryParse(s.ToString(), provider, styles, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParseExact(ReadOnlySpan<char> input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) =>
DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) =>
DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result);
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/Split/net461/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Polyfills;
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
static partial class Polyfill
{
extension(DateTime target)
Expand All @@ -29,32 +30,38 @@ long TicksComponent()
/// <summary>
/// Tries to parse a string into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) =>
DateTime.TryParse(s, provider, DateTimeStyles.None, out result);
#if FeatureMemory
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out DateTime result) =>
DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> s, out DateTime result) =>
DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) =>
DateTime.TryParse(s.ToString(), provider, styles, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParseExact(ReadOnlySpan<char> s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) =>
DateTime.TryParseExact(s.ToString(), format, provider, style, out result);
/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) =>
DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/Split/net461/DelegatePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Polyfills;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
static partial class Polyfill
{
/// <summary>
Expand Down Expand Up @@ -39,6 +40,7 @@ public bool MoveNext()
/// <summary>
/// Gets an enumerator for the invocation targets of this delegate.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static InvocationListEnumerator<TDelegate> EnumerateInvocationList<TDelegate>(TDelegate? target)
where TDelegate : Delegate =>
new(target);
Expand Down
4 changes: 4 additions & 0 deletions src/Split/net461/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory<char> contents
/// <summary>
/// Appends the specified string to the file, creating the file if it does not already exist.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AppendAllText(string path, ReadOnlySpan<char> contents) =>
File.AppendAllText(path, contents.ToString());
/// <summary>
/// Appends the specified string to the file, creating the file if it does not already exist.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AppendAllText(string path, ReadOnlySpan<char> contents, Encoding encoding) =>
File.AppendAllText(path, contents.ToString(), encoding);
/// <summary>
Expand All @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory<byte> by
/// Creates a new file, writes the specified string to the file, and then closes the file.
/// If the target file already exists, it is truncated and overwritten.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteAllText(string path, ReadOnlySpan<char> contents) =>
File.WriteAllText(path, contents.ToString());
/// <summary>
/// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file.
/// If the target file already exists, it is truncated and overwritten.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteAllText(string path, ReadOnlySpan<char> contents, Encoding encoding) =>
File.WriteAllText(path, contents.ToString(), encoding);
/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Split/net461/GuidPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ namespace Polyfills;
using System.Text;
using System;
using System.Security.Cryptography;
using System.Runtime.CompilerServices;
static partial class Polyfill
{
extension(Guid)
{
/// <summary>
/// Tries to parse a string into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) =>
Guid.TryParse(s, out result);
/// <summary>Creates a new <see cref="Guid" /> according to RFC 9562, following the Version 7 format.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow);
/// <summary>Creates a new <see cref="Guid" /> according to RFC 9562, following the Version 7 format.</summary>
public static Guid CreateVersion7(DateTimeOffset timestamp)
Expand All @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp)
/// <summary>
/// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, out Guid result) =>
Guid.TryParseExact(input.ToString(), format.ToString(), out result);
/// <summary>
/// Tries to parse a span of UTF-8 characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Guid result) =>
Guid.TryParse(s.ToString(), out result);
/// <summary>
/// Tries to parse a span of UTF-8 characters into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<char> input, out Guid result) =>
Guid.TryParse(input.ToString(), out result);
/// <summary>
/// Tries to parse a span of UTF-8 bytes into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryParse(ReadOnlySpan<byte> utf8Text, out Guid result) =>
Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result);
/// <summary>
/// Parse a span of UTF-8 bytes into a value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Guid Parse(ReadOnlySpan<byte> utf8Text) =>
Guid.Parse(Encoding.UTF8.GetString(utf8Text));
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/Split/net461/KeyValuePair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
#if PolyUseEmbeddedAttribute
Expand All @@ -17,6 +18,7 @@ static class KeyValuePair
/// <summary>
/// Creates a new key/value pair instance using provided values.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(TKey key, TValue value) =>
new(key, value);
}
Loading