예제 #1
0
 internal static int IndexRangeCheck(ISwiftExistentialContainer impl, int index)
 {
     if (index < 0 || index >= impl.Count)
     {
         throw new ArgumentOutOfRangeException(nameof(index));
     }
     return(index);
 }
예제 #2
0
 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];
 }
예제 #3
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 }));
        }
예제 #4
0
 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);
        }
예제 #6
0
        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);
 }
예제 #9
0
 public SwiftComparableProxy(ISwiftExistentialContainer container)
     : base(typeof(ISwiftComparable), null)
 {
     throw new NotImplementedException("SwiftComparableProxy should never get constructed from an existential container.");
 }
예제 #10
0
 public void CopyTo(ISwiftExistentialContainer to)
 {
     Copy(this, to);
 }