Esempio n. 1
0
        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));
                }
            }
        }
Esempio n. 2
0
        public void RemoveAt(int index)
        {
            if (index < 0 || index >= Count)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            NativeMethodsForSwiftArray.ArrayRemoveAt(CheckedSwiftData, index, ElementMetatype);
        }
Esempio n. 3
0
 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));
     }
 }
Esempio n. 4
0
        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));
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public SwiftArray(nint capacity)
     : this(NativeMethodsForSwiftArray.NewArray(ValidateCapacity(capacity), ElementMetatype))
 {
 }
Esempio n. 7
0
 public void Clear()
 {
     NativeMethodsForSwiftArray.ArrayClear(CheckedSwiftData, ElementMetatype);
 }
Esempio n. 8
0
 public static SwiftMetatype GetSwiftMetatype()
 {
     return(NativeMethodsForSwiftArray.PIMetadataAccessor_SwiftArray(SwiftMetadataRequest.Complete, ElementMetatype));
 }