Show / Hide Table of Contents

Class ThreadSafeList<T>

Inheritance
System.Object
ThreadSafeList<T>
ControllerList<T>
SerializedSynchronizedCollection<T>
Implements
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
System.Collections.IList
System.Collections.ICollection
System.Collections.Generic.IReadOnlyList<T>
System.Collections.Generic.IReadOnlyCollection<T>
ISnapshotable<T>
ISnapshotable
Namespace: Eco.Core.Utils
Assembly: Eco.Core.dll
Syntax
public class ThreadSafeList<T> : Object, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, ISnapshotable<T>, ISnapshotable
Type Parameters
Name Description
T

Constructors

ThreadSafeList()

Declaration
public ThreadSafeList()

ThreadSafeList(IEnumerable<T>)

Declaration
public ThreadSafeList(IEnumerable<T> contents)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> contents

Properties

Collection

Declaration
public ICollection<T> Collection { get; }
Property Value
Type Description
System.Collections.Generic.ICollection<T>

Count

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32

IsFixedSize

Declaration
public bool IsFixedSize { get; }
Property Value
Type Description
System.Boolean

IsReadOnly

Declaration
public bool IsReadOnly { get; }
Property Value
Type Description
System.Boolean

IsSynchronized

Declaration
public bool IsSynchronized { get; }
Property Value
Type Description
System.Boolean

Item[Int32]

Declaration
public virtual T this[int index] { get; set; }
Parameters
Type Name Description
System.Int32 index
Property Value
Type Description
T

Snapshot

Gets current list read-only snapshot. May be used to get consistent result between different access calls.

Declaration
public ImmutableList<T> Snapshot { get; }
Property Value
Type Description
System.Collections.Immutable.ImmutableList<T>

SyncRoot

Declaration
public object SyncRoot { get; }
Property Value
Type Description
System.Object

TypeName

Declaration
public string TypeName { get; }
Property Value
Type Description
System.String

Methods

Add(T)

Declaration
public virtual void Add(T item)
Parameters
Type Name Description
T item

AddOrReplace(T, Predicate<T>)

Replaces first element matching the matcher with item or adds new item if no one matched.

Declaration
public virtual void AddOrReplace(T item, Predicate<T> matcher)
Parameters
Type Name Description
T item
System.Predicate<T> matcher

AddRange(IEnumerable<T>)

Declaration
public virtual void AddRange(IEnumerable<T> items)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> items

Clear()

Declaration
public virtual void Clear()

Contains(T)

