Attributes

Every public Bevel attribute with its arguments, properties, targets and the diagnostics it can raise.

On this page
samples/Bevel.SampleBlog/Data/Posts/BlogPost.cscsharp
[DataSource("Posts", "./**/*.md", OrderBy = "Date desc, Title")]
[Process<DropDrafts>(Order = -1)]
[Process<PostStats>]
public sealed record BlogPost(
    [Unique(IgnoreCase = true)] string Slug,
    string Title,
    [GroupByDate("Archive", GroupPeriod.Month)]
    DateOnly Date,
    string Summary,
    [GroupBy("Tags")] string[] Tags,
    [GroupBy("Categories")] string Category,
    bool Featured,
    [Reference("Authors")] Author Author,
    string RawMarkdown,
    [Process<FirstParagraph>(nameof(RawMarkdown))]
    string Excerpt = "",
    // Optional list reference: front matter `contributors: [ada]`; absent means null (see PostPage).
    [Reference("Authors", Required = false)]
    IReadOnlyList<Author>? Contributors = null,
    int WordCount = 0,
    int ReadingMinutes = 0,
    bool Draft = false);

You describe your data with attributes. Bevel reads them during dotnet build and generates the typed ISiteData. All attributes live in the Bevel namespace. using Bevel; is added for you when ImplicitUsings is on (see MSBuild.BevelImplicitUsings).

Attribute Goes on Use it to
[DataSource] Record or class Load a file or folder into a dataset.
[DataSet] Loader class Name a dataset written as a loader.
[DependsOn] Item type or loader Load other datasets first.
[LoadOrder] Loader class Break ties among ready loaders.
[Reference] Property or parameter Resolve a key into an item from another dataset.
[Unique] Property or parameter Make a value unique across a list.
[GroupBy] and friends Property or parameter Turn a member into a dataset of groups.
[Process<T>] Member or item type Compute values at build time.
[PostProcess<T>] Item type Process a whole list once.
[Model] Page parameter Pick which parameter receives the item.
[NoLayout] Page component Skip the default layout.

Bevel also emits [BevelDataRegistration] and [BevelDataStats] into your assembly. They are generated code. You never write them.

DataSource

csharp
[DataSource("Authors", "./authors.json")]
public sealed record Author(string Id, string Name);

Declares a dataset loaded from a file or folder. Targets: class or struct. You can repeat it on one type, once per dataset.

Member Type Meaning
Name (ctor) string Property name on ISiteData.
Path (ctor) string File or folder. ./x is relative to the .cs file. Anything else is relative to the project root. Wildcards such as ./**/*.md are allowed in the last segment.
Element string? XML only: the element name of each list item.
OrderBy string? List datasets: members to sort by, each optionally asc or desc, such as "Date desc, Title".
LoadOrder int Tie-breaker among datasets that are ready to run. Lower runs first.

The file extension picks the format: .json, .yaml/.yml, .xml, .md/.markdown, plus any extension you register with an IBevelFormatReader (see Teach Bevel a new format). An unknown extension fails with BEVEL098. A folder means Markdown documents. A root array gives a list. A root object gives a single item.

A member is required unless it has a default value, is nullable, or is one Bevel fills (Slug, SourcePath, RawMarkdown). Bevel has no [Required] attribute. A missing value fails with BEVEL092.

Diagnostics: BEVEL012, BEVEL053, BEVEL092, BEVEL098, BEVEL099, BEVEL100.

DataSet

csharp
[DataSet("Metrics")]
public sealed class BlogMetricsLoader : IBevelDataLoader<BlogMetrics> { /* ... */ }

Marks a loader class as a dataset. The optional Name overrides the property name on ISiteData. Use it to resolve a name clash too (BEVEL012).

DependsOn

csharp
[DataSource("Pages", "Data/Docs/**/*.md")]
[DependsOn("Diagnostics")]
public sealed record Page(string Title /* ... */);

Names datasets that must load first. You can repeat it or pass several names. It works on loaders and on [DataSource] item types, so a post-processor can read other datasets with ctx.Get<T>("Name"). Group datasets are named Posts.Tags.

Diagnostics: BEVEL010, BEVEL011.

LoadOrder

csharp
[LoadOrder(1)]
public sealed class SiteLoader : IBevelDataLoader<Site> { /* ... */ }

Takes one int. Lower values load first, but only among datasets whose dependencies are done. Dependencies always win (BEVEL020). On a [DataSource], use the LoadOrder property instead.

Reference

