diff --git a/PolyShim/Net50/IntPtr.cs b/PolyShim/Net50/IntPtr.cs new file mode 100644 index 0000000..5f29150 --- /dev/null +++ b/PolyShim/Net50/IntPtr.cs @@ -0,0 +1,49 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; +using System.Globalization; + +internal static partial class PolyfillExtensions2 +{ + extension(IntPtr) + { + // https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string-system-globalization-numberstyles-system-iformatprovider) + public static IntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => + new(IntPtr.Size == 4 ? int.Parse(s, style, provider) : long.Parse(s, style, provider)); + + // https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string-system-iformatprovider) + public static IntPtr Parse(string s, IFormatProvider? provider) => + new(IntPtr.Size == 4 ? int.Parse(s, provider) : long.Parse(s, provider)); + + // https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string-system-globalization-numberstyles) + public static IntPtr Parse(string s, NumberStyles style) => + new(IntPtr.Size == 4 ? int.Parse(s, style) : long.Parse(s, style)); + + // https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string) + public static IntPtr Parse(string s) => + new(IntPtr.Size == 4 ? int.Parse(s) : long.Parse(s)); + + // https://learn.microsoft.com/dotnet/api/system.intptr.tryparse#system-intptr-tryparse(system-string-system-intptr@) + public static bool TryParse(string? s, out IntPtr result) + { + if (IntPtr.Size == 4) + { + var success = int.TryParse(s, out var intResult); + result = new IntPtr(intResult); + return success; + } + else + { + var success = long.TryParse(s, out var longResult); + result = new IntPtr(longResult); + return success; + } + } + } +} +#endif diff --git a/PolyShim/Net50/UIntPtr.cs b/PolyShim/Net50/UIntPtr.cs new file mode 100644 index 0000000..f48b034 --- /dev/null +++ b/PolyShim/Net50/UIntPtr.cs @@ -0,0 +1,51 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; +using System.Globalization; + +internal static partial class PolyfillExtensions3 +{ + extension(UIntPtr) + { + // https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string-system-globalization-numberstyles-system-iformatprovider) + public static UIntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => + new( + UIntPtr.Size == 4 ? uint.Parse(s, style, provider) : ulong.Parse(s, style, provider) + ); + + // https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string-system-iformatprovider) + public static UIntPtr Parse(string s, IFormatProvider? provider) => + new(UIntPtr.Size == 4 ? uint.Parse(s, provider) : ulong.Parse(s, provider)); + + // https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string-system-globalization-numberstyles) + public static UIntPtr Parse(string s, NumberStyles style) => + new(UIntPtr.Size == 4 ? uint.Parse(s, style) : ulong.Parse(s, style)); + + // https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string) + public static UIntPtr Parse(string s) => + new(UIntPtr.Size == 4 ? uint.Parse(s) : ulong.Parse(s)); + + // https://learn.microsoft.com/dotnet/api/system.uintptr.tryparse#system-uintptr-tryparse(system-string-system-uintptr@) + public static bool TryParse(string? s, out UIntPtr result) + { + if (UIntPtr.Size == 4) + { + var success = uint.TryParse(s, out var intResult); + result = new UIntPtr(intResult); + return success; + } + else + { + var success = ulong.TryParse(s, out var longResult); + result = new UIntPtr(longResult); + return success; + } + } + } +} +#endif diff --git a/PolyShim/Signatures.md b/PolyShim/Signatures.md index dfb0b97..d0be211 100644 --- a/PolyShim/Signatures.md +++ b/PolyShim/Signatures.md @@ -1,8 +1,8 @@ # Signatures -- **Total:** 320 +- **Total:** 330 - **Types:** 71 -- **Members:** 249 +- **Members:** 259 ___ @@ -169,6 +169,11 @@ ___ - [`bool TryParse(string, IFormatProvider?, out int)`](https://learn.microsoft.com/dotnet/api/system.int32.tryparse#system-int32-tryparse(system-string-system-iformatprovider-system-int32@)) .NET 7.0 - `IntPtr` - [`bool TryParse(string, IFormatProvider?, out IntPtr)`](https://learn.microsoft.com/dotnet/api/system.intptr.tryparse#system-intptr-tryparse(system-string-system-iformatprovider-system-intptr@)) .NET 7.0 + - [`bool TryParse(string?, out IntPtr)`](https://learn.microsoft.com/dotnet/api/system.intptr.tryparse#system-intptr-tryparse(system-string-system-intptr@)) .NET 5.0 + - [`IntPtr Parse(string, IFormatProvider?)`](https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string-system-iformatprovider)) .NET 5.0 + - [`IntPtr Parse(string, NumberStyles, IFormatProvider?)`](https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string-system-globalization-numberstyles-system-iformatprovider)) .NET 5.0 + - [`IntPtr Parse(string, NumberStyles)`](https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string-system-globalization-numberstyles)) .NET 5.0 + - [`IntPtr Parse(string)`](https://learn.microsoft.com/dotnet/api/system.intptr.parse#system-intptr-parse(system-string)) .NET 5.0 - `IReadOnlyDictionary` - [`TValue? GetValueOrDefault(TKey, TValue?)`](https://learn.microsoft.com/dotnet/api/system.collections.generic.collectionextensions.getvalueordefault#system-collections-generic-collectionextensions-getvalueordefault-2(system-collections-generic-ireadonlydictionary((-0-1))-0-1)) .NET Core 2.0 - [`TValue? GetValueOrDefault(TKey)`](https://learn.microsoft.com/dotnet/api/system.collections.generic.collectionextensions.getvalueordefault#system-collections-generic-collectionextensions-getvalueordefault-2(system-collections-generic-ireadonlydictionary((-0-1))-0)) .NET Core 2.0 @@ -419,6 +424,11 @@ ___ - [`bool TryParse(string, IFormatProvider?, out uint)`](https://learn.microsoft.com/dotnet/api/system.uint32.tryparse#system-uint32-tryparse(system-string-system-iformatprovider-system-uint32@)) .NET 7.0 - `UIntPtr` - [`bool TryParse(string, IFormatProvider?, out UIntPtr)`](https://learn.microsoft.com/dotnet/api/system.uintptr.tryparse#system-uintptr-tryparse(system-string-system-iformatprovider-system-uintptr@)) .NET 7.0 + - [`bool TryParse(string?, out UIntPtr)`](https://learn.microsoft.com/dotnet/api/system.uintptr.tryparse#system-uintptr-tryparse(system-string-system-uintptr@)) .NET 5.0 + - [`UIntPtr Parse(string, IFormatProvider?)`](https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string-system-iformatprovider)) .NET 5.0 + - [`UIntPtr Parse(string, NumberStyles, IFormatProvider?)`](https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string-system-globalization-numberstyles-system-iformatprovider)) .NET 5.0 + - [`UIntPtr Parse(string, NumberStyles)`](https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string-system-globalization-numberstyles)) .NET 5.0 + - [`UIntPtr Parse(string)`](https://learn.microsoft.com/dotnet/api/system.uintptr.parse#system-uintptr-parse(system-string)) .NET 5.0 - `ulong` - [`bool TryParse(string, IFormatProvider?, out ulong)`](https://learn.microsoft.com/dotnet/api/system.uint64.tryparse#system-uint64-tryparse(system-string-system-iformatprovider-system-uint64@)) .NET 7.0 - `UnconditionalSuppressMessageAttribute`