void ISwiftFieldExposable.InitNativeData(void *handle)
 {
     if (NativeDataInitialized)
     {
         throw new InvalidOperationException();
     }
     data = new TaggedPointer(handle, owned: false);
     InitNativeData(handle);
 }
Beispiel #2
0
 public void Dispose()
 {
     if (tp.IsOwned)
     {
         swiftType.Destroy(tp.Pointer);
     }
     if (handle.IsAllocated)
     {
         handle.Free();
     }
     tp = default;
 }
 // NOTE: If we ever change this implementation such that the returned SwiftHandle
 //  needs to be disposed, we must update NSHostingView and UIHostingView constructors.
 public SwiftHandle GetSwiftHandle()
 {
     if (data == null)
     {
         data = TaggedPointer.AllocHGlobal(SwiftType.NativeDataSize);
         try {
             InitNativeData(data.Pointer);
         } catch {
             data = default;
             throw;
         }
     }
     return(new SwiftHandle(data.Pointer, SwiftType));
 }
Beispiel #4
0
 public SwiftHandle(object toPin, SwiftType swiftType, bool destroyOnDispose = false)
 {
     this.swiftType = swiftType ?? throw new ArgumentNullException(nameof(swiftType));
     this.handle    = GCHandle.Alloc(toPin, GCHandleType.Pinned);
     this.tp        = new TaggedPointer(handle.AddrOfPinnedObject(), destroyOnDispose);
 }
Beispiel #5
0
 public SwiftHandle(void *pointer, SwiftType swiftType, GCHandle handle = default)
 {
     this.swiftType = swiftType ?? throw new ArgumentNullException(nameof(swiftType));
     this.tp        = new TaggedPointer(pointer, false);
     this.handle    = handle;
 }