Declaration
public bool Contains(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Boolean

CopyTo(T[], Int32)

Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type Name Description
T[] array
System.Int32 arrayIndex

GetAndClear()

Declaration
public virtual ImmutableList<T> GetAndClear()
Returns
Type Description
System.Collections.Immutable.ImmutableList<T>

GetAt(Int32)

Declaration
public virtual T GetAt(int index)
Parameters
Type Name Description
System.Int32 index
Returns
Type Description
T

GetEnumerator()

Declaration
public ImmutableList<T>.Enumerator GetEnumerator()
Returns
Type Description
System.Collections.Immutable.ImmutableList.Enumerator<>

GetOrCreate(Predicate<T>, Func<T>)

Declaration
public virtual T GetOrCreate(Predicate<T> test, Func<T> create)
Parameters
Type Name Description
System.Predicate<T> test
System.Func<T> create
Returns
Type Description
T

IndexOf(T)

Declaration
public virtual int IndexOf(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Int32

IndexOf(Object)

Declaration
public virtual int IndexOf(object value)
Parameters
Type Name Description
System.Object value
Returns
Type Description
System.Int32

Insert(Int32, T)

Declaration
public virtual void Insert(int index, T item)
Parameters
Type Name Description
System.Int32 index
T item

Move(Int32, Int32)

Declaration
public virtual void Move(int index, int newIndex)
Parameters
Type Name Description
System.Int32 index
System.Int32 newIndex

Remove(T)

Declaration
public virtual bool Remove(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Boolean

RemoveAll(Predicate<T>)

Declaration
public virtual int RemoveAll(Predicate<T> match)
Parameters
Type Name Description
System.Predicate<T> match
Returns
Type Description
System.Int32

RemoveAll(Predicate<T>, out ImmutableList<T>)

Removes all elements by match and returns removed elements in output parameter. This operation is atomic and ensures that all returned elements belonging to this remove operation. In example if you do something like

var l = items.ToList(); /* items may be added or removed */ items.RemoveAll(predicate); /* items may be added or removed */ var removed = l.Except(items);

then you may have inconsistent results where in removed will be items which was added since call to RemoveAll or removed since call to ToList and may match the predicate or you may miss some removed items if they added after call to ToList or added back to items since call to RemoveAll.

Declaration
public virtual void RemoveAll(Predicate<T> match, out ImmutableList<T> removed)
Parameters
Type Name Description
System.Predicate<T> match
System.Collections.Immutable.ImmutableList<T> removed

RemoveAt(Int32)

Removes an element but doesnt return it (needed for implementing IList).

Declaration
public void RemoveAt(int index)
Parameters
Type Name Description
System.Int32 index

RemoveAtAndReturn(Int32)

Remove the indexed element atomically and return it.

Declaration
public virtual T RemoveAtAndReturn(int index)
Parameters
Type Name Description
System.Int32 index
Returns
Type Description
T

RemoveFirst(Predicate<T>)

Removes first item matching the matcher. Returns true if item was removed.

Declaration
public virtual bool RemoveFirst(Predicate<T> matcher)
Parameters
Type Name Description
System.Predicate<T> matcher
Returns
Type Description
System.Boolean

RemoveNulls()

Declaration
public bool RemoveNulls()
Returns
Type Description
System.Boolean

RemoveRange(IEnumerable<T>)

Declaration
public virtual bool RemoveRange(IEnumerable<T> items)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> items
Returns
Type Description
System.Boolean

Set(IEnumerable<T>)

Declaration
public virtual void Set(IEnumerable<T> items)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> items

SetAt(Int32, T)

Declaration
public virtual void SetAt(int index, T obj)
Parameters
Type Name Description
System.Int32 index
T obj

Sort()

Declaration
public virtual void Sort()

Sort(IComparer<T>)

Declaration
public virtual void Sort(IComparer<T> comparer)
Parameters
Type Name Description
System.Collections.Generic.IComparer<T> comparer

Sort(Comparison<T>)

Declaration
public virtual void Sort(Comparison<T> comparison)
Parameters
Type Name Description
System.Comparison<T> comparison

Sort(Int32, Int32, IComparer<T>)

Declaration
public virtual void Sort(int index, int count, IComparer<T> comparer)
Parameters
Type Name Description
System.Int32 index
System.Int32 count
System.Collections.Generic.IComparer<T> comparer

ToArray()

Makes atomic ToArray operation. It isn't safe to use System.Linq.Enumerable.ToArray``1(System.Collections.Generic.IEnumerable{``0}), because it gets Count as a separate operation (and count may be modified in between).

Declaration
public T[] ToArray()
Returns
Type Description
T[]

ToList()

Makes atomic ToList operation. It isn't safe to use System.Linq.Enumerable.ToList``1(System.Collections.Generic.IEnumerable{``0}), because it gets Count as a separate operation (and count may be modified in between).

Declaration
public List<T> ToList()
Returns
Type Description
System.Collections.Generic.List<T>

WithSnapshot(Action<IReadOnlyList<T>>)

Same as WithSnapshot<TResult>(Func<IReadOnlyList<T>, TResult>) but for action.

Declaration
public void WithSnapshot(Action<IReadOnlyList<T>> action)
Parameters
Type Name Description
System.Action<System.Collections.Generic.IReadOnlyList<T>> action

Action to execute with read-only list.

WithSnapshot<TResult>(Func<IReadOnlyList<T>, TResult>)

Allows to execute action with immutable list for thread-safe calculations I.e. you may want to get Count first and then make some calculations based on number of elements. For separate Count and GetEnumerator operations you may have state changed between these two calls.

Declaration
public TResult WithSnapshot<TResult>(Func<IReadOnlyList<T>, TResult> action)
Parameters
Type Name Description
System.Func<System.Collections.Generic.IReadOnlyList<T>, TResult> action

Function to execute with read-only list.

Returns
Type Description
TResult
Type Parameters
Name Description
TResult

Result of function applied to immutable list.

Explicit Interface Implementations

ISnapshotable.Snapshot

Declaration
ICollection ISnapshotable.Snapshot { get; }
Returns
Type Description
System.Collections.ICollection

ISnapshotable<T>.Snapshot

Declaration
ICollection<T> ISnapshotable<T>.Snapshot { get; }
Returns
Type Description
System.Collections.Generic.ICollection<T>

Implements

System.Collections.Generic.IList<>
System.Collections.Generic.ICollection<>
System.Collections.Generic.IEnumerable<>
System.Collections.IEnumerable
System.Collections.IList
System.Collections.ICollection
System.Collections.Generic.IReadOnlyList<>
System.Collections.Generic.IReadOnlyCollection<>
ISnapshotable<T>
ISnapshotable

Extension Methods

PropertyChanges.FirePropertyChanged(Object, String)
PropertyChanges.FirePropertyChanged(Object, String, Object, Object)
PropertyChanges.FirePropertyChanged(Object, MemberChangedBeforeAfterEventArgs)
☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