-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListAccessor.cs
More file actions
33 lines (29 loc) · 1.28 KB
/
ListAccessor.cs
File metadata and controls
33 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
namespace Ramstack.Internal;
#if NET9_0_OR_GREATER
/// <summary>
/// Provides low-level access to the internal array buffer of a <see cref="List{T}"/>.
/// </summary>
/// <typeparam name="T">The type of the elements in the list.</typeparam>
internal static class ListAccessor<T>
{
/// <summary>
/// Returns a reference to the internal array buffer of the specified <see cref="List{T}"/>.
/// </summary>
/// <param name="list">The list whose internal buffer is to be accessed.</param>
/// <returns>
/// A reference to the internal array used by the list.
/// </returns>
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_items")]
public static extern ref T[] GetArray(List<T> list);
/// <summary>
/// Returns a reference to the internal "_size" field of the specified <see cref="List{T}"/>
/// representing the number of elements in the list.
/// </summary>
/// <param name="list">The list whose internal "_size" field is to be accessed.</param>
/// <returns>
/// A reference to the internal "_size" field representing the number of elements in the list.
/// </returns>
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_size")]
public static extern ref int GetCount(List<T> list);
}
#endif