Table of Contents

AdjustmentPolicyBuilder Class

Definition

Namespace
Bodu.Globalization.Calendar.Builder
Assembly
Bodu.Globalization.Calendar.Builder.dll
Package
Bodu.Globalization.Calendar.Builder 1.0.0
Source
AdjustmentPolicyBuilder.cs

Provides a fluent surface for authoring a reusable adjustment policy: its scope, the trigger that activates it, the action it performs, the emission mode of the resulting occurrence, and any custom handler parameters.

public sealed class AdjustmentPolicyBuilder
Inheritance
AdjustmentPolicyBuilder
Inherited Members
Extension Methods

Examples

// "If the holiday lands on a weekend, move it to the next working day and emit only the observed date."
builder.AddAdjustmentPolicy("weekend-roll", p => p
    .When(AdjustmentTrigger.IfWeekend)
    .Then(AdjustmentAction.MoveToNextWorkingDay)
    .SkipNonWorkingDates()
    .Emit(EmissionMode.ObservedOnly)
    .WithReason("Observed (weekend roll-forward)"));

Remarks

A policy reads as a sentence: When a trigger holds, Then perform an action, and Emit the resulting occurrence in the chosen mode. Configure the builder inside AddAdjustmentPolicy(string, Action<AdjustmentPolicyBuilder>) and reference the policy from a rule with WithAdjustment(string).

Methods

Emit(EmissionMode)

Sets the emission mode of the resulting occurrence.

public AdjustmentPolicyBuilder Emit(EmissionMode mode)

Parameters

mode EmissionMode

The emission mode.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

EmitNonWorking(bool)

Sets whether the emitted occurrence is a non-working day.

public AdjustmentPolicyBuilder EmitNonWorking(bool value = true)

Parameters

value bool

The emission non-working flag.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

OnTriggerWeekdays(params DayOfWeek[])

Replaces the weekdays attached to the trigger with the supplied collection.

public AdjustmentPolicyBuilder OnTriggerWeekdays(params DayOfWeek[] days)

Parameters

days DayOfWeek[]

The weekdays on which the trigger fires.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentNullException

days is null.

SkipNonWorkingDates(bool)

Sets whether the action skips other non-working dates while searching.

public AdjustmentPolicyBuilder SkipNonWorkingDates(bool value = true)

Parameters

value bool

The skip-non-working-dates flag.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

SkipWeekends(bool)

Sets whether the action skips weekends while searching.

public AdjustmentPolicyBuilder SkipWeekends(bool value = true)

Parameters

value bool

The skip-weekends flag.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Then(AdjustmentAction)

Sets the action type the policy performs when triggered.

public AdjustmentPolicyBuilder Then(AdjustmentAction type)

Parameters

type AdjustmentAction

The action type.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

When(AdjustmentTrigger)

Sets the trigger type that activates the policy.

public AdjustmentPolicyBuilder When(AdjustmentTrigger type)

Parameters

type AdjustmentTrigger

The trigger type.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

WithActionDayOfWeek(DayOfWeek)

Sets the target weekday for weekday-seeking actions.

public AdjustmentPolicyBuilder WithActionDayOfWeek(DayOfWeek dayOfWeek)

Parameters

dayOfWeek DayOfWeek

The target weekday.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

WithActionDays(int)

Sets the signed day offset applied by an add-days action.

public AdjustmentPolicyBuilder WithActionDays(int days)

Parameters

days int

The day offset.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

WithActionHandlerKey(string)

Sets the custom-handler key used by a custom action.

public AdjustmentPolicyBuilder WithActionHandlerKey(string handlerKey)

Parameters

handlerKey string

The custom action handler key.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentException

handlerKey is null, empty, or white-space.

WithDescription(string)

Sets the human-readable description of the policy.

public AdjustmentPolicyBuilder WithDescription(string description)

Parameters

description string

The description text.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentNullException

description is null.

WithMaxSearchDays(int)

Sets the maximum number of days an action searches before giving up.

public AdjustmentPolicyBuilder WithMaxSearchDays(int maxSearchDays)

Parameters

maxSearchDays int

The search horizon in days.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentOutOfRangeException

maxSearchDays is less than 1.

WithParameter(string, string)

Adds or replaces a custom handler parameter.

public AdjustmentPolicyBuilder WithParameter(string key, string value)

Parameters

key string

The parameter key.

value string

The parameter value.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentException

key is null, empty, or white-space.

ArgumentNullException

value is null.

WithPriority(int)

Sets the priority of the policy.

public AdjustmentPolicyBuilder WithPriority(int priority)

Parameters

priority int

The numeric priority.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

WithReason(string)

Sets the reason attached to the emitted occurrence.

public AdjustmentPolicyBuilder WithReason(string reason)

Parameters

reason string

The emission reason.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentNullException

reason is null.

WithReplacementRule(string, string?)

Sets the replacement rule reference for a replace-with-rule action.

public AdjustmentPolicyBuilder WithReplacementRule(string notableDateRef, string? ruleRef = null)

Parameters

notableDateRef string

The identifier of the replacement concept.

ruleRef string

The identifier of the replacement rule, or null.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentException

notableDateRef is null, empty, or white-space.

WithScope(Action<AdjustmentScopeBuilder>)

Configures the scope of the policy through the supplied delegate.

public AdjustmentPolicyBuilder WithScope(Action<AdjustmentScopeBuilder> configure)

Parameters

configure Action<AdjustmentScopeBuilder>

A delegate that configures the scope.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentNullException

configure is null.

WithTriggerDay(int)

Sets the comparison day used by day-sensitive triggers.

public AdjustmentPolicyBuilder WithTriggerDay(int day)

Parameters

day int

The day of the month.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentOutOfRangeException

day is outside 1 to 31.

WithTriggerHandlerKey(string)

Sets the custom-handler key used by a custom trigger.

public AdjustmentPolicyBuilder WithTriggerHandlerKey(string handlerKey)

Parameters

handlerKey string

The custom trigger handler key.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentException

handlerKey is null, empty, or white-space.

WithTriggerMonth(int)

Sets the comparison month used by month-sensitive triggers.

public AdjustmentPolicyBuilder WithTriggerMonth(int month)

Parameters

month int

The one-based month number.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Exceptions

ArgumentOutOfRangeException

month is outside 1 to 12.

WithTriggerWeekOrdinal(WeekOrdinal)

Sets the week ordinal used by occurrence-sensitive triggers.

public AdjustmentPolicyBuilder WithTriggerWeekOrdinal(WeekOrdinal weekOrdinal)

Parameters

weekOrdinal WeekOrdinal

The week ordinal.

Returns

AdjustmentPolicyBuilder

The same AdjustmentPolicyBuilder instance, enabling chained calls.

Applies to

ProductVersions
.NET8, 10

See Also