NotableDateAlgorithmRegistry Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
A mutable registry of custom INotableDateAlgorithm implementations keyed by algorithm key.
public sealed class NotableDateAlgorithmRegistry : INotableDateAlgorithmRegistry
- Inheritance
-
NotableDateAlgorithmRegistry
- Implements
- Inherited Members
- Extension Methods
Examples
NotableDateAlgorithmRegistry registry = new NotableDateAlgorithmRegistry()
.Register("contoso.march-equinox", new MarchEquinoxAlgorithm())
.Register("contoso.harvest-moon", new HarvestMoonAlgorithm());
NotableDateResource resource = NotableDateResourceLoader.Load(documentXml, _ => null, registry);
NotableDateService service = new(resource, new NotableDateServiceOptions { Algorithms = registry });
Remarks
Keys are matched ordinally and are case-sensitive, mirroring the engine's built-in algorithm keys. Registering a key that is already present replaces the previous algorithm.
When to use. Populate a registry with custom INotableDateAlgorithm implementations, then pass it to NotableDateResourceLoader (so a document may reference the keys during validation) and to the NotableDateService (so they resolve at query time).
Thread safety. Lookups are lock-free and safe to run concurrently with registrations: each Register(string, INotableDateAlgorithm) publishes a new immutable snapshot atomically, so a reader observes either the state before or after a registration, never a torn intermediate. Prefer populating the registry before sharing it with a live service; registrations performed afterwards become visible to in-flight resolutions at snapshot granularity.
Constructors
NotableDateAlgorithmRegistry()
public NotableDateAlgorithmRegistry()
Methods
Contains(string)
Determines whether an algorithm is registered under the supplied key.
public bool Contains(string key)
Parameters
keystringThe algorithm key.
Returns
Exceptions
- ArgumentNullException
keyis null.
Register(string, INotableDateAlgorithm)
Registers an algorithm under a key, replacing any existing registration.
public NotableDateAlgorithmRegistry Register(string key, INotableDateAlgorithm algorithm)
Parameters
keystringThe algorithm key the strategy references.
algorithmINotableDateAlgorithmThe algorithm implementation.
Returns
- NotableDateAlgorithmRegistry
The same registry, to allow chaining.
Exceptions
- ArgumentNullException
keyoralgorithmis null.
TryGet(string, out INotableDateAlgorithm?)
Attempts to retrieve the algorithm registered under the supplied key.
public bool TryGet(string key, out INotableDateAlgorithm? algorithm)
Parameters
keystringThe algorithm key.
algorithmINotableDateAlgorithmWhen this method returns, the registered algorithm, or null when none.
Returns
Exceptions
- ArgumentNullException
keyis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |