/// <summary> /// Remove an item from the <see cref="IPagedDataSet"/> with the specified position /// </summary> /// <param name="dataSet">The dataset to modify</param> /// <param name="offset">The position to remove relative to the dataset's caret</param> /// <returns></returns> public static async Task RemoveAtOffset(this IRemovable removable, IPagedDataSet dataSet, int offset) { var pi = await dataSet.GetCurrentPageIndex(); var ps = await dataSet.GetPageSize(); var sel = await dataSet.GetSelector(); if (sel == null) { throw new InvalidOperationException("The paged data set does not support selecting items that is required for this method to work"); } await removable.RemoveAt(dataSet, pi *ps + offset + await sel.GetCaretPosition()); }
/// <summary> /// Add an item into the <see cref="IPagedDataSet"/> with the position relative to the <see cref="ISelectable"/>'s caret /// </summary> /// <param name="addable">The adder to perform</param> /// <param name="item">The item to add</param> /// <param name="dataSet">the dataset to modify</param> /// <param name="offset">The position to add relative to the <see cref="IPagedDataSet{TItem, TResult}"/> caret</param> /// <returns></returns> public static async Task AddOffset(this IAddable addable, IPagedDataSet dataSet, object item, int offset) { var selector = await dataSet.GetSelector(); if (selector == null) { throw new InvalidOperationException("PagedDataSet must support selector to use this function!"); } var pi = await dataSet.GetCurrentPageIndex(); var ps = await dataSet.GetPageSize(); var caret = await selector.GetCaretPosition(); await addable.Add(item, pi *ps + caret + offset); }