OrderedList<T> Class

A List that provides methods for inserting/finding before/after. See remarks.

public class OrderedList<T> : List<T> where T : notnull

Type parameters

T
Type of the list item

Remarks

We use a typed list and don't use extension methods because it would pollute all list implements and the top level namespace.

See also

Inheritance
List<T> OrderedList<T>

Constructors

NameDescription
OrderedList()Performs the ordered list operation.
OrderedList(IEnumerable<T>)Performs the ordered list operation.

OrderedList overloads

OrderedList()

OrderedList.cs

Performs the ordered list operation.

public OrderedList()

OrderedList(IEnumerable<T>)

OrderedList.cs

Performs the ordered list operation.

public OrderedList(IEnumerable<T> collection)
Parameters
collection IEnumerable<T>

Methods

NameDescription
AddIfNotAlready<TItem>()Adds if not already t item.
AddIfNotAlready<TItem>(TItem)Adds if not already t item.
Contains<TItem>()Performs the contains t item operation.
Find<TItem>()Performs the find t item operation.
FindExact<TItem>()Performs the find exact t item operation.
InsertAfter<TItem>(T)Performs the insert after t item operation.
InsertBefore<TItem>(T)Performs the insert before t item operation.
Replace<TItem>(T)Replaces TItem with replacement.
ReplaceOrAdd<TItem>(T)Replaces TItem with newItem or adds newItem.
TryFind<TItem>(TItem?)Attempts to find t item.
TryRemove<TItem>()Removes the first occurrence of TItem

AddIfNotAlready overloads

AddIfNotAlready<TItem>()

OrderedList.cs

Adds if not already t item.

public void AddIfNotAlready<TItem>() where TItem : class, T, new()
Type parameters
TItem

AddIfNotAlready<TItem>(TItem)

OrderedList.cs

Adds if not already t item.

public void AddIfNotAlready<TItem>(TItem item) where TItem : T
Type parameters
TItem
Parameters
item TItem

Contains<TItem>()

OrderedList.cs

Performs the contains t item operation.

public bool Contains<TItem>() where TItem : T

Type parameters

TItem

Returns

bool

Find<TItem>()

OrderedList.cs

Performs the find t item operation.

public TItem? Find<TItem>() where TItem : T

Type parameters

TItem

Returns

TItem?

FindExact<TItem>()

OrderedList.cs

Performs the find exact t item operation.

public TItem? FindExact<TItem>() where TItem : T

Type parameters

TItem

Returns

TItem?

InsertAfter<TItem>(T)

OrderedList.cs

Performs the insert after t item operation.

public bool InsertAfter<TItem>(T item) where TItem : T

Type parameters

TItem

Parameters

item T

Returns

bool

InsertBefore<TItem>(T)

OrderedList.cs

Performs the insert before t item operation.

public bool InsertBefore<TItem>(T item) where TItem : T

Type parameters

TItem

Parameters

item T

Returns

bool

Replace<TItem>(T)

OrderedList.cs

Replaces TItem with replacement.

public bool Replace<TItem>(T replacement) where TItem : T

Type parameters

TItem
Item type to find in the list

Parameters

replacement T
Object to replace this item with

Returns

bool true if a replacement was made; otherwise false.

ReplaceOrAdd<TItem>(T)

OrderedList.cs

Replaces TItem with newItem or adds newItem.

public bool ReplaceOrAdd<TItem>(T newItem) where TItem : T

Type parameters

TItem
Item type to find in the list

Parameters

newItem T
Object to add/replace the found item with

Returns

bool true if a replacement was made; otherwise false.

TryFind<TItem>(TItem?)

OrderedList.cs

Attempts to find t item.

public bool TryFind<TItem>(out TItem? item) where TItem : T

Type parameters

TItem

Parameters

item TItem?

Returns

bool

TryRemove<TItem>()

OrderedList.cs

Removes the first occurrence of TItem

public bool TryRemove<TItem>() where TItem : T

Type parameters

TItem

Returns

bool