AdjustmentPolicyBuilder Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Builder
- Assembly
- Bodu.Globalization.Calendar.Builder.dll
- Package
- Bodu.Globalization.Calendar.Builder 1.0.0
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
modeEmissionModeThe 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
valueboolThe 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
daysDayOfWeek[]The weekdays on which the trigger fires.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
daysis null.
SkipNonWorkingDates(bool)
Sets whether the action skips other non-working dates while searching.
public AdjustmentPolicyBuilder SkipNonWorkingDates(bool value = true)
Parameters
valueboolThe 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
valueboolThe 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
typeAdjustmentActionThe 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
typeAdjustmentTriggerThe 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
dayOfWeekDayOfWeekThe 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
daysintThe 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
handlerKeystringThe custom action handler key.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
handlerKeyis null, empty, or white-space.
WithDescription(string)
Sets the human-readable description of the policy.
public AdjustmentPolicyBuilder WithDescription(string description)
Parameters
descriptionstringThe description text.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
descriptionis null.
WithMaxSearchDays(int)
Sets the maximum number of days an action searches before giving up.
public AdjustmentPolicyBuilder WithMaxSearchDays(int maxSearchDays)
Parameters
maxSearchDaysintThe search horizon in days.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
maxSearchDaysis less than 1.
WithParameter(string, string)
Adds or replaces a custom handler parameter.
public AdjustmentPolicyBuilder WithParameter(string key, string value)
Parameters
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
keyis null, empty, or white-space.- ArgumentNullException
valueis null.
WithPriority(int)
Sets the priority of the policy.
public AdjustmentPolicyBuilder WithPriority(int priority)
Parameters
priorityintThe 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
reasonstringThe emission reason.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
reasonis null.
WithReplacementRule(string, string?)
Sets the replacement rule reference for a replace-with-rule action.
public AdjustmentPolicyBuilder WithReplacementRule(string notableDateRef, string? ruleRef = null)
Parameters
notableDateRefstringThe identifier of the replacement concept.
ruleRefstringThe identifier of the replacement rule, or null.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
notableDateRefis 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
configureAction<AdjustmentScopeBuilder>A delegate that configures the scope.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
configureis null.
WithTriggerDay(int)
Sets the comparison day used by day-sensitive triggers.
public AdjustmentPolicyBuilder WithTriggerDay(int day)
Parameters
dayintThe day of the month.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
dayis outside 1 to 31.
WithTriggerHandlerKey(string)
Sets the custom-handler key used by a custom trigger.
public AdjustmentPolicyBuilder WithTriggerHandlerKey(string handlerKey)
Parameters
handlerKeystringThe custom trigger handler key.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
handlerKeyis null, empty, or white-space.
WithTriggerMonth(int)
Sets the comparison month used by month-sensitive triggers.
public AdjustmentPolicyBuilder WithTriggerMonth(int month)
Parameters
monthintThe one-based month number.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
monthis outside 1 to 12.
WithTriggerWeekOrdinal(WeekOrdinal)
Sets the week ordinal used by occurrence-sensitive triggers.
public AdjustmentPolicyBuilder WithTriggerWeekOrdinal(WeekOrdinal weekOrdinal)
Parameters
weekOrdinalWeekOrdinalThe week ordinal.
Returns
- AdjustmentPolicyBuilder
The same AdjustmentPolicyBuilder instance, enabling chained calls.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |