File: Internal\Runtime\CompilerHelpers\SharedCodeHelpers.cs
Web Access
Project: src\src\runtime\src\coreclr\nativeaot\System.Private.CoreLib\src\System.Private.CoreLib.csproj (System.Private.CoreLib)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime;

using Internal.Runtime.Augments;

using Debug = System.Diagnostics.Debug;

namespace Internal.Runtime.CompilerHelpers
{
    /// <summary>
    /// These methods are used to implement shared generic code.
    /// </summary>
    internal static class SharedCodeHelpers
    {
        public static unsafe MethodTable* GetOrdinalInterface(MethodTable* pType, ushort interfaceIndex)
        {
            Debug.Assert(interfaceIndex < pType->NumInterfaces);
            return pType->InterfaceMap[interfaceIndex];
        }

        public static unsafe MethodTable* GetCurrentSharedThunkContext()
        {
            return (MethodTable*)RuntimeImports.GetCurrentInteropThunkContext();
        }

        public static unsafe MethodTable* GetClassHandleFromMethodParam(IntPtr pDictionary)
        {
            bool success = RuntimeAugments.TypeLoaderCallbacks.TryGetOwningTypeForMethodDictionary(pDictionary, out RuntimeTypeHandle th);
            Debug.Assert(success);
            return th.ToMethodTable();
        }
    }
}