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)); }
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); }
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); }