예제 #1
0
        /// <summary>
        /// Makes a relationship to an item, appending it at the end of the sorted relationship.
        /// </summary>
        /// <param name="item">RealmObject being added to the relationship.</param>
        /// <typeparam name="T">Type of the RealmObject which is the target of the relationship.</typeparam>
        public void Add(T item)
        {
            this.ManageObjectIfNeeded(item);
            var rowIndex = ((RealmObject)item).RowHandle.RowIndex;

            NativeLinkList.add(_listHandle, (IntPtr)rowIndex);
        }
예제 #2
0
 /// <summary>
 /// Breaks the relationship to the item at the ordinal index, without deleting the item.
 /// </summary>
 /// <param name="index">Ordinal zero-based index of the related item.</param>
 /// <exception cref="IndexOutOfRangeException">When the index is out of range for the related items.</exception>
 public void RemoveAt(int index)
 {
     if (index < 0)
     {
         throw new IndexOutOfRangeException();
     }
     NativeLinkList.erase(_listHandle, (IntPtr)index);
 }
예제 #3
0
        /// <summary>
        /// Finds an ordinal index for an item in a relationship.
        /// </summary>
        /// <param name="item">RealmObject being removed from the relationship.</param>
        /// <typeparam name="T">Type of the RealmObject which is the target of the relationship.</typeparam>
        /// <returns>0-based index if the item was found in the related set, or RealmList.ITEM_NOT_FOUND.</returns>
        public int IndexOf(T item)
        {
            if (!item.IsManaged)
            {
                throw new ArgumentException("Value does not belong to a realm", nameof(item));
            }

            var rowIndex = ((RealmObject)item).RowHandle.RowIndex;

            return((int)NativeLinkList.find(_listHandle, (IntPtr)rowIndex, (IntPtr)0));
        }
예제 #4
0
        /// <summary>
        /// Makes a relationship to an item, inserting at a specified location ahead of whatever else was in that location.
        /// </summary>
        /// <param name="index">Ordinal zero-based index at which to insert the related items.</param>
        /// <param name="item">RealmObject being inserted into the relationship.</param>
        /// <typeparam name="T">Type of the RealmObject which is the target of the relationship.</typeparam>
        /// <exception cref="IndexOutOfRangeException">When the index is out of range for the related items.</exception>
        public void Insert(int index, T item)
        {
            if (index < 0)
            {
                throw new IndexOutOfRangeException();
            }

            this.ManageObjectIfNeeded(item);
            var rowIndex = ((RealmObject)item).RowHandle.RowIndex;

            NativeLinkList.insert(_listHandle, (IntPtr)index, (IntPtr)rowIndex);
        }
예제 #5
0
        /// <summary>
        /// Returns the item at the ordinal index.
        /// </summary>
        /// <param name="index">Ordinal zero-based index of the related items.</param>
        /// <typeparam name="T">Type of the RealmObject which is the target of the relationship.</typeparam>
        /// <returns>A related item, if exception not thrown.</returns>
        /// <exception cref="IndexOutOfRangeException">When the index is out of range for the related items.</exception>
        public T this[int index]
        {
            get
            {
                if (index < 0)
                {
                    throw new IndexOutOfRangeException();
                }
                var linkedRowPtr = NativeLinkList.get(_listHandle, (IntPtr)index);
                return((T)_parent.MakeRealmObject(typeof(T), linkedRowPtr));
            }

            set
            {
                throw new NotImplementedException();
            }
        }
예제 #6
0
 /// <summary>
 /// Breaks the relationship to all related items, without deleting the items.
 /// </summary>
 public void Clear()
 {
     NativeLinkList.clear(_listHandle);
 }