-
-
Notifications
You must be signed in to change notification settings - Fork 3
Add things from PolyCore #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Windows10CE
wants to merge
14
commits into
MonoMod:master
Choose a base branch
from
Windows10CE:missing-from-polycore
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6d4e71b
{,ReadOnly}SpanAction<T, in TArg>
Windows10CE 5943dc5
char.IsBetween and char.IsAsciiX
Windows10CE 7dcbf41
CollectionsMarshal
Windows10CE fbb7902
Remove GetValueRef methods
Windows10CE 032569f
CollectionsExtensions.{AddRange,InsertRange,CopyTo,AsReadOnly}
Windows10CE 24e3d41
ISpanFormattable
Windows10CE a7b4e54
Enumerable.Reverse(TSource[])
Windows10CE 8e1ceb9
RuntimeHelpers.{IsReferenceOrContainsReferences,GetUninitializedObjec…
Windows10CE 7252c9d
Marshal.InitHandle
Windows10CE 2252c45
Index, Range, RuntimeHelpers.GetSubArray
Windows10CE c4aa7c6
Fix Marshal.InitHandle
Windows10CE d2d3823
Fix warnings and errors
Windows10CE aa8628f
MemoryMarshal.{GetArrayDataReference,CreateReadOnlySpanFromNullTermin…
Windows10CE 54a39be
string.{Create,CopyTo,TryCopyTo,ReplaceLineEndings,Concat}
Windows10CE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
src/MonoMod.Backports/System/Buffers,is_fx,lt_core_2.1,lt_std_2.1/SpanActions.cs
This file contains hidden or 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,5 @@ | ||
| namespace System.Buffers | ||
| { | ||
| public delegate void SpanAction<T, in TArg>(Span<T> span, TArg arg); | ||
| public delegate void ReadOnlySpanAction<T, in TArg>(ReadOnlySpan<T> span, TArg arg); | ||
| } |
This file contains hidden or 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,91 @@ | ||
| namespace System | ||
| { | ||
| public static class CharEx | ||
| { | ||
| // there is no real reason to forward these, they are all very simple | ||
| extension(char) | ||
| { | ||
| /// <summary>Indicates whether a character is categorized as an ASCII letter.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is an ASCII letter; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range 'A' through 'Z', inclusive, | ||
| /// or 'a' through 'z', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiLetter(char c) => (uint)((c | 0x20) - 'a') <= 'z' - 'a'; | ||
|
|
||
| /// <summary>Indicates whether a character is categorized as a lowercase ASCII letter.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is a lowercase ASCII letter; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range 'a' through 'z', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiLetterLower(char c) => IsBetween(c, 'a', 'z'); | ||
|
|
||
| /// <summary>Indicates whether a character is categorized as an uppercase ASCII letter.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is an uppercase ASCII letter; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range 'A' through 'Z', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiLetterUpper(char c) => IsBetween(c, 'A', 'Z'); | ||
|
|
||
| /// <summary>Indicates whether a character is categorized as an ASCII digit.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is an ASCII digit; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range '0' through '9', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiDigit(char c) => IsBetween(c, '0', '9'); | ||
|
|
||
| /// <summary>Indicates whether a character is categorized as an ASCII letter or digit.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is an ASCII letter or digit; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range 'A' through 'Z', inclusive, | ||
| /// 'a' through 'z', inclusive, or '0' through '9', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiLetterOrDigit(char c) => IsAsciiLetter(c) | IsBetween(c, '0', '9'); | ||
|
|
||
| /// <summary>Indicates whether a character is categorized as an ASCII hexadecimal digit.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is a hexadecimal digit; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range '0' through '9', inclusive, | ||
| /// 'A' through 'F', inclusive, or 'a' through 'f', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiHexDigit(char c) => IsAsciiDigit(c) || IsBetween(c, 'a', 'f') || IsBetween(c, 'A', 'F'); | ||
|
|
||
| /// <summary>Indicates whether a character is categorized as an ASCII upper-case hexadecimal digit.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is a hexadecimal digit; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range '0' through '9', inclusive, | ||
| /// or 'A' through 'F', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiHexDigitUpper(char c) => IsAsciiDigit(c) || IsBetween(c, 'A', 'F'); | ||
|
|
||
| /// <summary>Indicates whether a character is categorized as an ASCII lower-case hexadecimal digit.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <returns>true if <paramref name="c"/> is a lower-case hexadecimal digit; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// This determines whether the character is in the range '0' through '9', inclusive, | ||
| /// or 'a' through 'f', inclusive. | ||
| /// </remarks> | ||
| public static bool IsAsciiHexDigitLower(char c) => IsAsciiDigit(c) || IsBetween(c, 'a', 'f'); | ||
|
|
||
| /// <summary>Indicates whether a character is within the specified inclusive range.</summary> | ||
| /// <param name="c">The character to evaluate.</param> | ||
| /// <param name="minInclusive">The lower bound, inclusive.</param> | ||
| /// <param name="maxInclusive">The upper bound, inclusive.</param> | ||
| /// <returns>true if <paramref name="c"/> is within the specified range; otherwise, false.</returns> | ||
| /// <remarks> | ||
| /// The method does not validate that <paramref name="maxInclusive"/> is greater than or equal | ||
| /// to <paramref name="minInclusive"/>. If <paramref name="maxInclusive"/> is less than | ||
| /// <paramref name="minInclusive"/>, the behavior is undefined. | ||
| /// </remarks> | ||
| public static bool IsBetween(char c, char minInclusive, char maxInclusive) => | ||
| (uint)(c - minInclusive) <= (uint)(maxInclusive - minInclusive); | ||
| } | ||
| } | ||
| } |
100 changes: 100 additions & 0 deletions
100
src/MonoMod.Backports/System/Collections/Generic/CollectionExtensionsEx.cs
This file contains hidden or 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,100 @@ | ||
| #if NET8_0_OR_GREATER | ||
| #define HAS_LISTSPANMETHODS | ||
| #endif | ||
| #if NET7_0_OR_GREATER | ||
| #define HAS_ASREADONLY | ||
| #endif | ||
|
|
||
| using System.Collections.ObjectModel; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| #if !HAS_LISTSPANMETHODS | ||
| using System.Runtime.InteropServices; | ||
| #endif | ||
|
|
||
| namespace System.Collections.Generic | ||
| { | ||
| [SuppressMessage("Design", "CA1002:Do not expose generic lists", | ||
| Justification = "Replicating existing APIs")] | ||
| public static class CollectionExtensionsEx | ||
| { | ||
| public static void AddRange<T>( | ||
| #if !HAS_LISTSPANMETHODS | ||
| this | ||
| #endif | ||
| List<T> list, params ReadOnlySpan<T> source | ||
| ) | ||
| { | ||
| #if HAS_LISTSPANMETHODS | ||
| list.AddRange(source); | ||
| #else | ||
| ThrowHelper.ThrowIfArgumentNull(list, ExceptionArgument.list); | ||
| if (source.IsEmpty) | ||
| { | ||
| return; | ||
| } | ||
| var currentCount = list.Count; | ||
| CollectionsMarshal.SetCount(list, currentCount + source.Length); | ||
| source.CopyTo(CollectionsMarshal.AsSpan(list).Slice(currentCount + 1)); | ||
| #endif | ||
| } | ||
|
|
||
| public static void InsertRange<T>( | ||
| #if !HAS_LISTSPANMETHODS | ||
| this | ||
| #endif | ||
| List<T> list, int index, params ReadOnlySpan<T> source | ||
| ) | ||
| { | ||
| #if HAS_LISTSPANMETHODS | ||
| list.InsertRange(index, source); | ||
| #else | ||
| ThrowHelper.ThrowIfArgumentNull(list, ExceptionArgument.list); | ||
| if ((uint)index > (uint)list.Count) | ||
| { | ||
| ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); | ||
| } | ||
| if (source.IsEmpty) | ||
| { | ||
| return; | ||
| } | ||
| var currentCount = list.Count; | ||
| CollectionsMarshal.SetCount(list, currentCount + source.Length); | ||
| var items = CollectionsMarshal.AsSpan(list); | ||
| if (index < currentCount) | ||
| { | ||
| items.Slice(index, currentCount - index).CopyTo(items.Slice(index + source.Length)); | ||
| } | ||
| source.CopyTo(items.Slice(index)); | ||
| #endif | ||
| } | ||
|
|
||
| public static void CopyTo<T>( | ||
| #if !HAS_LISTSPANMETHODS | ||
| this | ||
| #endif | ||
| List<T> list, Span<T> destination | ||
| ) | ||
| { | ||
| #if HAS_LISTSPANMETHODS | ||
| list.CopyTo(destination); | ||
| #else | ||
| ThrowHelper.ThrowIfArgumentNull(list, ExceptionArgument.list); | ||
| CollectionsMarshal.AsSpan(list).CopyTo(destination); | ||
| #endif | ||
| } | ||
|
|
||
| public static ReadOnlyCollection<T> AsReadOnly<T>( | ||
| #if !HAS_ASREADONLY | ||
| this | ||
| #endif | ||
| IList<T> list | ||
| ) => new(list); | ||
|
|
||
| public static ReadOnlyDictionary<TKey, TValue> AsReadOnly<TKey, TValue>( | ||
| #if !HAS_ASREADONLY | ||
| this | ||
| #endif | ||
| IDictionary<TKey, TValue> list | ||
| ) where TKey : notnull => new(list); | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
....Backports/System/Collections/ObjectModel/ReadOnlyDictionary,gte_fx_4.5,is_core,is_std.cs
This file contains hidden or 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,4 @@ | ||
| using System.Collections.ObjectModel; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: TypeForwardedTo(typeof(ReadOnlyDictionary<,>))] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these actually part of the OOB package? I didn't think they were.