Search Results for

    Show / Hide Table of Contents

    Class ThreadSafeListHandler<T>

    Inheritance
    Object
    ThreadSafeListHandler<T>
    Implements
    IList<T>
    ICollection<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Sdl.LanguagePlatform.TranslationMemoryApi.LiteBCM.Collection
    Assembly: Sdl.LanguagePlatform.TranslationMemoryApi.dll
    Syntax
    public class ThreadSafeListHandler<T> : IList<T>, ICollection<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
    Type Parameters
    Name Description
    T

    Generic type for the items

    Constructors

    ThreadSafeListHandler(IEnumerable<T>, Func<T, IEnumerable<T>, (Boolean IsValid, String ErrorReason)>, Boolean)

    A Thread-Safe handler wrapping a given List. It manipulates the list directly, in a thread safe way. NOTE: If the list is manipulated without the handler, you can still have concurrency issues. All handling should be done through this component!

    Declaration
    public ThreadSafeListHandler(IEnumerable<T> items, Func<T, IEnumerable<T>, (bool IsValid, string ErrorReason)> itemValidator = null, bool allowDefault = false)
    Parameters
    Type Name Description
    IEnumerable<T> items

    The list to be manipulated through the handler in a synchronized thread-safe way.

    Func<T, IEnumerable<T>, (T1, T2)<Boolean, String>> itemValidator

    Optional validator for the items to be enforced on setting, adding or inserting items. Does not verify the items at construction time.

    Boolean allowDefault

    Tells if items in the list are allowed to have the type's default value.

    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when the provided items are null.

    ThreadSafeListHandler(Func<T, IEnumerable<T>, (Boolean IsValid, String ErrorReason)>, Boolean)

    A Thread-Safe handler for a collection of items. Starts with an empty collection.

    Declaration
    public ThreadSafeListHandler(Func<T, IEnumerable<T>, (bool IsValid, string ErrorReason)> itemValidator = null, bool allowDefault = false)
    Parameters
    Type Name Description
    Func<T, IEnumerable<T>, (T1, T2)<Boolean, String>> itemValidator

    Optional validator for the items to be enforced on setting, adding or inserting items. Does not verify the items at construction time.

    Boolean allowDefault

    Tells if items in the list are allowed to have the type's default value.

    Exceptions
    Type Condition
    System.ArgumentNullException

    Properties

    Count

    Gets the number of elements in the collection.

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

    IsReadOnly

    Tells if the collection is read-only. Always returns false.

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

    Item[Int32]

    Gets or sets an item at the specified index. Throws an exception if the index is out of bounds.

    Declaration
    public T this[int index] { get; set; }
    Parameters
    Type Name Description
    Int32 index

    Index for the desired item.

    Property Value
    Type Description
    T

    The item at the given index.

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    Thrown if index is out of bounds of the collection.

    Items

    The items, not protected by any locking mechanisms. Should not be iterated on - use GetSafeArrayClone instead. Should only be used if more complex manipulation is needed that is not available through the handler. Must use SyncRoot for locking! This is the exposing the same exact reference provided in the constructor of the handler.

    Declaration
    public List<T> Items { get; }
    Property Value
    Type Description
    List<T>

    SyncRoot

    The object used for the locking mechanism that keeps the backing list operations synchronized.

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

    Methods

    Add(T)

    Adds an item to the collection. Throws an exception if the item is invalid.

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

    The item to be added if it passes validation rules of the collection.

    Clear()

    Removes all the items from the collection.

    Declaration
    public void Clear()

    Contains(T)

    Tells if the collection contains a given item.

    Declaration
    public bool Contains(T item)
    Parameters
    Type Name Description
    T item

    The item to be searched.

    Returns
    Type Description
    Boolean

    True if the item is found in the collection. False otherwise.

    CopyTo(T[], Int32)

    Copies the items of the collection to an array, starting at a given index.

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

    Array where to copy items to.

    Int32 arrayIndex

    Index in the array where to start the copying from.

    GetEnumerator()

    Gets an enumerator that can be used to iterate the collection.

    Declaration
    public IEnumerator<T> GetEnumerator()
    Returns
    Type Description
    IEnumerator<T>

    An enumerator that can be used to iterate the collection.

    GetSafeClone()

    Generates an array clone obtained in a thread safe way. Should be used for enumeration instead of the original list. Manipulating the result will not change the original list.

    Declaration
    public List<T> GetSafeClone()
    Returns
    Type Description
    List<T>

    A snapshot of the backing list.

    IndexOf(T)

    Gets the index of a given item in the collection.

    Declaration
    public int IndexOf(T item)
    Parameters
    Type Name Description
    T item

    Item to be searched in the collection.

    Returns
    Type Description
    Int32

    The index of the item in the collection. -1 if not found.

    Insert(Int32, T)

    Inserts an item at a given index. Throws an exception if the item is invalid or if the index is out of bounds.

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

    Index where to insert the given item.

    T item

    Item to be inserted at the given index.

    Remove(T)

    Removes a given item from the collection, if found.

    Declaration
    public bool Remove(T item)
    Parameters
    Type Name Description
    T item

    Item to be removed.

    Returns
    Type Description
    Boolean

    True if the item was removed. False otherwise.

    RemoveAt(Int32)

    Removes an item at a given index.

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

    Index for the item that needs to be removed.

    Explicit Interface Implementations

    IEnumerable.GetEnumerator()

    Declaration
    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    IEnumerator

    Implements

    System.Collections.Generic.IList<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IReadOnlyCollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    In this article
    Back to top Generated by DocFX