public static void PrintObjectInfo(ISwiftObject obj, string label, int stackFrameIndex) { var handle = obj == null ? IntPtr.Zero : obj.SwiftObject; var typeName = obj != null?obj.GetType().Name : "(null)"; PrintObjectInfo(handle, label, typeName, stackFrameIndex > 0 ? stackFrameIndex + 1 : 0); }
public static SwiftAnyObject FromISwiftObject(ISwiftObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } return(new SwiftAnyObject(obj.SwiftObject)); }
public static void DumpSwiftObject(ISwiftObject obj, bool terse) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } DumpSwiftObject(obj.SwiftObject, terse); }
public static string ClassName(ISwiftObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } return(ClassName(obj.SwiftObject)); }
public static string MemoryStatus(ISwiftObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } return(MemoryStatus(obj.SwiftObject)); }
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))); }
internal static IntPtr GetClassPtr(ISwiftObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (obj.SwiftObject == IntPtr.Zero) { return(IntPtr.Zero); } return(object_getClass(obj.SwiftObject)); }
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))); }
public unsafe void Combine <T>(T thing) where T : ISwiftHashable { fixed(byte *thisSwiftDataPtr = StructMarshal.Marshaler.PrepareNominal(this)) { IntPtr thingIntPtr; ISwiftObject thingProxy = null; var thingIsSwiftable = StructMarshal.Marshaler.IsSwiftRepresentable(typeof(T)); if (thingIsSwiftable) { byte *thingPtr = stackalloc byte [StructMarshal.Marshaler.Strideof(typeof(T))]; thingIntPtr = new IntPtr(thingPtr); StructMarshal.Marshaler.ToSwift(thing, thingIntPtr); } else { if (SwiftProtocolTypeAttribute.IsAssociatedTypeProxy(typeof(ISwiftHashable))) { byte *thingPtr0 = stackalloc byte [IntPtr.Size]; thingIntPtr = new IntPtr(thingPtr0); Marshal.WriteIntPtr(thingIntPtr, thingProxy.SwiftObject); } else { var thingExistentialContainer = SwiftObjectRegistry.Registry.ExistentialContainerForProtocols(thing, typeof(ISwiftHashable)); byte *thingProtoPtr = stackalloc byte [thingExistentialContainer.SizeOf]; thingIntPtr = new IntPtr(thingProtoPtr); thingExistentialContainer.CopyTo(thingIntPtr); } } NativeMethodsForSwiftHasher.PI_hasherCombine((IntPtr)thisSwiftDataPtr, thingIntPtr, StructMarshal.Marshaler.Metatypeof(typeof(T), new Type [] { typeof(ISwiftHashable) }), StructMarshal.Marshaler.ProtocolWitnessof(typeof(ISwiftHashable), typeof(T))); if (thingIsSwiftable) { StructMarshal.Marshaler.ReleaseSwiftPointer(typeof(T), thingIntPtr); } else { if (thingProxy != null) { StructMarshal.ReleaseSwiftObject(thingProxy); } } } }
public static bool IsSwiftClassObject(ISwiftObject obj) { return(GetSwiftClassPriv(obj).IsSwiftTypeMetadata); }
internal static SwiftMetatype GetObjectType(ISwiftObject obj) { return(new SwiftMetatype(swift_getObjectType(obj.SwiftObject))); }
public static string ObjectInformation(ISwiftObject obj, OutputOptions options) { string hexFormat = IntPtr.Size < 8 ? "X8" : "X16"; var writer = new StringWriter(); if (obj == null) { writer.WriteLine("ISwiftObject is null."); } else { if (obj.SwiftObject == IntPtr.Zero) { writer.WriteLine("ISwiftObject has a 0 SwiftObject."); } else { writer.WriteLine($"ISwiftObject with value {obj.SwiftObject.ToString (hexFormat)}."); writer.WriteLine($"Retain count {StructMarshal.RetainCount (obj)}."); if (!SwiftClassObject.IsSwiftClassObject(obj)) { writer.WriteLine("Unable to retrieve class object. Maybe an Objective C object?"); } else { try { SwiftClassObject classObj = SwiftClassObject.FromSwiftObject(obj); if (classObj == null) { writer.WriteLine("Unable to retrieve class object."); } else { string name = NameFromClassObject(classObj) ?? "<no name available>"; writer.WriteLine($"Instance of {name}."); } if (classObj.SuperClass != null) { string superName = NameFromClassObject(classObj.SuperClass) ?? "<no name available>"; writer.WriteLine($"Inherits from {superName}."); } writer.WriteLine($"Instance size {classObj.InstanceSize} bytes."); writer.WriteLine($"Is swift 1 class: {classObj.IsSwift1Class}."); writer.WriteLine($"Uses swift 1 reference counting: {classObj.UsesSwift1RefCounting}."); if ((options & OutputOptions.Vtable) != 0) { DumpVTable(writer, hexFormat, classObj.Vtable, classObj.VtableSize); } if ((options & OutputOptions.TypeDescriptor) != 0) { if (classObj.IsNominalTypeDescriptorValid) { DumpNominalTypeDescriptor(writer, classObj.NominalTypeDescriptor); } else { writer.WriteLine("No type descriptor."); } } } catch (Exception e) { writer.WriteLine($"Error attempting to retrieve class object: {e.Message}"); } } } } return(writer.ToString()); }