Beispiel #1
0
        private static ClassDisposeHandle CreateAction <TAction, TArg0>(TArg0 arg0, IntPtr pMethod, out TAction action)
            where TAction : Delegate
            where TArg0 : class
        {
            MethodTable *pMT = MethodTable.GetMethodTable <TAction>();

            ObjectHeader *pThis     = TypedReferenceHelper.ClassToPointer(arg0);
            ObjectHeader *objHeader = (ObjectHeader *)RawMemoryManager.Allocate(pMT->BaseSize);

            try
            {
                objHeader->SyncBlock   = 0;
                objHeader->MethodTable = pMT;

                Byte *objBody = (Byte *)(objHeader + 1);
                *(MethodTable ***)objBody = &pThis->MethodTable;     // Delegate._target
                *(IntPtr *)(objBody + 2 * sizeof(IntPtr)) = pMethod; // Delegate._methodPtr

                action = TypedReferenceHelper.PointerToObject <TAction>(objHeader);
            }
            catch
            {
                RawMemoryManager.Free(pMT->BaseSize, objHeader);
                throw;
            }

            return(new ClassDisposeHandle(pMT->BaseSize, objHeader));
        }
Beispiel #2
0
        public MethodTable *GetMethodTable()
        {
            if (IsGenericVariable())
            {
                return(null);
            }

            if (GetInternalCorElementType() == CorElementType.FnPtr)
                return(MethodTable.GetMethodTable <UIntPtr>());

            fixed(TypeDesc *pThis = &this)
            {
                ParamTypeDesc *pParam = (ParamTypeDesc *)pThis;

                if (GetInternalCorElementType() == CorElementType.ValueType)
                {
                    return(pParam->Arg.AsMethodTable());
                }
                else
                {
                    return(pParam->GetTemplateMethodTableInternal());
                }
            }
        }