=> NativeFieldsOffset + NativeFields.Sum(fld => fld.SwiftType.NativeDataSize); // FIXME: alignment? #region Native Fields /// <summary> /// Determines the fields to expose to Swift. /// </summary> /// <remarks> /// This method is called from the constructor. The only instance state that /// is guaranteed to be initialized before this method is called is <see cref="ManagedType"/>. /// </remarks> protected virtual unsafe IReadOnlyList <SwiftFieldInfo> DetermineNativeFields() { var offset = NativeFieldsOffset; var managedFields = ManagedType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var swiftFields = new List <SwiftFieldInfo> (managedFields.Length); foreach (var fld in managedFields) { if (!typeof(ISwiftFieldExposable).IsAssignableFrom(fld.FieldType)) { continue; } var nullability = Nullability.Of(fld); var swiftType = SwiftType.Of(fld.FieldType, nullability); Debug.Assert(swiftType != null, "ISwiftFieldExposable types must be SwiftTypes"); // FIXME: '!' shouldn't be needed as we have Debug.Assert swiftFields.Add(new SwiftFieldInfo(fld, swiftType !, nullability, offset)); offset += swiftType !.NativeDataSize; // FIXME: alignment? } return(swiftFields.ToArray()); }
void ISwiftFieldExposable.SetSwiftType(SwiftType swiftType, Nullability nullability) { this.swiftType = swiftType; SetNullability(nullability); }
public SwiftProtocolAttribute(string libraryPath, string module, string name) : this(libraryPath, SwiftType.Mangle(module, name)) { }
public SwiftHandle(object toPin, SwiftType swiftType, bool destroyOnDispose = false) { this.swiftType = swiftType ?? throw new ArgumentNullException(nameof(swiftType)); this.handle = GCHandle.Alloc(toPin, GCHandleType.Pinned); this.tp = new TaggedPointer(handle.AddrOfPinnedObject(), destroyOnDispose); }
public SwiftHandle(void *pointer, SwiftType swiftType, GCHandle handle = default) { this.swiftType = swiftType ?? throw new ArgumentNullException(nameof(swiftType)); this.tp = new TaggedPointer(pointer, false); this.handle = handle; }
// FIXME: Does this belong somewhere else? public ProtocolDescriptor *GetProtocol(string module, string name) => (ProtocolDescriptor *)RequireSymbol("$s" + SwiftType.Mangle(module, name) + "Mp");