Class ModelCollection<T>
- Namespace
- TimeCockpit.Data.DataModel
- Assembly
- TimeCockpit.Data.dll
Represents a dynamic data collection that provides notification events when items get added or removed.
public sealed class ModelCollection<T> : DynamicObject, IDynamicMetaObjectProvider, IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, INotifyCollectionChanged where T : NamedDynamicObject
Type Parameters
TThe type of elements in the list.
- Inheritance
-
ObjectModelCollection<T>
- Implements
-
IDynamicMetaObjectProviderIList<T>ICollection<T>IEnumerable<T>IListICollectionIEnumerableINotifyCollectionChanged
- Inherited Members
-
Object.ToString()Object.Equals(Object)Object.Equals(Object, Object)Object.ReferenceEquals(Object, Object)Object.GetHashCode()Object.GetType()Object.MemberwiseClone()
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.
public ModelCollection()
Exceptions
- System.InvalidOperationException
Occurs, when {T} is not of type NamedDynamicObject.
Properties
Count
Gets the number of elements contained in the ModelCollection<T>.
public int Count { get; }
Property Value
- Int32
IsReadOnly
Gets a value indicating whether the ModelCollection<T> is read-only.
public bool IsReadOnly { get; }
Property Value
- Boolean
Item[String]
Gets or sets the element with the specified key.
public T this[string key] { get; }
Parameters
keyStringThe key of the element to get.
Property Value
- T
The element with the specified key.
Methods
Add(T)
Adds an item to the ModelCollection<T>.
public void Add(T item)
Parameters
itemTThe object to add to the ModelCollection<T>.
Remarks
The name of the model element is used as the item's key.
Exceptions
- 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.
public void AddRange(IEnumerable<T> items)
Parameters
itemsIEnumerable<T>Items to add.
Clear()
Removes all items from the ModelCollection<T>.
public void Clear()
Contains(T)
Determines whether the ModelCollection<T> contains a specific value.
public bool Contains(T item)
Parameters
itemTThe object to locate in the ModelCollection<T>.
Returns
- Boolean
True if the item is found in the ModelCollection<T>, otherwise false.
Contains(String)
Determines whether the ModelCollection<T> contains a specific value.
public bool Contains(string item)
Parameters
itemStringThe name of the object to locate in the ModelCollection<T>.
Returns
- 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.
public void CopyTo(T[] array, int arrayIndex)
Parameters
arrayT[]The one-dimensional Array that is the destination of the elements copied from ModelCollection<T>. The System.Array must have zero-based indexing.
arrayIndexInt32The zero-based index in array at which copying begins.
Exceptions
- System.InvalidOperationException
Copying of elements is not allowed in this collection.
GetEnumerator()
Returns an enumerator that iterates through a collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An System.Collections.IEnumerator object that can be used to iterate through the collection.
GetMember(String)
Gets a member dynamically.
public override object GetMember(string name)
Parameters
nameStringName of the collection item to get.
Returns
- Object
Dynamic member.
GetMetaObject(Expression)
Gets the meta object of the dynamic object.
public override DynamicMetaObject GetMetaObject(Expression parameter)
Parameters
parameterExpressionProvided by the DLR (Dynamic Language Runtime).
Returns
- DynamicMetaObject
DynamicObject.DynamicMetaObject that represents this specific object’s binding logic.
IndexOf(T)
Determines the index of a specific item in the ModelCollection<T>.
public int IndexOf(T item)
Parameters
itemTThe object to locate in the ModelCollection<T>.
Returns
- Int32
The index of item if found in the list; otherwise, -1.
Exceptions
- 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.
public void Insert(int index, T item)
Parameters
indexInt32The zero-based index at which item should be inserted.
itemTThe object to insert into the ModelCollection<T>.
Exceptions
- 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>.
public bool Remove(T item)
Parameters
itemTThe object to remove from the ModelCollection<T>.
Returns
- Boolean
True if the item was successfully removed, otherwise false. This method also returns false if item is not found in the ModelCollection<T>.
Remove(String)
Removes the first occurrence of a specific object from the ModelCollection<T>.
public bool Remove(string item)
Parameters
itemStringThe name of the object to remove from the ModelCollection<T>.
Returns
- 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
- System.Collections.Generic.KeyNotFoundException
The specified item was not found in the collection.
RemoveAt(Int32)
Removes the ModelCollection<T> item at the specified index.
public void RemoveAt(int index)
Parameters
indexInt32The zero-based index of the item to remove.
Exceptions
- 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!
public bool TryGetValue(string key, out T value)
Parameters
keyStringThe key whose value to get.
valueTWhen 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
- 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!
public bool TryGetValueInReverseOrder(string key, out T value)
Parameters
keyStringThe key whose value to get.
valueTWhen 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
- 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.
public bool TryRemoveExactWithNotification(string name)
Parameters
nameStringthe name to find.
Returns
- Boolean
returns true if the name of the item was contained, false otherwise.
Events
CollectionChanged
Occurs when an item is added or removed.
public event NotifyCollectionChangedEventHandler CollectionChanged
Event Type
- NotifyCollectionChangedEventHandler
Explicit Interface Implementations
IList<T>.get_Item(Int32)
T IList<T>.get_Item(int index)
Parameters
indexInt32
Returns
- T
IList<T>.Item[Int32]
Gets or sets the element at the specified index (CURRENTLY NOT IMPLEMENTED!)
T IList<T>.this[] { get; set; }
Parameters
indexInt32The zero-based index of the element to get or set (CURRENTLY NOT USED!).
Returns
- T
The element at the specified index.
Remarks
This method is currently not implemented and therefore it always throws a System.NotImplementedException.
Exceptions
- System.NotImplementedException
Always thrown because property is currently not implemented.
IList<T>.set_Item(Int32, T)
void IList<T>.set_Item(int index, T value)
Parameters
indexInt32valueT
ICollection.CopyTo(Array, Int32)
Copies the elements of the ModelCollection<T> to an Array, starting at a particular System.Array index.
void ICollection.CopyTo(Array array, int index)
Parameters
arrayArrayThe one-dimensional Array that is the destination of the elements copied from ModelCollection<T>. The System.Array must have zero-based indexing.
indexInt32The zero-based index in array at which copying begins.
Exceptions
- 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).
bool ICollection.IsSynchronized { get; }
Returns
- Boolean
ICollection.SyncRoot
Gets an object that can be used to synchronize access to the ModelCollection<T>.
object ICollection.SyncRoot { get; }
Returns
- Object
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through a collection.
IEnumerator IEnumerable.GetEnumerator()
Returns
- IEnumerator
An System.Collections.IEnumerator object that can be used to iterate through the collection.
IList.Add(Object)
Adds an item to the ModelCollection<T>.
int IList.Add(object value)
Parameters
valueObjectThe object to add to the ModelCollection<T>.
Returns
- Int32
The position into which the new element was inserted.
Exceptions
- System.ArgumentException
Occurs, when value is not of type {T}.
IList.Contains(Object)
Determines whether the ModelCollection<T> contains a specific value.
bool IList.Contains(object value)
Parameters
valueObjectThe object to locate in the ModelCollection<T>.
Returns
- Boolean
True if the item is found in the ModelCollection<T>, otherwise false.
Exceptions
- System.ArgumentException
Occurs, when value is not of type {T}.
IList.get_Item(Int32)
object IList.get_Item(int index)
Parameters
indexInt32
Returns
- Object
IList.IndexOf(Object)
Determines the index of a specific item in the ModelCollection<T>.
int IList.IndexOf(object value)
Parameters
valueObjectThe object to locate in the ModelCollection<T>.
Returns
- Int32
The index of item if found in the list; otherwise, -1.
Exceptions
- 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.
void IList.Insert(int index, object value)
Parameters
indexInt32The zero-based index at which item should be inserted.
valueObjectThe object to insert into the ModelCollection<T>.
Exceptions
- 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.
bool IList.IsFixedSize { get; }
Returns
- Boolean
IList.Item[Int32]
Gets or sets the element at the specified index (CURRENTLY NOT IMPLEMENTED!)
object IList.this[] { get; set; }
Parameters
indexInt32The zero-based index of the element to get or set (CURRENTLY NOT USED!).
Returns
- Object
The element at the specified index.
Remarks
This method is currently not implemented and therefore it always throws a System.NotImplementedException.
Exceptions
- 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>.
void IList.Remove(object value)
Parameters
valueObjectThe object to remove from the ModelCollection<T>.
Exceptions
- System.ArgumentException
Occurs, when value is not of type {T}.
IList.set_Item(Int32, Object)
void IList.set_Item(int index, object value)
Parameters
indexInt32valueObject