Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Move part of RuntimeHelpers to shared partition (dotnet/coreclr#23130)
Browse files Browse the repository at this point in the history
* Move part of RuntimeHelpers to shared partition

* Remove FormatterServices.cs

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
marek-safar authored and jkotas committed Mar 10, 2019
1 parent 106009b commit a5414fc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ReferenceAssemblyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeCompatibilityAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeFeature.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeWrappedException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SpecialNameAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StateMachineAttribute.cs" />
Expand Down
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()
{
}
}
}

0 comments on commit a5414fc

Please sign in to comment.