Table of Contents

StrategyResolutionContext Class

Definition

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

Provides a strategy with access to the surrounding resource so that referential strategies (such as OffsetFromRuleStrategy) can resolve the occurrence of another rule for the same year.

public sealed class StrategyResolutionContext
Inheritance
StrategyResolutionContext
Inherited Members
Extension Methods

Remarks

The context maintains an in-progress set keyed by rule identity so that a circular reference between offset rules resolves to null rather than recursing without end.

Constructors

StrategyResolutionContext(NotableDateResource)

Initializes a new instance of the StrategyResolutionContext class.

public StrategyResolutionContext(NotableDateResource resource)

Parameters

resource NotableDateResource

The resource that referential strategies resolve against.

Exceptions

ArgumentNullException

resource is null.

StrategyResolutionContext(NotableDateResource, INotableDateAlgorithmRegistry?, string?)

Initializes a new instance of the StrategyResolutionContext class with a custom algorithm registry.

public StrategyResolutionContext(NotableDateResource resource, INotableDateAlgorithmRegistry? algorithms, string? territory = null)

Parameters

resource NotableDateResource

The resource that referential strategies resolve against.

algorithms INotableDateAlgorithmRegistry

The custom algorithm registry, or null for built-ins only.

territory string

The territory being resolved, consulted by business-day strategies; defaults to an empty territory.

Exceptions

ArgumentNullException

resource is null.

Properties

Algorithms

Gets the custom algorithm registry consulted for keys the built-in catalogue does not recognize.

public INotableDateAlgorithmRegistry? Algorithms { get; }

Property Value

INotableDateAlgorithmRegistry

The registry, or null when only built-in algorithms are available.

Territory

Gets the territory being resolved, used by business-day strategies to determine non-working days.

public string Territory { get; }

Property Value

string

The territory code; an empty string when the context is not territory-scoped.

Methods

AddWorkingDays(DateOnly, int, string)

Moves a date by a signed number of working days for a territory, skipping non-working days.

public DateOnly? AddWorkingDays(DateOnly origin, int workingDays, string territory)

Parameters

origin DateOnly

The origin date, which is not counted as one of the offset working days.

workingDays int

The signed number of working days to move; positive forward, negative backward.

territory string

The territory whose non-working days apply.

Returns

DateOnly?

The resulting date, or null when the move would run past the representable date range.

IsWorkingDay(DateOnly, string)

Determines whether a date is a working day for a territory, using the resource's working-week pattern and every applicable non-working notable-date occurrence.

public bool IsWorkingDay(DateOnly date, string territory)

Parameters

date DateOnly

The date to test.

territory string

The territory whose non-working days apply.

Returns

bool

true when the date is a working day; otherwise false.

Remarks

The result is deterministic and independent of resource-declaration order: a non-working day is a rest day outside the working week, or a day claimed by a non-working rule's base occurrence (and its fixed-duration span).

A business-day strategy consulted while those non-working days are being built sees rest days only, so a non-working rule that counts working days resolves against the working week alone.

ReferenceIsRecurring(string, string?)

Determines whether a rule referenced by id resolves to a recurrence source, which cannot be used as a singular reference.

public bool ReferenceIsRecurring(string notableDateRef, string? ruleRef)

Parameters

notableDateRef string

The identifier of the referenced notable-date concept.

ruleRef string

The identifier of the referenced rule, or null to use its sole rule.

Returns

bool

true when the reference resolves to a rule whose occurrence source is a recurrence; otherwise false.

ResolveReference(string, string?, int)

Resolves the occurrence of a referenced rule for the supplied Gregorian year.

public DateOnly? ResolveReference(string notableDateRef, string? ruleRef, int year)

Parameters

notableDateRef string

The identifier of the referenced notable-date concept.

ruleRef string

The identifier of the referenced rule, or null to use its sole rule.

year int

The Gregorian year to resolve.

Returns

DateOnly?

The referenced occurrence, or null when the reference cannot be resolved (missing, ambiguous, circular, or producing no occurrence).

ResolveReferenceAll(string, string?, int)

Resolves every occurrence of a referenced rule for the supplied Gregorian year.

public IReadOnlyList<DateOnly> ResolveReferenceAll(string notableDateRef, string? ruleRef, int year)

Parameters

notableDateRef string

The identifier of the referenced notable-date concept.

ruleRef string

The identifier of the referenced rule, or null to use its sole rule.

year int

The Gregorian year to resolve.

Returns

IReadOnlyList<DateOnly>

The referenced occurrences in ascending chronological order; empty when the reference cannot be resolved (missing, ambiguous, circular, or producing no occurrence).

Remarks

A non-Gregorian anchor's short lunar month and day can recur twice in one Gregorian year, so a referential strategy that projects each anchor occurrence must resolve through this member rather than ResolveReference(string, string?, int), which yields only the year's first occurrence.

Applies to

ProductVersions
.NET8, 10