csharp
[Reference("Authors")] Author Author,
[Reference("Authors", Required = false)] IReadOnlyList<Author>? Contributors = null,

Resolves a key from your data into the matching item of another dataset. The target dataset becomes a dependency on its own. Targets: property or constructor parameter.

Member Default Meaning
Dataset (ctor) none Name of the referenced list dataset.
From {member}Id, then {member} The key name in your source file.
Key Id The key member on the referenced item.
Required true When true, a missing key or an unknown id fails the build.

It works on Markdown, JSON and YAML datasets. A reference to the member's own dataset fails with BEVEL094. Store the keys and look the items up when the page renders.

Diagnostics: BEVEL013, BEVEL052, BEVEL078, BEVEL088, BEVEL094.

Unique

csharp
[Unique(IgnoreCase = true)] string Slug,

Requires the value to be unique across a list dataset. Bevel checks it after processors, on the final values, and skips null. Targets: property or constructor parameter.

Member Default Meaning
IgnoreCase false Compare strings without case. A case-only match is then an error. Strings only.

Without IgnoreCase, values that differ only by case give a warning, BEVEL089, because they can overwrite each other as file names on macOS and Windows.

Diagnostics: BEVEL079, BEVEL089, BEVEL090, BEVEL091.

Group attributes

csharp
[GroupByDate("Archive", GroupPeriod.Month)] DateOnly Date,
[GroupBy("Tags")] string[] Tags,
[GroupBy("Categories")] string Category,

Each group attribute turns one member into a dataset of groups on the parent collection, such as data.Posts.Tags. Bevel generates a group type for it (BlogPostGroups.Tag). Put exactly one group attribute on a member. All of them target a property or constructor parameter.

Attribute Member type Arguments
[GroupBy(name)] string, string[], lists of strings name
[GroupByDate(name, period)] DateOnly, DateTime, DateTimeOffset and nullable forms name, GroupPeriod (Year, Month, Day), Format
[GroupByFlag(name, trueText = "Yes", falseText = "No")] bool, bool? name, trueText, falseText
[GroupBy<TGrouper>(name)] anything name, a class implementing IGrouper<TValue, TGroupValue> under Data/

All four share these properties.

Property Default Meaning
TypeName Singular of name (Tags gives Tag) Name of the generated group type.
Key Slug, then Id The member that identifies the item. Must be unique in the parent.
Source none Parent dataset name. Needed only when several datasets use the item type.
OrderBy "Count desc, Text" for text; "Value desc" for dates and flags Order of the groups. Use Text, Slug, Value or Count.

[GroupByDate] also has Format, a .NET date format applied to Value for Text. It does not change the slug. Text groups merge by slug, ignoring case, and keep the first spelling.

Diagnostics: BEVEL060 to BEVEL077.

Process

csharp
// Member form: compute one member from another.
[Process<FirstParagraph>(nameof(RawMarkdown))] string Excerpt = "",

// Record form: on the item type, may set several members.
[Process<DropDrafts>(Order = -1)]
[Process<PostStats>]
public sealed record BlogPost(/* ... */);

Computes values at build time. Targets: property, parameter, class or struct. You can repeat it.

Form Constructor Processor implements
Member [Process<T>(string source)] IProcessor<TSource, TResult>
Record [Process<T>] IProcessor<TItem>
Member Meaning
Source Name of the member handed to the processor. null for the record form.
Order Record form only. Lower runs first. Ties keep source order.

Processors are created from the build-time services and must live under Data/. Order is: bind, member processors, record processors, then OrderBy, [Unique] and groups. A record processor can return ProcessResult.Remove to drop an item.

Diagnostics: BEVEL081 to BEVEL088, BEVEL093.

PostProcess

csharp
[DataSource("Pages", "Data/Docs/**/*.md")]
[PostProcess<PageNav>(Order = 0)]
public sealed record Page(string Title /* ... */);
Since 0.3

Runs an IDatasetProcessor<TItem> once, after every item is loaded and processed, and before OrderBy, [Unique] and groups. Use it for navigation, cross-references and link checks. Target: class or struct, repeatable. List datasets only.

Member Meaning
Order Lower runs first. Ties keep source order.

Diagnostics: BEVEL096, BEVEL097.

Model

razor
[Parameter, Model] public BlogPost Post { get; set; } = default!;

Add [Model] to the one [Parameter] that receives the item when a page component has several parameters of a type the item fits. Target: property.

NoLayout

razor
@attribute [NoLayout]

Add it to a page component to skip BevelOptions.DefaultLayout. Target: class. See BevelOptions.DefaultLayout.