public T this [int index] { get { if (index < 0 || index >= Count) { throw new IndexOutOfRangeException(); } unsafe { byte *p = stackalloc byte [ElementStride]; NativeMethodsForSwiftArray.ArrayGet(p, CheckedSwiftData, index, ElementMetatype); return(StructMarshal.Marshaler.ToNet <T> (p, false)); } } set { if (index < 0 || index >= Count) { throw new IndexOutOfRangeException(); } unsafe { byte *buff = stackalloc byte [ElementStride]; StructMarshal.Marshaler.ToSwift(typeof(T), value, buff); NativeMethodsForSwiftArray.ArraySet(CheckedSwiftData, buff, index, ElementMetatype); StructMarshal.Marshaler.ReleaseSwiftPointer(typeof(T), new IntPtr(buff)); } } }
public void RemoveAt(int index) { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException(nameof(index)); } NativeMethodsForSwiftArray.ArrayRemoveAt(CheckedSwiftData, index, ElementMetatype); }
public void Add(T item) { unsafe { byte *buff = stackalloc byte [ElementStride]; StructMarshal.Marshaler.ToSwift(typeof(T), item, buff); NativeMethodsForSwiftArray.ArrayAdd(CheckedSwiftData, buff, ElementMetatype); StructMarshal.Marshaler.ReleaseSwiftPointer(typeof(T), new IntPtr(buff)); } }
public void Insert(int index, T item) { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException(nameof(index)); } unsafe { byte *buff = stackalloc byte [ElementStride]; StructMarshal.Marshaler.ToSwift(typeof(T), item, buff); NativeMethodsForSwiftArray.ArrayInsert(CheckedSwiftData, buff, index, ElementMetatype); StructMarshal.Marshaler.ReleaseSwiftPointer(typeof(T), new IntPtr(buff)); } }
public bool Remove(T item) { nint i = 0; foreach (T thing in this) { if (Equals(thing, item)) { NativeMethodsForSwiftArray.ArrayRemoveAt(CheckedSwiftData, i, ElementMetatype); return(true); } i++; } return(false); }
public SwiftArray(nint capacity) : this(NativeMethodsForSwiftArray.NewArray(ValidateCapacity(capacity), ElementMetatype)) { }
public void Clear() { NativeMethodsForSwiftArray.ArrayClear(CheckedSwiftData, ElementMetatype); }
public static SwiftMetatype GetSwiftMetatype() { return(NativeMethodsForSwiftArray.PIMetadataAccessor_SwiftArray(SwiftMetadataRequest.Complete, ElementMetatype)); }