Class CompositePatternBuilder<T>
A builder for composite patterns.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Inherited Members
Namespace: NodaTime.Text
Assembly: NodaTime.dll
Syntax
public sealed class CompositePatternBuilder<T> : IEnumerable<IPattern<T>>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of value to be parsed or formatted by the resulting pattern. |
Remarks
A composite pattern is a combination of multiple patterns. When parsing, these are checked
in the order in which they are added to the builder with the Add(IPattern<T>, Func<T, bool>)
method, by trying to parse and seeing if the result is a successful one. When formatting,
the patterns are checked in the reverse order, using the predicate provided along with the pattern
when calling
Add
. The intention is that patterns are added in "most precise first" order,
and the predicate should indicate whether it can fully represent the given value - so the "less precise"
(and therefore usually shorter) pattern can be used first.Constructors
CompositePatternBuilder()
Constructs a new instance which initially has no component patterns. At least one component
pattern must be added before Build() is called.
Since 2.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public CompositePatternBuilder()
Methods
Add(IPattern<T>, Func<T, bool>)
Adds a component pattern to this builder.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public void Add(IPattern<T> pattern, Func<T, bool> formatPredicate)
Parameters
Type | Name | Description |
---|---|---|
IPattern<T> | pattern | The component pattern to use as part of the eventual composite pattern. |
Func<T, bool> | formatPredicate | A predicate to determine whether or not this pattern is suitable for formatting the given value. |
Build()
Builds a composite pattern from this builder. Further changes to this builder
will have no impact on the returned pattern.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public IPattern<T> Build()
Returns
Type | Description |
---|---|
IPattern<T> | A pattern using the patterns added to this builder. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | No component patterns have been added. |
Explicit Interface Implementations
IEnumerable<IPattern<T>>.GetEnumerator()
Returns an enumerator that iterates through the collection.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
IEnumerator<IPattern<T>> IEnumerable<IPattern<T>>.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<IPattern<T>> | An enumerator that can be used to iterate through the collection. |
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through a collection.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator object that can be used to iterate through the collection. |