This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f801662
commit 47ce583
Showing
4 changed files
with
83 additions
and
19 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Globalization; | ||
|
||
namespace System | ||
{ | ||
public static partial class Int32Polyfill | ||
{ | ||
public static bool TryParse(ReadOnlySpan<char> s, out int value) | ||
{ | ||
#if NETCOREAPP2_1 | ||
return int.TryParse(s, out value); | ||
#else | ||
return int.TryParse(s.ToString(), out value); | ||
#endif | ||
} | ||
|
||
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out int value) | ||
{ | ||
#if NETCOREAPP2_1 | ||
return int.TryParse(s, style, provider, out value); | ||
#else | ||
return int.TryParse(s.ToString(), style, provider, out value); | ||
#endif | ||
} | ||
|
||
public static int Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider = null) | ||
{ | ||
#if NETCOREAPP2_1 | ||
return int.Parse(s, style, provider); | ||
#else | ||
return int.Parse(s.ToString(), style, provider); | ||
#endif | ||
} | ||
|
||
public static bool TryFormat(this int value, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider provider = null) | ||
{ | ||
#if NETCOREAPP2_1 | ||
return value.TryFormat(destination, out charsWritten, format, provider); | ||
#else | ||
var str = value.ToString(format.ToString(), provider); | ||
if (str.AsSpan().TryCopyTo(destination)) | ||
{ | ||
charsWritten = str.Length; | ||
return true; | ||
} | ||
charsWritten = 0; | ||
return false; | ||
#endif | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters