NotableDateDocumentBuilder Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Builder
- Assembly
- Bodu.Globalization.Calendar.Builder.dll
- Package
- Bodu.Globalization.Calendar.Builder 1.0.0
Provides a fluent, chainable API for authoring a Bodu notable-date document on the notable-date schema, with full-fidelity XML serialization, a JSON-subset surface, and materialization into a NotableDateResource through the canonical loader.
public sealed class NotableDateDocumentBuilder
- Inheritance
-
NotableDateDocumentBuilder
- Inherited Members
- Extension Methods
Examples
NotableDateResource resource = NotableDateDocumentBuilder.Create("contoso-holidays")
.AddAdjustmentPolicy("weekend-roll", p => p
.When(AdjustmentTrigger.IfWeekend)
.Then(AdjustmentAction.MoveToNextWorkingDay)
.Emit(EmissionMode.ObservedOnly))
.AddNotableDate("christmas", "Christmas Day", NotableDateCategory.PublicHoliday, c => c
.AsNonWorkingByDefault()
.AddRule("fixed", r => r
.Fixed(12, 25)
.WithAdjustment("weekend-roll")))
.Build();
NotableDateService service = new(resource);
// The same model serializes to XML or JSON for storage or distribution.
NotableDateDocumentBuilder builder = NotableDateDocumentBuilder.Create("contoso-holidays")
.AddNotableDate("new-year", "New Year's Day", NotableDateCategory.PublicHoliday, c => c
.AddRule("fixed", r => r.Fixed(1, 1)));
string xml = builder.ToXml();
string json = builder.ToJson();
Remarks
The builder accumulates an in-memory model of the document. Calling ToXml() or Build()
renders the model to XML in the urn:bodu:globalization:calendar namespace; building then loads that XML
through NotableDateResourceLoader, which remains the single source of validation and assembly. The
XML form expresses every feature of the schema, whereas the JSON form rendered by ToJson() is
restricted to the subset the companion JSON schema can represent.
Workflow. Obtain a builder with Create() or Create(string, string), declare reusable adjustment policies with AddAdjustmentPolicy(string, Action<AdjustmentPolicyBuilder>), add each notable-date concept with AddNotableDate(string, string, NotableDateCategory, Action<NotableDateDefinitionBuilder>), then terminate by materializing a NotableDateResource with Build(), serializing with ToXml() / ToJson() / Save(string), or wrapping the result with ToProvider().
Methods
AddAdjustmentPolicy(string, Action<AdjustmentPolicyBuilder>)
Adds a reusable adjustment policy and configures it through the supplied delegate.
public NotableDateDocumentBuilder AddAdjustmentPolicy(string id, Action<AdjustmentPolicyBuilder> configure)
Parameters
idstringThe stable identifier of the policy.
configureAction<AdjustmentPolicyBuilder>A delegate that configures the policy.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
idis null, empty, or white-space.- ArgumentNullException
configureis null.
AddImport(string, Action<ImportBuilder>?)
Adds an import of an external resource and optionally configures its Use directives.
public NotableDateDocumentBuilder AddImport(string resource, Action<ImportBuilder>? configure = null)
Parameters
resourcestringThe name of the imported resource.
configureAction<ImportBuilder>A delegate that configures the import, or null.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
resourceis null, empty, or white-space.
AddNotableDate(string, string, NotableDateCategory, Action<NotableDateDefinitionBuilder>)
Adds a notable-date concept and configures it through the supplied delegate.
public NotableDateDocumentBuilder AddNotableDate(string id, string displayName, NotableDateCategory category, Action<NotableDateDefinitionBuilder> configure)
Parameters
idstringThe stable identifier of the concept.
displayNamestringThe human-readable display name of the concept.
categoryNotableDateCategoryThe category of the concept.
configureAction<NotableDateDefinitionBuilder>A delegate that configures the concept.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
idordisplayNameis null, empty, or white-space.- ArgumentNullException
configureis null.
AddOverride(Action<OverrideBuilder>)
Adds override operations through the supplied delegate, appending to any previously configured overrides.
public NotableDateDocumentBuilder AddOverride(Action<OverrideBuilder> configure)
Parameters
configureAction<OverrideBuilder>A delegate that configures the override operations.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
configureis null.
Build()
Materializes the document into a validated NotableDateResource through the canonical loader.
public NotableDateResource Build()
Returns
- NotableDateResource
The loaded and validated NotableDateResource.
Exceptions
- InvalidOperationException
The document is incomplete: the resource identifier is missing, a concept has no rules, a rule has no strategy, or an adjustment policy is missing a trigger, action, or emission.
- NotableDateValidationException
The loader produced one or more error diagnostics.
Build(Func<string, string?>?)
Materializes the document into a validated NotableDateResource, resolving imports through the supplied resolver.
public NotableDateResource Build(Func<string, string?>? importResolver)
Parameters
importResolverFunc<string, string>A delegate mapping a resource name to its XML or JSON content, or null to resolve no imports.
Returns
- NotableDateResource
The loaded and validated NotableDateResource.
Exceptions
- InvalidOperationException
The document is incomplete: the resource identifier is missing, a concept has no rules, a rule has no strategy, or an adjustment policy is missing a trigger, action, or emission.
- NotableDateValidationException
The loader produced one or more error diagnostics.
Clone()
Creates a deep copy of this document builder.
public NotableDateDocumentBuilder Clone()
Returns
- NotableDateDocumentBuilder
A new NotableDateDocumentBuilder carrying an independent copy of the document model.
Create()
Creates an empty document builder with no resource identifier configured.
public static NotableDateDocumentBuilder Create()
Returns
Create(string, string)
Creates a document builder with the supplied resource identifier and schema version.
public static NotableDateDocumentBuilder Create(string resourceId, string schemaVersion = "1.0")
Parameters
resourceIdstringThe resource identifier of the document.
schemaVersionstringThe schema version emitted on the root element.
Returns
Exceptions
- ArgumentException
resourceIdorschemaVersionis null, empty, or white-space.
FromJson(string)
Parses a JSON string into a builder.
public static NotableDateDocumentBuilder FromJson(string json)
Parameters
jsonstringThe notable-date document JSON content.
Returns
- NotableDateDocumentBuilder
A new NotableDateDocumentBuilder populated from the JSON.
Examples
// Round-trip a document through its JSON-subset form, then materialize a resource.
NotableDateDocumentBuilder original = NotableDateDocumentBuilder.Create("contoso-holidays")
.AddNotableDate("new-year", "New Year's Day", NotableDateCategory.PublicHoliday, c => c
.AddRule("fixed", r => r.Fixed(1, 1)));
string json = original.ToJson();
NotableDateDocumentBuilder reparsed = NotableDateDocumentBuilder.FromJson(json);
NotableDateResource resource = reparsed.Build();
Exceptions
- ArgumentException
jsonis null, empty, or white-space.- FormatException
jsonis not well-formed or is not a notable-date document.
FromJsonObject(JsonObject)
Parses a JsonObject into a builder.
public static NotableDateDocumentBuilder FromJsonObject(JsonObject json)
Parameters
jsonJsonObjectThe notable-date document JSON object.
Returns
- NotableDateDocumentBuilder
A new NotableDateDocumentBuilder populated from the object.
Exceptions
- ArgumentNullException
jsonis null.
FromXDocument(XDocument)
Parses an XDocument into a builder.
public static NotableDateDocumentBuilder FromXDocument(XDocument document)
Parameters
documentXDocumentThe notable-date document.
Returns
- NotableDateDocumentBuilder
A new NotableDateDocumentBuilder populated from the document.
Exceptions
- ArgumentNullException
documentis null.- FormatException
The root element is not a notable-date resource element.
FromXml(string)
Parses an XML document into a builder.
public static NotableDateDocumentBuilder FromXml(string xml)
Parameters
xmlstringThe notable-date document XML content.
Returns
- NotableDateDocumentBuilder
A new NotableDateDocumentBuilder populated from the XML.
Examples
// Round-trip a document through its XML form: serialize, then re-parse into an equivalent builder.
NotableDateDocumentBuilder original = NotableDateDocumentBuilder.Create("contoso-holidays")
.AddNotableDate("new-year", "New Year's Day", NotableDateCategory.PublicHoliday, c => c
.AddRule("fixed", r => r.Fixed(1, 1)));
string xml = original.ToXml();
NotableDateDocumentBuilder reparsed = NotableDateDocumentBuilder.FromXml(xml);
NotableDateResource resource = reparsed.Build();
Exceptions
- ArgumentException
xmlis null, empty, or white-space.- FormatException
xmlis not well-formed or is not a notable-date document.
Load(string)
Reads a document from a file and parses it into a builder, inferring the format from the file extension.
public static NotableDateDocumentBuilder Load(string path)
Parameters
pathstringThe source file path. A
.xmlextension reads XML; a.jsonextension reads JSON.
Returns
- NotableDateDocumentBuilder
A new NotableDateDocumentBuilder populated from the file.
Exceptions
- ArgumentException
pathis null, empty, white-space, or has an unrecognized extension.- FormatException
The file content is not a well-formed notable-date document.
Save(string)
Serializes the document to a file, inferring the format from the file extension.
public void Save(string path)
Parameters
pathstringThe destination file path. A
.xmlextension writes XML; a.jsonextension writes JSON.
Examples
NotableDateDocumentBuilder builder = NotableDateDocumentBuilder.Create("contoso-holidays")
.AddNotableDate("new-year", "New Year's Day", NotableDateCategory.PublicHoliday, c => c
.AddRule("fixed", r => r.Fixed(1, 1)));
// The extension selects the format: .xml writes XML, .json writes JSON.
builder.Save("contoso-holidays.xml");
builder.Save("contoso-holidays.json");
// Reload the document later and build a service over it.
NotableDateResource resource = NotableDateDocumentBuilder.Load("contoso-holidays.xml").Build();
Exceptions
- ArgumentException
pathis null, empty, white-space, or has an unrecognized extension.- InvalidOperationException
The document is incomplete.
- NotSupportedException
A JSON target is requested but the document uses a feature the JSON subset cannot represent.
Save(string, NotableDateDocumentFormat)
Serializes the document to a file in the specified format.
public void Save(string path, NotableDateDocumentFormat format)
Parameters
pathstringThe destination file path.
formatNotableDateDocumentFormatThe serialization format.
Exceptions
- ArgumentException
pathis null, empty, or white-space.- InvalidOperationException
The document is incomplete.
- NotSupportedException
A JSON target is requested but the document uses a feature the JSON subset cannot represent.
- NotableDateValidationException
A binary target is requested and the document produced one or more error diagnostics.
SaveBinary(Stream, Func<string, string?>?)
Compiles the document to a sealed binary rule pack written to a stream.
public void SaveBinary(Stream stream, Func<string, string?>? importResolver = null)
Parameters
streamStreamThe writable stream receiving the pack.
importResolverFunc<string, string>A delegate mapping a resource name to its XML or JSON content, or null to resolve no imports.
Exceptions
- ArgumentNullException
streamis null.- InvalidOperationException
The document is incomplete.
- NotableDateValidationException
The document produced one or more error diagnostics.
SaveBinary(string)
Compiles the document to a sealed binary rule pack on disk.
public void SaveBinary(string path)
Parameters
pathstringThe destination file path, conventionally with the
.bcalextension.
Remarks
The document is materialized through Build() first, so only content that passed the canonical loader's validation is ever encoded; the pack then loads via LoadBinary(Stream) without re-parsing or re-validating.
Exceptions
- ArgumentException
pathis null, empty, or white-space.- InvalidOperationException
The document is incomplete.
- NotableDateValidationException
The document produced one or more error diagnostics.
SaveBinary(string, Func<string, string?>?)
Compiles the document to a sealed binary rule pack on disk, resolving imports through the supplied resolver.
public void SaveBinary(string path, Func<string, string?>? importResolver)
Parameters
pathstringThe destination file path, conventionally with the
.bcalextension.importResolverFunc<string, string>A delegate mapping a resource name to its XML or JSON content, or null to resolve no imports.
Exceptions
- ArgumentException
pathis null, empty, or white-space.- InvalidOperationException
The document is incomplete.
- NotableDateValidationException
The document produced one or more error diagnostics.
ToJson()
Serializes the document to an indented JSON string in the JSON-subset form.
public string ToJson()
Returns
- string
The serialized JSON.
Exceptions
- InvalidOperationException
The document is incomplete.
- NotSupportedException
The document uses a feature the JSON subset cannot represent.
ToJsonObject()
Serializes the document to a JsonObject in the JSON-subset form.
public JsonObject ToJsonObject()
Returns
- JsonObject
The serialized JSON object.
Exceptions
- InvalidOperationException
The document is incomplete.
- NotSupportedException
The document uses a feature the JSON subset cannot represent.
ToProvider()
Materializes the document and wraps it in a mutable provider.
public INotableDateResourceProvider ToProvider()
Returns
- INotableDateResourceProvider
An INotableDateResourceProvider exposing the built resource.
Exceptions
- InvalidOperationException
The document is incomplete.
- NotableDateValidationException
The loader produced one or more error diagnostics.
ToXDocument()
Serializes the document to an XDocument in the urn:bodu:globalization:calendar namespace.
public XDocument ToXDocument()
Returns
- XDocument
The serialized document.
Exceptions
- InvalidOperationException
The document is incomplete.
ToXml()
Serializes the document to an indented XML string in the urn:bodu:globalization:calendar namespace.
public string ToXml()
Returns
- string
The serialized XML.
Exceptions
- InvalidOperationException
The document is incomplete.
TryBuild(out NotableDateResource?, out IReadOnlyList<NotableDateValidationDiagnostic>)
Attempts to materialize the document into a validated NotableDateResource, collecting every diagnostic instead of throwing on an invalid document.
public bool TryBuild(out NotableDateResource? resource, out IReadOnlyList<NotableDateValidationDiagnostic> diagnostics)
Parameters
resourceNotableDateResourceThe built resource, or null when the document does not validate.
diagnosticsIReadOnlyList<NotableDateValidationDiagnostic>Every diagnostic serialization and validation produced.
Returns
TryBuild(Func<string, string?>?, out NotableDateResource?, out IReadOnlyList<NotableDateValidationDiagnostic>)
Attempts to materialize the document into a validated NotableDateResource resolving imports through the supplied resolver, collecting every diagnostic instead of throwing on an invalid document.
public bool TryBuild(Func<string, string?>? importResolver, out NotableDateResource? resource, out IReadOnlyList<NotableDateValidationDiagnostic> diagnostics)
Parameters
importResolverFunc<string, string>A delegate mapping a resource name to its XML or JSON content, or null to resolve no imports.
resourceNotableDateResourceThe built resource, or null when the document does not validate.
diagnosticsIReadOnlyList<NotableDateValidationDiagnostic>Every diagnostic serialization and validation produced.
Returns
Validate()
Lints the document, returning every diagnostic the canonical loader's validation would produce - errors, warnings, and informational messages - without throwing.
public IReadOnlyList<NotableDateValidationDiagnostic> Validate()
Returns
- IReadOnlyList<NotableDateValidationDiagnostic>
The collected diagnostics; empty when the document is valid.
Remarks
Validation runs the same pipeline as Build() - the document is serialized to XML and passed
through NotableDateResourceLoader - so a clean result guarantees Build() succeeds
for the same document. A document too incomplete to serialize (a missing resource identifier, a concept with no
rules, a rule with no strategy) is reported as a BODU-CAL-BUILDER-INCOMPLETE error diagnostic rather than
an exception.
Validate(Func<string, string?>?)
Lints the document against the supplied import resolver, returning every diagnostic without throwing.
public IReadOnlyList<NotableDateValidationDiagnostic> Validate(Func<string, string?>? importResolver)
Parameters
importResolverFunc<string, string>A delegate mapping a resource name to its XML or JSON content, or null to resolve no imports.
Returns
- IReadOnlyList<NotableDateValidationDiagnostic>
The collected diagnostics; empty when the document is valid.
WithMetadata(string?, string?, params string[])
Sets the document metadata name, description, and sources.
public NotableDateDocumentBuilder WithMetadata(string? name = null, string? description = null, params string[] sources)
Parameters
namestringThe metadata name, or null to leave it unset.
descriptionstringThe metadata description, or null to leave it unset.
sourcesstring[]The metadata source entries.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
sourcesis null.
WithResolutionPolicy(Action<ResolutionPolicyBuilder>)
Configures the document-level resolution policy through the supplied delegate.
public NotableDateDocumentBuilder WithResolutionPolicy(Action<ResolutionPolicyBuilder> configure)
Parameters
configureAction<ResolutionPolicyBuilder>A delegate that configures the resolution policy.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
configureis null.
WithResourceId(string)
Sets the resource identifier of the document.
public NotableDateDocumentBuilder WithResourceId(string resourceId)
Parameters
resourceIdstringThe resource identifier.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
resourceIdis null, empty, or white-space.
WithSchemaVersion(string)
Sets the schema version emitted on the root element.
public NotableDateDocumentBuilder WithSchemaVersion(string schemaVersion)
Parameters
schemaVersionstringThe schema version.
Returns
- NotableDateDocumentBuilder
The same NotableDateDocumentBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
schemaVersionis null, empty, or white-space.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |