示例#1
0
        public static SwiftTupleMap FromTypes(Type [] types)
        {
            lock (cachelock) {
                SwiftTupleMap map;
                if (cache.TryGetValue(types, out map))
                {
                    return(map);
                }
                map       = new SwiftTupleMap();
                map.Types = types;
                var metatypes = new SwiftMetatype [types.Length];
                for (int i = 0; i < types.Length; i++)
                {
                    metatypes [i] = StructMarshal.Marshaler.Metatypeof(types [i]);
                }
                var mt = SwiftCore.TupleMetatype(metatypes);
                map.Offsets = mt.GetTupleElementOffsets();
                map.Size    = (int)SwiftCore.SizeOf(mt);
                map.Stride  = (int)SwiftCore.StrideOf(mt);

                cache.Add(types, map);

                return(map);
            }
        }
示例#2
0
 public static string MemoryStatus(IntPtr handle)
 {
     if (handle == IntPtr.Zero)
     {
         return("(zero handle)");
     }
     return($"s: {SwiftCore.RetainCount (handle)} u: {SwiftCore.UnownedRetainCount (handle)} w: {SwiftCore.WeakRetainCount (handle)} IsDealloc: {SwiftCore.IsDeallocating (handle)}");
 }
        public static SwiftClassObject FromSwiftObject(ISwiftObject obj)
        {
            SwiftClassPriv classPriv = GetSwiftClassPriv(obj);

            if (!classPriv.IsSwiftTypeMetadata)
            {
                throw new NotSupportedException("class object is an Objective C class.");
            }
            return(new SwiftClassObject(classPriv, SwiftCore.GetClassPtr(obj)));
        }
        static SwiftClassPriv GetSwiftClassPriv(ISwiftObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            var classPtr = SwiftCore.GetClassPtr(obj);

            if (classPtr == IntPtr.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(obj));
            }
            return((SwiftClassPriv)Marshal.PtrToStructure(classPtr, typeof(SwiftClassPriv)));
        }