Core Feature
Source Generators
Eliminate magic strings. Type-safe View names and Element IDs at compile time.
The Problem
HTMX development relies on string identifiers: view names, element IDs, event names. Typos cause silent failures.
❌ Brittle and typo-prone
.AlsoUpdate("product-list", "_ProductList", items)
The Solution
Swap.Htmx includes C# Source Generators that scan your project at compile time and generate type-safe constants—zero configuration required.
Type-Safe Views
Generated automatically from Views folder
public static class SwapViews
{
public static class Products
{
public const string List = "List";
public const string _Card = "_Card";
}
}
✅ No more typos
return SwapView(SwapViews.Products.List);
Type-Safe Element IDs
Generated from id="..." attributes
public static class SwapElements
{
public const string ProductGrid = "product-grid";
public const string CartCount = "cart-count";
}
Benefits
- Compile-Time Safety: Typos become build errors, not runtime bugs
- Full IntelliSense: Autocomplete for all views and IDs
- Zero Runtime Cost: All generation happens during build
- Refactor Fearlessly: Rename a view? Compiler tells you everywhere it's used
Generated Classes
- SwapViews
- SwapElements
- [SwapEventSource]
Scanned Folders
- Views/
- Pages/
- Modules/