Class BindableCollection<T>
- Namespace
- Acuit.Pinpoint.Configuration
- Assembly
- Acuit.Pinpoint.Configuration.dll
A generic collection that works better with configuration binding (i.e., via ConfigurationBinder or MonitoredOptions<TOptions>), by allowing default values to be specified but that can be overridden via configuration settings.
public class BindableCollection<T> : Collection<T>, IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
T
The type of elements in the collection.
- Inheritance
-
Collection<T>BindableCollection<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- Inherited Members
Remarks
The configuration settings binder works with regular collections (i.e., objects that derive from ICollection<T>) by always adding values to it, so if the collection in the strongly-typed object contains default items, the items specified via configuration will be appended to the list of default items instead of replacing them. This class will cause items specified via configuration to replace any default items.
Note that the default items must be specified via one of the constructor overrides that accept default items, and not via collection initializers, since collection initializers simply cause the collection's Add(T) method to be called.
Note that there is currently no way to have a collection with default items and then override via configuration with an empty collection.
Constructors
BindableCollection()
Initializes a new instance of the BindableCollection<T> class.
public BindableCollection()
BindableCollection(IEnumerable<T>)
Initializes a new instance of the BindableCollection<T> class.
public BindableCollection(IEnumerable<T> defaults)
Parameters
defaults
IEnumerable<T>The default items for the collection.
Exceptions
- ArgumentNullException
defaults
is null.
BindableCollection(params T[])
Initializes a new instance of the BindableCollection<T> class.
public BindableCollection(params T[] defaults)
Parameters
defaults
T[]The default items for the collection.
Exceptions
- ArgumentNullException
defaults
is null.
Methods
InsertItem(int, T)
Inserts an element into the collection at the specified index.
protected override void InsertItem(int index, T item)
Parameters
index
intThe zero-based index at which item should be inserted.
item
TThe object to insert. The value can be null for reference types.