This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move part of RuntimeHelpers to shared partition (dotnet/coreclr#23130)
* Move part of RuntimeHelpers to shared partition * Remove FormatterServices.cs Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
- Loading branch information
1 parent
106009b
commit a5414fc
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
src/Common/src/CoreLib/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,66 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.Serialization; | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
public static partial class RuntimeHelpers | ||
{ | ||
public delegate void TryCode(object userData); | ||
|
||
public delegate void CleanupCode(object userData, bool exceptionThrown); | ||
|
||
/// <summary> | ||
/// GetSubArray helper method for the compiler to slice an array using a range. | ||
/// </summary> | ||
public static T[] GetSubArray<T>(T[] array, Range range) | ||
{ | ||
Type elementType = array.GetType().GetElementType(); | ||
Span<T> source = array.AsSpan(range); | ||
|
||
if (elementType.IsValueType) | ||
{ | ||
return source.ToArray(); | ||
} | ||
else | ||
{ | ||
T[] newArray = (T[])Array.CreateInstance(elementType, source.Length); | ||
source.CopyTo(newArray); | ||
return newArray; | ||
} | ||
} | ||
|
||
public static object GetUninitializedObject(Type type) | ||
{ | ||
if (type is null) | ||
{ | ||
throw new ArgumentNullException(nameof(type), SR.ArgumentNull_Type); | ||
} | ||
|
||
if (!type.IsRuntimeImplemented()) | ||
{ | ||
throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type.ToString())); | ||
} | ||
|
||
return GetUninitializedObjectInternal(type); | ||
} | ||
|
||
public static void PrepareContractedDelegate(Delegate d) | ||
{ | ||
} | ||
|
||
public static void ProbeForSufficientStack() | ||
{ | ||
} | ||
|
||
public static void PrepareConstrainedRegions() | ||
{ | ||
} | ||
|
||
public static void PrepareConstrainedRegionsNoOP() | ||
{ | ||
} | ||
} | ||
} |