-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CollectionMarshal.cs
94 lines (77 loc) · 3.44 KB
/
CollectionMarshal.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#region Using Directives
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.ComponentModel;
using System.Security.Permissions;
#endregion
#pragma warning disable IDE1006 // Naming Styles
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Attribute which tells the runtime not to worry about accessibility modifiers
/// and visibility of type members in the target assembly.
/// </summary>
[EditorBrowsable( EditorBrowsableState.Never )]
[AttributeUsage( AttributeTargets.Assembly, AllowMultiple = true )]
public class IgnoresAccessChecksToAttribute: Attribute
{
/// <summary>
/// Creates the IgnoreAccessChecksToAttribute with the specified target assembly name
/// </summary>
/// <param name="assemblyName">Name of the target assembly</param>
public IgnoresAccessChecksToAttribute( string assemblyName ) =>
AssemblyName = assemblyName;
/// <summary>
/// The name of the target assembly for which access checks are not performed at runtime.
/// </summary>
public string AssemblyName { get; protected set; }
};
}
namespace System.Runtime.InteropServices
{
/// <summary>
/// An unsafe class that provides a set of methods to access
/// the underlying data representations of collections.
/// </summary>
public static class CollectionMarshal
{
/// <summary>
/// Gets a Span<<typeparamref name="T"/>> view over the data in <paramref name="list"/>.
/// </summary>
/// <remarks>
/// <para><h3><b>Warning:</b> Read-only operation!</h3></para>
/// Items should not be added or removed from the List<<typeparamref name="T"/>> while the Span<<typeparamref name="T"/>> is in use.
/// </remarks>
/// <typeparam name="T">The type of items in <paramref name="list"/>.</typeparam>
/// <param name="list">List from which to create the Span<<typeparamref name="T"/>>.</param>
/// <returns>A Span<<typeparamref name="T"/>> instance over the List<<typeparamref name="T"/>>.</returns>
[MethodImpl( MethodImplOptions.ForwardRef )]
public static extern Span<T> AsSpan< T >( List<T> list );
//public static ref TValue GetValueRefOrNullRef<TKey, TValue>(
// Dictionary<TKey, TValue> dictionary, TKey key ) where TKey : notnull
// => ref dictionary.FindValue( key );
};
}
namespace System.Collections.Generic
{
/// <summary>
/// Defines extensions for System.Collections.Generic's List<T> collection
/// </summary>
[EditorBrowsable( EditorBrowsableState.Never )]
public static class __ListXTension
{
/// <summary>
/// Gets a Span<<typeparamref name="T"/>> view over the data in this List<<typeparamref name="T"/>> instance
/// </summary>
/// <remarks>
/// <para><h3><b>Warning:</b> Read-only operation!</h3></para>
/// Items should not be added or removed from the List<<typeparamref name="T"/>> while the Span<<typeparamref name="T"/>> is in use.
/// </remarks>
/// <typeparam name="T">The type of items in <paramref name="list"/></typeparam>
/// <param name="list">This List<<typeparamref name="T"/>> instance</param>
/// <returns>A Span<<typeparamref name="T"/>> instance over the List<<typeparamref name="T"/>>.</returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Span<T> AsSpan< T >( this List<T> list ) =>
Runtime.InteropServices.CollectionMarshal.AsSpan( list );
};
}