SafeList is mutable, but it uses immutable data structures to minimize the need for locking. The provided manipulation Exposes a immutable list. Changes are made by copying the lists. SafeList is Never perform logic on SafeList directly, always use GetList() or GetCollection() first, followed by SetList(). If you need involved list-fu, use ModifyList and specify a callback. It will execute inside a lock, preventing changes on other threads from overwriting each other.
More...
|
delegate void | ChangedHandler (SafeList< T > sender) |
|
delegate IEnumerable< T > | ListEditor (IList< T > items) |
|
| SafeList (IEnumerable< T > items) |
|
ReadOnlyCollection< T > | GetCollection () |
| Returns an immutable snapshot of the collection More...
|
|
IList< T > | GetList () |
| Returns a mutable snapshot of the list More...
|
|
void | SetList (IEnumerable< T > list) |
| Replaces the current collection with a new one. (copied to ensure safety) Use ModifyList when modifying the list. Use this only when the previous or current state of the list is irrelevant. More...
|
|
void | Add (T item) |
| Adds the specified item to the end of the list More...
|
|
bool | Remove (T item) |
| Removes the item from the list More...
|
|
void | AddFirst (T item) |
| Adds the specified item to the beginning of the list More...
|
|
void | ModifyList (ListEditor callback) |
| Allows a caller to perform logic on the list inside a lock, and return a modified list. Callbacks should be fast, and should reference the IList they are fed, not this SafeList instance. Calling methods on the SafeList instance will cause a deadlock. More...
|
|
bool | Contains (T item) |
| Returns true if the collection contains the specified item at the moment. More...
|
|
IEnumerator< T > | GetEnumerator () |
|
|
volatile ReadOnlyCollection< T > | items |
|
object | writeLock = new object() |
|
|
T | First [get] |
| Returns the first item in the list. May return null if the list is empty. More...
|
|
T | Last [get] |
| Returns the first item in the list. May return null if the list is empty. More...
|
|
IEnumerable< T > | Reversed [get] |
|
SafeList is mutable, but it uses immutable data structures to minimize the need for locking. The provided manipulation Exposes a immutable list. Changes are made by copying the lists. SafeList is Never perform logic on SafeList directly, always use GetList() or GetCollection() first, followed by SetList(). If you need involved list-fu, use ModifyList and specify a callback. It will execute inside a lock, preventing changes on other threads from overwriting each other.
- Template Parameters
-
Definition at line 19 of file SafeList.cs.
void ImageResizer.Collections.SafeList< T >.Add |
( |
T |
item | ) |
|
|
inline |
Adds the specified item to the end of the list
- Parameters
-
Definition at line 73 of file SafeList.cs.
77 items =
new ReadOnlyCollection<T>(newList);
IList< T > GetList()
Returns a mutable snapshot of the list
void ImageResizer.Collections.SafeList< T >.AddFirst |
( |
T |
item | ) |
|
|
inline |
Adds the specified item to the beginning of the list
- Parameters
-
Definition at line 122 of file SafeList.cs.
125 newList.Insert(0, item);
126 items =
new ReadOnlyCollection<T>(newList);
IList< T > GetList()
Returns a mutable snapshot of the list
bool ImageResizer.Collections.SafeList< T >.Contains |
( |
T |
item | ) |
|
|
inline |
Returns true if the collection contains the specified item at the moment.
- Parameters
-
- Returns
Definition at line 150 of file SafeList.cs.
151 return items.Contains(item);
ReadOnlyCollection<T> ImageResizer.Collections.SafeList< T >.GetCollection |
( |
| ) |
|
|
inline |
Returns an immutable snapshot of the collection
- Returns
Definition at line 47 of file SafeList.cs.
IList<T> ImageResizer.Collections.SafeList< T >.GetList |
( |
| ) |
|
|
inline |
Returns a mutable snapshot of the list
- Returns
Definition at line 54 of file SafeList.cs.
55 return new List<T>(items);
void ImageResizer.Collections.SafeList< T >.ModifyList |
( |
ListEditor |
callback | ) |
|
|
inline |
Allows a caller to perform logic on the list inside a lock, and return a modified list. Callbacks should be fast, and should reference the IList they are fed, not this SafeList instance. Calling methods on the SafeList instance will cause a deadlock.
- Parameters
-
Definition at line 138 of file SafeList.cs.
140 items =
new ReadOnlyCollection<T>(
new List<T>(callback(
GetList())));
IList< T > GetList()
Returns a mutable snapshot of the list
bool ImageResizer.Collections.SafeList< T >.Remove |
( |
T |
item | ) |
|
|
inline |
Removes the item from the list
- Parameters
-
Definition at line 86 of file SafeList.cs.
89 bool removed = newList.Remove(item);
90 if (!removed)
return false;
91 items =
new ReadOnlyCollection<T>(newList);
IList< T > GetList()
Returns a mutable snapshot of the list
void ImageResizer.Collections.SafeList< T >.SetList |
( |
IEnumerable< T > |
list | ) |
|
|
inline |
Replaces the current collection with a new one. (copied to ensure safety) Use ModifyList when modifying the list. Use this only when the previous or current state of the list is irrelevant.
- Parameters
-
Definition at line 63 of file SafeList.cs.
65 items =
new ReadOnlyCollection<T>(
new List<T>(list));
T ImageResizer.Collections.SafeList< T >.First |
|
get |
Returns the first item in the list. May return null if the list is empty.
Definition at line 99 of file SafeList.cs.
T ImageResizer.Collections.SafeList< T >.Last |
|
get |
Returns the first item in the list. May return null if the list is empty.
Definition at line 110 of file SafeList.cs.
The documentation for this class was generated from the following file:
- C:/Users/nathanael/Documents/resizer/Core/Collections/SafeList.cs