-
Notifications
You must be signed in to change notification settings - Fork 6
/
MiniBCL.cs
227 lines (192 loc) · 6.07 KB
/
MiniBCL.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
namespace System
{
using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
public class Object
{
// The layout of object is a contract with the compiler.
public IntPtr m_pEEType;
}
public struct Void { }
// The layout of primitive types is special cased because it would be recursive.
// These really don't need any fields to work.
public struct Boolean { }
public struct Char { }
public struct SByte { }
public struct Byte { }
public struct Int16 { }
public struct UInt16 { }
public struct Int32 { }
public struct UInt32 { }
public struct Int64 { }
public struct UInt64 { }
public struct UIntPtr { }
public struct Single { }
public struct Double { }
public unsafe struct IntPtr
{
private void* _value;
public IntPtr(void* value) { _value = value; }
[Intrinsic]
public static readonly IntPtr Zero;
}
public abstract class ValueType { }
public abstract class Enum : ValueType { }
public struct Nullable<T> where T : struct { }
public sealed class String
{
// The layout of the string type is a contract with the compiler.
public readonly int Length;
public char _firstChar;
public unsafe char this[int index]
{
[System.Runtime.CompilerServices.Intrinsic]
get
{
return Internal.Runtime.CompilerServices.Unsafe.Add(ref _firstChar, index);
}
}
}
public abstract class Array
{
#pragma warning disable CA1823, 169, 649 // private field '{blah}' is never used
private int _numComponents;
#pragma warning restore CA1823, 169, 649
public int Length
{
get
{
// NOTE: The compiler has assumptions about the implementation of this method.
// Changing the implementation here (or even deleting this) will NOT have the desired impact
return _numComponents;
}
}
}
public abstract class Delegate { }
public abstract class MulticastDelegate : Delegate { }
public struct RuntimeTypeHandle { }
public struct RuntimeMethodHandle { }
public struct RuntimeFieldHandle { }
public class Attribute { }
public enum AttributeTargets { }
public sealed class AttributeUsageAttribute : Attribute
{
public AttributeUsageAttribute(AttributeTargets validOn)
{
}
public bool AllowMultiple { get; set; }
public bool Inherited { get; set; }
}
internal readonly ref struct ByReference<T>
{
#pragma warning disable CA1823, 169 // private field '{blah}' is never used
private readonly IntPtr _value;
#pragma warning restore CA1823, 169
[Intrinsic]
public extern ByReference(ref T value);
public unsafe ref T Value
{
// Implemented as a JIT intrinsic - This default implementation is for
// completeness and to provide a concrete error if called via reflection
// or if the intrinsic is missed.
[Intrinsic]
get => ref Unsafe.As<byte, T>(ref *(byte*)null);
}
}
public readonly ref struct ReadOnlySpan<T>
{
internal readonly ByReference<T> _pointer;
private readonly int _length;
public ReadOnlySpan(T[] array)
{
if (array == null)
{
this = default;
return; // returns default
}
_pointer = new ByReference<T>(ref array[0]);
_length = array.Length;
}
public unsafe ReadOnlySpan(void* pointer, int length)
{
_pointer = new ByReference<T>(ref Unsafe.As<byte, T>(ref *(byte*)pointer));
_length = length;
}
public ref readonly T this[int index]
{
[Intrinsic]
get
{
//if ((uint)index >= (uint)_length)
// ThrowHelper.ThrowIndexOutOfRangeException();
return ref Unsafe.Add(ref _pointer.Value, index);
}
}
public static implicit operator ReadOnlySpan<T>(T[] array) => new ReadOnlySpan<T>(array);
}
}
namespace System.Runtime.CompilerServices
{
internal sealed class IntrinsicAttribute : Attribute { }
public class RuntimeHelpers
{
public static unsafe int OffsetToStringData => sizeof(IntPtr) + sizeof(int);
}
public enum MethodImplOptions
{
NoInlining = 0x0008,
InternalCall = 0x1000,
NoOptimization = 64,
}
public sealed class MethodImplAttribute : Attribute
{
public MethodImplAttribute(MethodImplOptions methodImplOptions) { }
}
}
namespace System.Runtime.InteropServices
{
public enum CharSet
{
None = 1,
Ansi = 2,
Unicode = 3,
Auto = 4,
}
public sealed class DllImportAttribute : Attribute
{
public string EntryPoint;
public CharSet CharSet;
public bool ExactSpelling;
public DllImportAttribute(string dllName) { }
}
public enum LayoutKind
{
Sequential = 0,
Explicit = 2,
Auto = 3,
}
public sealed class UnmanagedCallersOnlyAttribute : Attribute
{
public string EntryPoint;
public UnmanagedCallersOnlyAttribute() { }
}
public sealed class StructLayoutAttribute : Attribute
{
public StructLayoutAttribute(LayoutKind layoutKind) { }
}
public sealed class InAttribute : Attribute
{
}
}
namespace Internal.Runtime.CompilerServices
{
public static unsafe partial class Unsafe
{
// The body of this method is generated by the compiler.
// It will do what Unsafe.Add is expected to do. It's just not possible to express it in C#.
[System.Runtime.CompilerServices.Intrinsic]
public static extern ref T Add<T>(ref T source, int elementOffset);
[System.Runtime.CompilerServices.Intrinsic]
public static extern ref TTo As<TFrom, TTo>(ref TFrom source);
}
}