Search Results for

    Show / Hide Table of Contents

    Class ModelCollection<T>

    Represents a dynamic data collection that provides notification events when items get added or removed.

    Inheritance
    System.Object
    DynamicObject
    ModelCollection<T>
    Implements
    System.Dynamic.IDynamicMetaObjectProvider
    System.Collections.Generic.IList<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IList
    System.Collections.ICollection
    System.Collections.IEnumerable
    System.Collections.Specialized.INotifyCollectionChanged
    Inherited Members
    DynamicObject.SetMember(String, Object)
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: TimeCockpit.Data.DataModel
    Assembly: TimeCockpit.Data.dll
    Syntax
    public sealed class ModelCollection<T> : DynamicObject, IDynamicMetaObjectProvider, IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, INotifyCollectionChanged where T : NamedDynamicObject
    Type Parameters
    Name Description
    T

    The type of elements in the list.

    Remarks

    T has to be derived from NamedDynamicObject.

    ModelCollection<T> can be seen as a special kind of dictionary. The name of the model element (see Name) is used as the key. In fact the class uses an object of type System.Collections.Generic.Dictionary<TKey, TValue> internally. You can access model elements in the collection using their model element names (i.e. keys). Accessing the collection using integer indexes is currently not supported.

    Constructors

    ModelCollection()

    Initializes a new instance of the ModelCollection class.

    Declaration
    public ModelCollection()
    Exceptions
    Type Condition
    System.InvalidOperationException

    Occurs, when {T} is not of type NamedDynamicObject.

    Properties

    Count

    Gets the number of elements contained in the ModelCollection<T>.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    System.Int32
    Implements
    System.Collections.Generic.ICollection<T>.Count
    System.Collections.ICollection.Count

    IsReadOnly

    Gets a value indicating whether the ModelCollection<T> is read-only.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    System.Boolean
    Implements
    System.Collections.Generic.ICollection<T>.IsReadOnly
    System.Collections.IList.IsReadOnly

    Item[String]

    Gets or sets the element with the specified key.

    Declaration
    public T this[string key] { get; }
    Parameters
    Type Name Description
    System.String key

    The key of the element to get.

    Property Value
    Type Description
    T

    The element with the specified key.

    Methods

    Add(T)

    Adds an item to the ModelCollection<T>.

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

    The object to add to the ModelCollection<T>.

    Implements
    System.Collections.Generic.ICollection<T>.Add(T)
    Remarks

    The name of the model element is used as the item's key.

    Exceptions
    Type Condition
    System.ArgumentException

    Occurs, when the name of the item is not set, or an item is added to the collection twice.

    AddRange(IEnumerable<T>)

    Adds a collection of items and fires CollectionChanged once at the end of the operation.

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

    Items to add.

    Clear()

    Removes all items from the ModelCollection<T>.

    Declaration
    public void Clear()
    Implements
    System.Collections.Generic.ICollection<T>.Clear()
    System.Collections.IList.Clear()

    Contains(T)

    Determines whether the ModelCollection<T> contains a specific value.

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

    The object to locate in the ModelCollection<T>.

    Returns
    Type Description
    System.Boolean

    True if the item is found in the ModelCollection<T>, otherwise false.

    Implements
    System.Collections.Generic.ICollection<T>.Contains(T)

    Contains(String)

    Determines whether the ModelCollection<T> contains a specific value.

    Declaration
    public bool Contains(string item)
    Parameters
    Type Name Description
    System.String item

    The name of the object to locate in the ModelCollection<T>.

    Returns
    Type Description
    System.Boolean

    True if the item is found in the ModelCollection<T>, otherwise false.

    CopyTo(T[], Int32)

    Copies the elements of the ModelCollection<T> to an Array, starting at a particular System.Array index.

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

    The one-dimensional Array that is the destination of the elements copied from ModelCollection<T>. The System.Array must have zero-based indexing.

    System.Int32 arrayIndex

    The zero-based index in array at which copying begins.

    Implements
    System.Collections.Generic.ICollection<T>.CopyTo(T[], System.Int32)
    Exceptions
    Type Condition
    System.InvalidOperationException

    Copying of elements is not allowed in this collection.

    GetEnumerator()

    Returns an enumerator that iterates through a collection.

    Declaration
    public IEnumerator<T> GetEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<T>

    An System.Collections.IEnumerator object that can be used to iterate through the collection.

    Implements
    System.Collections.Generic.IEnumerable<T>.GetEnumerator()

    GetMember(String)

    Gets a member dynamically.

    Declaration
    public override object GetMember(string name)
    Parameters
    Type Name Description
    System.String name

    Name of the collection item to get.

    Returns
    Type Description
    System.Object

    Dynamic member.

    Overrides
    DynamicObject.GetMember(String)

    GetMetaObject(Expression)

    Gets the meta object of the dynamic object.

    Declaration
    public override DynamicMetaObject GetMetaObject(Expression parameter)
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression parameter

    Provided by the DLR (Dynamic Language Runtime).

    Returns
    Type Description
    System.Dynamic.DynamicMetaObject

    DynamicObject.DynamicMetaObject that represents this specific object’s binding logic.

    Overrides
    DynamicObject.GetMetaObject(Expression)

    IndexOf(T)

    Determines the index of a specific item in the ModelCollection<T>.

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

    The object to locate in the ModelCollection<T>.

    Returns
    Type Description
    System.Int32

    The index of item if found in the list; otherwise, -1.

    Implements
    System.Collections.Generic.IList<T>.IndexOf(T)
    Exceptions
    Type Condition
    System.InvalidOperationException

    Getting the index of an element is not allowed in this collection.

    Insert(Int32, T)

    Inserts an item to the ModelCollection<T> at the specified index.

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

    The zero-based index at which item should be inserted.

    T item

    The object to insert into the ModelCollection<T>.

    Implements
    System.Collections.Generic.IList<T>.Insert(System.Int32, T)
    Exceptions
    Type Condition
    System.InvalidOperationException

    Inserting items at a specified index is not allowed in this collection.

    Remove(T)

    Removes the first occurrence of a specific object from the ModelCollection<T>.

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

    The object to remove from the ModelCollection<T>.

    Returns
    Type Description
    System.Boolean

    True if the item was successfully removed, otherwise false. This method also returns false if item is not found in the ModelCollection<T>.

    Implements
    System.Collections.Generic.ICollection<T>.Remove(T)

    Remove(String)

    Removes the first occurrence of a specific object from the ModelCollection<T>.

    Declaration
    public bool Remove(string item)
    Parameters
    Type Name Description
    System.String item

    The name of the object to remove from the ModelCollection<T>.

    Returns
    Type Description
    System.Boolean

    True if the item was successfully removed, otherwise false. This method also returns false if item is not found in the ModelCollection<T>.

    Exceptions
    Type Condition
    System.Collections.Generic.KeyNotFoundException

    The specified item was not found in the collection.

    RemoveAt(Int32)

    Removes the ModelCollection<T> item at the specified index.

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

    The zero-based index of the item to remove.

    Implements
    System.Collections.Generic.IList<T>.RemoveAt(System.Int32)
    System.Collections.IList.RemoveAt(System.Int32)
    Exceptions
    Type Condition
    System.InvalidOperationException

    Removing elements by index is not allowed in this collection.

    TryGetValue(String, out T)

    Gets the value associated with the specified key. This method performs the lookup in the SYS, APP, USR order!

    Declaration
    public bool TryGetValue(string key, out T value)
    Parameters
    Type Name Description
    System.String key

    The key whose value to get.

    T value

    When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

    Returns
    Type Description
    System.Boolean

    true if the object that implements System.Collections.Generic.IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.

    TryGetValueInReverseOrder(String, out T)

    ATTENTION: This method performs the lookup in the SYS, APP, USR order and gets the value associated with the specified key. USE WITH CARE!

    Declaration
    public bool TryGetValueInReverseOrder(string key, out T value)
    Parameters
    Type Name Description
    System.String key

    The key whose value to get.

    T value

    When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

    Returns
    Type Description
    System.Boolean

    true if the object that implements System.Collections.Generic.IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.

    TryRemoveExactWithNotification(String)

    Tries to find an element with the exact name.

    Declaration
    public bool TryRemoveExactWithNotification(string name)
    Parameters
    Type Name Description
    System.String name

    the name to find.

    Returns
    Type Description
    System.Boolean

    returns true if the name of the item was contained, false otherwise.

    Events

    CollectionChanged

    Occurs when an item is added or removed.

    Declaration
    public event NotifyCollectionChangedEventHandler CollectionChanged
    Event Type
    Type Description
    System.Collections.Specialized.NotifyCollectionChangedEventHandler

    Explicit Interface Implementations

    IList<T>.get_Item(Int32)

    Declaration
    T IList<T>.get_Item(int index)
    Parameters
    Type Name Description
    System.Int32 index
    Returns
    Type Description
    T
    Implements
    System.Collections.Generic.IList<T>.get_Item(System.Int32)

    IList<T>.Item[Int32]

    Gets or sets the element at the specified index (CURRENTLY NOT IMPLEMENTED!)

    Declaration
    T IList<T>.this[] { get; set; }
    Parameters
    Type Name Description
    System.Int32 index

    The zero-based index of the element to get or set (CURRENTLY NOT USED!).

    Returns
    Type Description
    T

    The element at the specified index.

    Implements
    System.Collections.Generic.IList<T>.Item[System.Int32]
    Remarks

    This method is currently not implemented and therefore it always throws a System.NotImplementedException.

    Exceptions
    Type Condition
    System.NotImplementedException

    Always thrown because property is currently not implemented.

    IList<T>.set_Item(Int32, T)

    Declaration
    void IList<T>.set_Item(int index, T value)
    Parameters
    Type Name Description
    System.Int32 index
    T value
    Implements
    System.Collections.Generic.IList<T>.set_Item(System.Int32, T)

    ICollection.CopyTo(Array, Int32)

    Copies the elements of the ModelCollection<T> to an Array, starting at a particular System.Array index.

    Declaration
    void ICollection.CopyTo(Array array, int index)
    Parameters
    Type Name Description
    System.Array array

    The one-dimensional Array that is the destination of the elements copied from ModelCollection<T>. The System.Array must have zero-based indexing.

    System.Int32 index

    The zero-based index in array at which copying begins.

    Implements
    System.Collections.ICollection.CopyTo(System.Array, System.Int32)
    Exceptions
    Type Condition
    System.InvalidOperationException

    Copying of elements is not allowed in this collection.

    ICollection.IsSynchronized

    Gets a value indicating whether access to the ModelCollection<T> is synchronized (thread safe).

    Declaration
    bool ICollection.IsSynchronized { get; }
    Returns
    Type Description
    System.Boolean
    Implements
    System.Collections.ICollection.IsSynchronized

    ICollection.SyncRoot

    Gets an object that can be used to synchronize access to the ModelCollection<T>.

    Declaration
    object ICollection.SyncRoot { get; }
    Returns
    Type Description
    System.Object
    Implements
    System.Collections.ICollection.SyncRoot

    IEnumerable.GetEnumerator()

    Returns an enumerator that iterates through a collection.

    Declaration
    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    System.Collections.IEnumerator

    An System.Collections.IEnumerator object that can be used to iterate through the collection.

    Implements
    System.Collections.IEnumerable.GetEnumerator()

    IList.Add(Object)

    Adds an item to the ModelCollection<T>.

    Declaration
    int IList.Add(object value)
    Parameters
    Type Name Description
    System.Object value

    The object to add to the ModelCollection<T>.

    Returns
    Type Description
    System.Int32

    The position into which the new element was inserted.

    Implements
    System.Collections.IList.Add(System.Object)
    Exceptions
    Type Condition
    System.ArgumentException

    Occurs, when value is not of type {T}.

    IList.Contains(Object)

    Determines whether the ModelCollection<T> contains a specific value.

    Declaration
    bool IList.Contains(object value)
    Parameters
    Type Name Description
    System.Object value

    The object to locate in the ModelCollection<T>.

    Returns
    Type Description
    System.Boolean

    True if the item is found in the ModelCollection<T>, otherwise false.

    Implements
    System.Collections.IList.Contains(System.Object)
    Exceptions
    Type Condition
    System.ArgumentException

    Occurs, when value is not of type {T}.

    IList.get_Item(Int32)

    Declaration
    object IList.get_Item(int index)
    Parameters
    Type Name Description
    System.Int32 index
    Returns
    Type Description
    System.Object
    Implements
    System.Collections.IList.get_Item(System.Int32)

    IList.IndexOf(Object)

    Determines the index of a specific item in the ModelCollection<T>.

    Declaration
    int IList.IndexOf(object value)
    Parameters
    Type Name Description
    System.Object value

    The object to locate in the ModelCollection<T>.

    Returns
    Type Description
    System.Int32

    The index of item if found in the list; otherwise, -1.

    Implements
    System.Collections.IList.IndexOf(System.Object)
    Exceptions
    Type Condition
    System.InvalidOperationException

    Getting the index of an element is not allowed in this collection.

    IList.Insert(Int32, Object)

    Inserts an item to the ModelCollection<T> at the specified index.

    Declaration
    void IList.Insert(int index, object value)
    Parameters
    Type Name Description
    System.Int32 index

    The zero-based index at which item should be inserted.

    System.Object value

    The object to insert into the ModelCollection<T>.

    Implements
    System.Collections.IList.Insert(System.Int32, System.Object)
    Exceptions
    Type Condition
    System.InvalidOperationException

    Inserting items at a specified index is not allowed in this collection.

    IList.IsFixedSize

    Gets a value indicating whether the ModelCollection<T> has a fixed size.

    Declaration
    bool IList.IsFixedSize { get; }
    Returns
    Type Description
    System.Boolean
    Implements
    System.Collections.IList.IsFixedSize

    IList.Item[Int32]

    Gets or sets the element at the specified index (CURRENTLY NOT IMPLEMENTED!)

    Declaration
    object IList.this[] { get; set; }
    Parameters
    Type Name Description
    System.Int32 index

    The zero-based index of the element to get or set (CURRENTLY NOT USED!).

    Returns
    Type Description
    System.Object

    The element at the specified index.

    Implements
    System.Collections.IList.Item[System.Int32]
    Remarks

    This method is currently not implemented and therefore it always throws a System.NotImplementedException.

    Exceptions
    Type Condition
    System.NotImplementedException

    Always thrown because property is currently not implemented.

    IList.Remove(Object)

    Removes the first occurrence of a specific object from the ModelCollection<T>.

    Declaration
    void IList.Remove(object value)
    Parameters
    Type Name Description
    System.Object value

    The object to remove from the ModelCollection<T>.

    Implements
    System.Collections.IList.Remove(System.Object)
    Exceptions
    Type Condition
    System.ArgumentException

    Occurs, when value is not of type {T}.

    IList.set_Item(Int32, Object)

    Declaration
    void IList.set_Item(int index, object value)
    Parameters
    Type Name Description
    System.Int32 index
    System.Object value
    Implements
    System.Collections.IList.set_Item(System.Int32, System.Object)
    In This Article
    Back to top Copyright © 2020 software architects gmbh