public unsafe static object Unbox(ISwiftExistentialContainer container) { Type targetType; if (!SwiftTypeRegistry.Registry.TryGetValue(container.ObjectMetadata, out targetType)) { throw new SwiftRuntimeException($"Unable to unbox swift type {container.ObjectMetadata.TypeName}."); } byte *anyPtr = stackalloc byte [container.SizeOf]; var anyIntPtr = new IntPtr(anyPtr); CopyTo(container, anyIntPtr); byte *resultPtr = stackalloc byte [(int)SwiftCore.StrideOf(container.ObjectMetadata)]; var resultIntPtr = new IntPtr(resultPtr); AnyPinvokes.FromAny(resultIntPtr, anyIntPtr, container.ObjectMetadata); return(StructMarshal.Marshaler.ToNet(resultIntPtr, targetType)); }
public static unsafe SwiftExistentialContainer0 Box(object o) { if (o == null) { throw new ArgumentNullException(nameof(o)); } var mt = StructMarshal.Marshaler.Metatypeof(o.GetType()); SwiftExistentialContainer0 result = new SwiftExistentialContainer0(); byte *anyPtr = stackalloc byte [result.SizeOf]; var anyIntPtr = new IntPtr(anyPtr); byte *argPtr = stackalloc byte [StructMarshal.Marshaler.Strideof(o.GetType())]; var argIntPtr = new IntPtr(argPtr); StructMarshal.Marshaler.ToSwift(o, argIntPtr); AnyPinvokes.ToAny(anyIntPtr, argIntPtr, mt); CopyTo(anyIntPtr, ref result); return(result); }