Class SchemaItemCollection<TItem>
Represents a collection of strongly typed schema items, providing functionality for indexing, addition, removal, and lookup based on item names. This collection is intended to manage schema items that inherit from the SchemaItem class.
public abstract class SchemaItemCollection<TItem> : List<TItem>, IList<TItem>, ICollection<TItem>, IReadOnlyList<TItem>, IReadOnlyCollection<TItem>, IEnumerable<TItem>, IList, ICollection, IEnumerable where TItem : SchemaItem
Type Parameters
TItemThe specific type of schema items contained in the collection.
- Inheritance
-
List<TItem>SchemaItemCollection<TItem>
- Implements
-
IList<TItem>ICollection<TItem>IReadOnlyList<TItem>IReadOnlyCollection<TItem>IEnumerable<TItem>
- Derived
- Inherited Members
Constructors
SchemaItemCollection()
Initializes a new instance of the SchemaItemCollection<TItem> class.
protected SchemaItemCollection()
SchemaItemCollection(IEnumerable<TItem>)
Initializes a new instance of the SchemaItemCollection<TItem> class with the specified collection of items.
protected SchemaItemCollection(IEnumerable<TItem> items)
Parameters
itemsIEnumerable<TItem>The collection of items to initialize the collection with.
SchemaItemCollection(int)
Initializes a new instance of the SchemaItemCollection<TItem> class with the specified initial capacity.
protected SchemaItemCollection(int capacity)
Parameters
capacityintThe initial number of elements that the collection can contain.
Properties
this[string]
Provides indexed access to schema items in the collection by their unique names. The indexer performs a lookup in the internal dictionary to retrieve the schema item that matches the given name.
public TItem this[string name] { get; }
Parameters
namestringThe unique name of the schema item to retrieve.
Property Value
- TItem
The schema item associated with the specified name.
Exceptions
- KeyNotFoundException
Thrown if the specified name does not exist in the collection.
Methods
Add(TItem)
Adds the specified item to the collection.
public void Add(TItem item)
Parameters
itemTItemThe item to add to the collection. Must not be null and must have a unique full name.
Exceptions
- ArgumentException
Thrown when an item with the same full name already exists in the collection.
- ArgumentNullException
Thrown when the provided item is null.
AddRange(IEnumerable<TItem>)
Adds a range of items to the collection.
public void AddRange(IEnumerable<TItem> items)
Parameters
itemsIEnumerable<TItem>An enumerable collection of items to add to the collection. Each item must not be null and must have a unique full name.
Exceptions
- ArgumentException
Thrown when one or more items in the collection have full names that already exist in the collection.
- ArgumentNullException
Thrown when the provided collection or any item in it is null.
Clear()
Removes all items from the SchemaItemCollection<TItem> and clears the internal dictionary used for name-based lookups.
public void Clear()
Contains(string)
Determines whether the collection contains an item with the specified name.
public bool Contains(string name)
Parameters
namestringThe name of the schema item to locate in the collection.
Returns
- bool
trueif an item with the specified name is found in the collection; otherwise,false.
IndexOf(string)
Returns the zero-based index of the schema item with the specified name within the collection.
public int IndexOf(string name)
Parameters
namestringThe name of the schema item to locate in the collection.
Returns
- int
The zero-based index of the schema item if found in the collection; otherwise, -1.
Remove(string)
Removes a schema item from the collection by its name.
public bool Remove(string name)
Parameters
namestringThe name of the schema item to remove from the collection. The item must exist within the collection.
Returns
- bool
trueif the schema item with the specified name was successfully removed from the collection; otherwise,false.
Remove(TItem)
Removes the specified schema item from the collection.
public bool Remove(TItem item)
Parameters
itemTItemThe schema item to remove from the collection. This item must exist within the collection.
Returns
- bool
trueif the specified schema item was successfully removed from the collection; otherwise,false.
RemoveRange(int, int)
Removes a range of schema items from the collection starting at the specified index.
public void RemoveRange(int index, int count)
Parameters
indexintThe zero-based starting index of the range of elements to remove. Must be within the bounds of the collection.
countintThe number of items to remove starting from the specified index. Must be non-negative and not exceed the available items from the index.
TryGetValue(string, out TItem)
Attempts to retrieve the schema item associated with the specified name from the collection.
public bool TryGetValue(string name, out TItem item)
Parameters
namestringThe name of the schema item to find in the collection.
itemTItemWhen this method returns, contains the schema item associated with the specified name, if the name is found, or null if the name is not found. This parameter is passed uninitialized.
Returns
- bool
trueif the collection contains an item with the specified name; otherwise,false.