internal static int IndexRangeCheck(ISwiftExistentialContainer impl, int index) { if (index < 0 || index >= impl.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } return(index); }
public SwiftExistentialContainer1(ISwiftExistentialContainer container) { if (container.Count != 1) { throw new ArgumentException($"Existential container has {container.Count} elements instead of 1."); } d0 = container.Data0; d1 = container.Data1; d2 = container.Data2; md = container.ObjectMetadata; wt0 = container [0]; }
public static BaseProxy MakeProxy(Type interfaceType, ISwiftExistentialContainer container) { var proxyType = ProxyTypeForInterfaceType(interfaceType); var ci = proxyType.GetConstructor(new Type [] { typeof(ISwiftExistentialContainer) }); if (ci == null) { throw new SwiftRuntimeException($"Type {proxyType.Name} does not have a constructor that an ISwiftExistentialContainer"); } return((BaseProxy)ci.Invoke(new object [] { container })); }
internal static void Copy(ISwiftExistentialContainer from, ISwiftExistentialContainer to) { if (from.Count != to.Count) { throw new ArgumentOutOfRangeException($"{nameof (from)} and {nameof (to)} must have matching Count properties"); } to.Data0 = from.Data0; to.Data1 = from.Data1; to.Data2 = from.Data2; for (int i = 0; i < from.Count; i++) { to [i] = from [i]; } }
public static T Unbox <T> (ISwiftExistentialContainer container) { var targetType = typeof(T); var obj = Unbox(container); // this shouldn't ever happen, but... if (obj == null) { throw new SwiftRuntimeException($"Unexpected null from unboxing a container of type {container.ObjectMetadata.TypeName}"); } if (!targetType.IsAssignableFrom(obj.GetType())) { throw new SwiftRuntimeException($"C# type {targetType.Name} can't be set from actual type {obj.GetType ()}"); } return((T)obj); }
internal static IntPtr CopyTo(ISwiftExistentialContainer from, IntPtr memory) { Marshal.WriteIntPtr(memory, from.Data0); memory += IntPtr.Size; Marshal.WriteIntPtr(memory, from.Data1); memory += IntPtr.Size; Marshal.WriteIntPtr(memory, from.Data2); memory += IntPtr.Size; Marshal.WriteIntPtr(memory, from.ObjectMetadata.Handle); memory += IntPtr.Size; for (int i = 0; i < from.Count; i++) { Marshal.WriteIntPtr(memory, from [i]); memory += IntPtr.Size; } return(memory); }
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 CustomStringConvertibleXamProxy(ISwiftExistentialContainer container) : base(typeof(ICustomStringConvertible), null) { this.container = new SwiftExistentialContainer1(container); }
public SwiftComparableProxy(ISwiftExistentialContainer container) : base(typeof(ISwiftComparable), null) { throw new NotImplementedException("SwiftComparableProxy should never get constructed from an existential container."); }
public void CopyTo(ISwiftExistentialContainer to) { Copy(this, to); }