-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Poly fill Index and Range types (#104170)
* Polyfill Index and Range types * Address the feedback * Revert ComInterface source gen changes
- Loading branch information
Showing
8 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/libraries/Common/tests/System/Runtime/CompilerServices/RuntimeHelpers.cs
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,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
internal static class RuntimeHelpers | ||
{ | ||
/// <summary> | ||
/// Slices the specified array using the specified range. | ||
/// </summary> | ||
internal static T[] GetSubArray<T>(T[] array, Range range) | ||
{ | ||
if (array == null) | ||
{ | ||
throw new ArgumentNullException(nameof(array)); | ||
} | ||
|
||
(int offset, int length) = range.GetOffsetAndLength(array.Length); | ||
|
||
if (default(T) != null || typeof(T[]) == array.GetType()) | ||
{ | ||
// We know the type of the array to be exactly T[]. | ||
|
||
if (length == 0) | ||
{ | ||
return Array.Empty<T>(); | ||
} | ||
|
||
var dest = new T[length]; | ||
Array.Copy(array, offset, dest, 0, length); | ||
return dest; | ||
} | ||
else | ||
{ | ||
// The array is actually a U[] where U:T. | ||
var dest = (T[])Array.CreateInstance(array.GetType().GetElementType(), length); | ||
Array.Copy(array, offset, dest, 0, length); | ||
return dest; | ||
} | ||
} | ||
} | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
src/libraries/Microsoft.Bcl.Memory/ref/Microsoft.Bcl.Memory.Forwards.netstandard21.cs
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,5 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Index))] | ||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Range))] |
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
41 changes: 41 additions & 0 deletions
41
src/libraries/Microsoft.Bcl.Memory/ref/Microsoft.Bcl.Memory.netstandard20.cs
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,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// ------------------------------------------------------------------------------ | ||
// Changes to this file must follow the https://aka.ms/api-review process. | ||
// ------------------------------------------------------------------------------ | ||
|
||
namespace System | ||
{ | ||
public readonly partial struct Index : System.IEquatable<System.Index> | ||
{ | ||
private readonly int _dummyPrimitive; | ||
public Index(int value, bool fromEnd = false) { throw null; } | ||
public static System.Index End { get { throw null; } } | ||
public bool IsFromEnd { get { throw null; } } | ||
public static System.Index Start { get { throw null; } } | ||
public int Value { get { throw null; } } | ||
public bool Equals(System.Index other) { throw null; } | ||
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } | ||
public static System.Index FromEnd(int value) { throw null; } | ||
public static System.Index FromStart(int value) { throw null; } | ||
public override int GetHashCode() { throw null; } | ||
public int GetOffset(int length) { throw null; } | ||
public static implicit operator System.Index (int value) { throw null; } | ||
public override string ToString() { throw null; } | ||
} | ||
public readonly partial struct Range : System.IEquatable<System.Range> | ||
{ | ||
private readonly int _dummyPrimitive; | ||
public Range(System.Index start, System.Index end) { throw null; } | ||
public static System.Range All { get { throw null; } } | ||
public System.Index End { get { throw null; } } | ||
public System.Index Start { get { throw null; } } | ||
public static System.Range EndAt(System.Index end) { throw null; } | ||
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } | ||
public bool Equals(System.Range other) { throw null; } | ||
public override int GetHashCode() { throw null; } | ||
public (int Offset, int Length) GetOffsetAndLength(int length) { throw null; } | ||
public static System.Range StartAt(System.Index start) { throw null; } | ||
public override string ToString() { throw null; } | ||
} | ||
} |
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
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
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
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