NamedListWithDefault<T>

public sealed class NamedListWithDefault<T>
A list of named values with one unnamed value always available.
T

Constructors

NamedListWithDefault

#
public NamedListWithDefault(T unnamedDefault, StringComparison comparison)
Create a new list with an unnamed default value.
unnamedDefault (T)Initial default value.
comparison (StringComparison)Comparison to use for names.

Properties

Count

#
public int Count { get; }
Gets the number of values, not including the unnamed value.

Named

#
public IDictionary<string, T> Named { get; }
Gets the underlying dictionary of named values.

Names

#
public IEnumerable<string> Names { get; }
Iterate over all names.

Unnamed

#
public T Unnamed { get; set; }
Gets or sets the unnamed default.

Indexers

this[]

#
public (string name, T value) this[int index] { get; }
Gets the indexed value. Zero represents the unnamed value, higher integers index the named list.
index (int)

this[]

#
public T this[string name] { get; set; }
Gets or sets the named value. If name is null or empty, the unnamed value is returned or set. If the name conflicts with an existing name, the old value will be overwritten.
name (string)

Methods

TryGet

#
public bool TryGet(string name, out T value)
Try and retrieve one of the values.
name (string)
value (out T)

TryRemove

#
public bool TryRemove(string name)
Try and remove the named value. Note that the unnamed value cannot be removed, you can only change the value it has.
name (string)