CSX Compiler
UltimateUI.Components.SourceGen reads *.uui.csx AdditionalFiles and turns
CSX return expressions inside C# methods into ordinary element construction code.
<ProjectReference Include="..\..\src\UltimateUI.Components.SourceGen\UltimateUI.Components.SourceGen.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<AdditionalFiles Include="WelcomeCard.uui.csx" />
using System;
using UltimateUI;
using UltimateUI.Components;
using UltimateUI.Events;
namespace MyApp.Views;
public static partial class WelcomeCard
{
public static Element Render(ComponentContext context, string title, int count, EventHandler<ClickEventArgs>? onClick)
{
var caption = $"Clicked {count}";
return (
<div className="card">
<h1>{title}</h1>
<button onClick={onClick}>{caption}</button>
</div>
);
}
}
Generated usage:
var element = WelcomeCard.Render(context, "CSX", 3, OnClick);
Supported today: C# using directives, file-scoped namespaces, partial classes,
C# method signatures whose first parameter is ComponentContext context,
ordinary C# statements before the CSX return, one XML-like root element, text
interpolation, attribute interpolation, children, onClick={handler} /
onInput={handler} event bindings, and {rows} insertion from an
IEnumerable<Element>. All attribute names must be camelCase and cannot contain
-; use ariaLabel, htmlFor, and onClick, not aria-label, html-for, or
on-click. PascalCase tags are function component calls, so <CounterView />
emits CounterView.Render(context).
The old top-level component / function declarations, class=,
hyphenated attributes such as on-click="handler" and aria-label="...", and
<slot name="rows" /> syntax have been removed.