Exemple #1
0
        public virtual void InitNonPrimaryBase(ICppObject baseInDerived, ICppObject derived, Type baseType)
        {
            int offset;
            var baseTypeInfo = GetCastInfo(derived.GetType(), baseType, out offset);

            Marshal.WriteIntPtr(baseInDerived.Native.Native, baseTypeInfo.GCHandleOffset, CppInstancePtr.MakeGCHandle(baseInDerived));
        }
Exemple #2
0
        public virtual CppInstancePtr Cast(ICppObject instance, Type targetType)
        {
            int offset;
            var baseTypeInfo = GetCastInfo(instance.GetType(), targetType, out offset);
            var result       = new CppInstancePtr(instance.Native, offset);

            if (offset > 0 && instance.Native.IsManagedAlloc && baseTypeInfo.HasVTable)
            {
                // we might need to paste the managed base-in-derived vtptr here --also inits native_vtptr
                baseTypeInfo.VTable.InitInstance(ref result);
            }

            return(result);
        }
Exemple #3
0
        public virtual CppInstancePtr Cast(ICppObject instance, Type targetType)
        {
            int offset;
            var baseTypeInfo = GetCastInfo(instance.GetType(), targetType, out offset);
            var result       = new CppInstancePtr(instance.Native, offset);

            if (offset > 0 && instance.Native.IsManagedAlloc && baseTypeInfo.HasVTable)
            {
                // we might need to paste the managed base-in-derived vtptr here --also inits native_vtptr
                baseTypeInfo.VTable.InitInstanceOffset(ref result, false, 0);

                // Make sure we update the vtable location in the original instance as well
                instance.Native.SetNativeBaseVTable(baseTypeInfo.WrapperType, result.NativeVTable);
            }

            return(result);
        }