Table of Contents

NotableDateAlgorithmRegistry Class

Definition

Namespace
Bodu.Globalization.Calendar.Algorithms
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
NotableDateAlgorithmRegistry.cs

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

key string

The algorithm key.

Returns

bool

true if an algorithm is registered; otherwise false.

Exceptions

ArgumentNullException

key is null.

Register(string, INotableDateAlgorithm)

Registers an algorithm under a key, replacing any existing registration.

public NotableDateAlgorithmRegistry Register(string key, INotableDateAlgorithm algorithm)

Parameters

key string

The algorithm key the strategy references.

algorithm INotableDateAlgorithm

The algorithm implementation.

Returns

NotableDateAlgorithmRegistry

The same registry, to allow chaining.

Exceptions

ArgumentNullException

key or algorithm is null.

TryGet(string, out INotableDateAlgorithm?)

Attempts to retrieve the algorithm registered under the supplied key.

public bool TryGet(string key, out INotableDateAlgorithm? algorithm)

Parameters

key string

The algorithm key.

algorithm INotableDateAlgorithm

When this method returns, the registered algorithm, or null when none.

Returns

bool

true if an algorithm was found; otherwise false.

Exceptions

ArgumentNullException

key is null.

Applies to

ProductVersions
.NET8, 10

See Also