Required values and Unique
Make members optional with defaults or nullable types, and fail the build on duplicate slugs with Unique.
On this page
public sealed record Guide(
[Unique(IgnoreCase = true)] string Slug,
string Title,
string Summary = "",
string? Subtitle = null);
Required and optional values
Every format (JSON, YAML, XML, Markdown) is strict. A value without a default and without ? is required. A missing one fails the build with BEVEL092. Give the parameter a default (string Summary = "") or make it nullable (string? Summary) to make it optional.
- Optional: a constructor parameter with a default value, a nullable member (
string?,int?), members Bevel fills (Slug,SourcePath,RawMarkdownfor Markdown),[Reference]members (they have their ownRequiredsetting) and[Process]members. - Required: any other constructor parameter, and
requiredproperties. Anullfor a non-nullable member counts as missing. - When the item type has a record-level
[Process], the check before processing is skipped, because the processor completes the item. - After all processors ran, any non-nullable reference-type member (
string, arrays, lists, classes) that is stillnullfails with BEVEL092.[Reference]members are exempt. Value types are not checked, since a default cannot be told from a value.
Unique values
[Unique] requires a member's value to be unique across a list dataset. Put it on a constructor parameter or a property. It works on any [DataSource] list: Markdown, JSON, YAML and XML. Datasets from C# loaders are not checked.
public sealed record Post([Unique(IgnoreCase = true)] string Slug, [Unique] string Title, string RawMarkdown);
- A duplicate fails the build with BEVEL079:
Dataset 'Posts': 'Slug' value 'intro' is used by 'a.md' and 'guides/intro/index.md'.Item names are theSourcePathwhen the record has one, elseitem #n. IgnoreCasedefaults tofalse. Strings compare withOrdinal, orOrdinalIgnoreCasewhen true. Other types use their default equality.IgnoreCase = trueon a non-string member fails with BEVEL091.- Several members can be
[Unique]. Each is checked on its own. - The check runs after processors and
OrderBy, on the final values. Null values are skipped. - Without
IgnoreCase,Introandintroare different values. Bevel warns with BEVEL089 because file names and URLs built from them overwrite each other on Windows and macOS. It is a real MSBuild warning at the attribute, soWarningsAsErrorsworks. UseIgnoreCase = truefor slugs. [Unique]on a single-object dataset fails with BEVEL090.- Declare it in one place, like the other member attributes (BEVEL078).