Class SortedItemsEvent<T>
- Namespace
- MonkeyLoader.Resonite.Events
- Assembly
- MonkeyLoader.Resonite.Integration.dll
Abstract base class for all sorts of events that focus on adding a (sorted) list of unique items.
public abstract class SortedItemsEvent<T>
Type Parameters
T
The type of the items.
- Inheritance
-
SortedItemsEvent<T>
- Inherited Members
Constructors
SortedItemsEvent()
Creates a new instance with no items.
protected SortedItemsEvent()
SortedItemsEvent(IEnumerable<T>)
Creates a new instance with the given items,
setting their sort order values to 0
.
protected SortedItemsEvent(IEnumerable<T> items)
Parameters
items
IEnumerable<T>The items to start with.
SortedItemsEvent(IEnumerable<T>, Func<T, int>)
Creates a new instance with the given items, using the
getSortOrder
function to determine their sort order values.
protected SortedItemsEvent(IEnumerable<T> items, Func<T, int> getSortOrder)
Parameters
items
IEnumerable<T>The items to start with.
getSortOrder
Func<T, int>The function to map items to a sort order value.
Fields
sortableItems
The items that have been added to the event.
protected readonly Dictionary<T, int> sortableItems
Field Value
- Dictionary<T, int>
Properties
Items
Gets the unique items as sorted by their sort order values.
public virtual IEnumerable<T> Items { get; }
Property Value
- IEnumerable<T>
Methods
AddItem(T, int, bool)
Adds the given item with the given sort order.
If it's already present, the sort order is only changed to the given one,
when updateOrder
is true
.
public bool AddItem(T item, int sortOrder = 0, bool updateOrder = false)
Parameters
item
TThe item to add.
sortOrder
intThe sort order value for the item.
updateOrder
boolWhether to update the sort order value if the item is already present.
Returns
- bool
true
if the item is now present as defined; otherwise,false
.
HasItem(T, out int?)
Checks whether the given item is already present.
public bool HasItem(T item, out int? sortOrder)
Parameters
item
TThe item to check for.
sortOrder
int?The sort order value of the item, if it is present.
Returns
- bool
true
if the item is present; otherwise,false
.
RemoveItem(T)
Removes the given item.
public bool RemoveItem(T item)
Parameters
item
TThe item to remove.
Returns
- bool
true
if the item was found and removed; otherwisefalse
.