Class RouteValuesCollection
Represents a three-phase, mutable, insertion-ordered collection of route parameter key-value pairs used to bridge URL generation and matching with IRouteParamsModel<TSelf> implementations.
Namespace: Singulink.UI.Navigation
Assembly: Singulink.UI.Navigation.dll
Syntax
public sealed class RouteValuesCollection : IEnumerable<(string Key, string Value)>, IEnumerable
Remarks
The collection progresses through three states:
- Building (initial): Add<T>(string, T), Reserve(string), and AddQuery(RouteQuery) may be called. Each call to Add<T>(string, T) or Reserve(string) reserves the key so that a subsequent AddQuery(RouteQuery) cannot add a conflicting entry; such a conflict throws. AddQuery(RouteQuery) transitions the collection to the Consuming state.
- Consuming: entered via AddQuery(RouteQuery) or automatically on the first call to any consume or read member (TryConsume<T>(string, out T?), enumerators, etc.). Further Add<T>(string, T), Reserve(string), and AddQuery(RouteQuery) calls throw.
- Done: entered when ConsumeQuery() is called. All remaining entries are captured into a RouteQuery and the collection is fully exhausted. Count, consume methods, and enumerators all throw in this state.
Instances are not thread-safe.
Constructors
| Name | Description |
|---|---|
| RouteValuesCollection() | Initializes a new instance of the RouteValuesCollection class in the Building state. |
| RouteValuesCollection(int) | Initializes a new instance of the RouteValuesCollection class in the Building state with the specified initial capacity. |
Properties
| Name | Description |
|---|---|
| Count | Gets the number of entries currently in the collection. |
Methods
| Name | Description |
|---|---|
| AddQuery(RouteQuery) | Adds all entries from the specified RouteQuery and transitions the collection to the Consuming state. Throws if any entry's key has already been reserved by Add<T>(string, T) or Reserve(string). |
| Add<T>(string, T) | Adds a parameter entry and reserves the specified key so that a subsequent AddQuery(RouteQuery) cannot add a conflicting entry. |
| ConsumeQuery() | Returns all remaining entries as a RouteQuery and transitions the collection to the Done state. No further members may be accessed after this call. |
| GetEnumerator() | Returns an enumerator that iterates through the collection. |
| Reserve(string) | Reserves the specified key without adding an entry, so that a subsequent AddQuery(RouteQuery) cannot add an entry with a matching key. Intended for optional named parameters whose current value is null. |
| TryConsume<T>(string, out T?) | Tries to consume (parse and remove) the entry with the specified key. Returns false if the key is not found or parsing fails. Transitions the collection to the Consuming state if it is not already. |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IEnumerable.GetEnumerator() | Returns an enumerator that iterates through a collection. |