Skip to content

Explore collection-initializer API (Option A') as alternative to fluent modifiers #9

Open

Description

Spec: docs/spec/019-collection-initializer-api-exploration.md

Today's fluent API mixes three syntaxes — .Method() chains, with { } for record props, and .Set(x => ...) as an escape hatch. Spec 019 explores Option A': new + object initializers + C# 12 collection expressions (Children = [..]). Same result, properties grouped, no .Set() escape hatch, spread works natively for dynamic children.

Example — TodoApp header

Today (fluent):

Text("todos").FontSize(36)
    .Set(t => t.FontWeight = FontWeights.Light)
    .Foreground(AccentText)
    .HAlign(HorizontalAlignment.Center)
    .Margin(0, 16, 0, 8)

Option A' (new + initializer):

new Text("todos") {
    FontSize = 36,
    Weight = FontWeights.Light,
    Foreground = AccentText,
    HAlign = HorizontalAlignment.Center,
    Margin = Thick(0, 16, 0, 8),
}

The FontWeight no longer needs .Set(), all properties sit in one { } block, and dynamic child lists become Children = [..items.Select(Render)] instead of .ToArray() into params.

See the spec for the full analysis across TodoApp, Outlook MessageRow, charts, and the comparison matrix vs. Options A/B/C/E.

Metadata

Metadata

Labels

design proposal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions