1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System.Runtime.Serialization;
6 using Internal.Runtime.CompilerServices;
8 namespace System.Runtime.CompilerServices
10 public static partial class RuntimeHelpers
12 public delegate void TryCode(object userData);
14 public delegate void CleanupCode(object userData, bool exceptionThrown);
17 /// Slices the specified array using the specified range.
19 public static T[] GetSubArray<T>(T[] array, Range range)
23 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
26 (int offset, int length) = range.GetOffsetAndLength(array.Length);
28 if (default(T) != null || typeof(T[]) == array.GetType())
30 // We know the type of the array to be exactly T[].
34 return Array.Empty<T>();
37 var dest = new T[length];
39 ref Unsafe.As<byte, T>(ref dest.GetRawSzArrayData()),
40 ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), offset),
46 // The array is actually a U[] where U:T.
47 T[] dest = (T[])Array.CreateInstance(array.GetType().GetElementType(), length);
48 Array.Copy(array, offset, dest, 0, length);
53 public static object GetUninitializedObject(Type type)
57 throw new ArgumentNullException(nameof(type), SR.ArgumentNull_Type);
60 if (!type.IsRuntimeImplemented())
62 throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type.ToString()));
65 return GetUninitializedObjectInternal(type);
68 public static void PrepareContractedDelegate(Delegate d)
72 public static void ProbeForSufficientStack()
76 public static void PrepareConstrainedRegions()
80 public static void PrepareConstrainedRegionsNoOP()