AngelSix.ThemeEngine.SourceGen
1.1.1
dotnet add package AngelSix.ThemeEngine.SourceGen --version 1.1.1
NuGet\Install-Package AngelSix.ThemeEngine.SourceGen -Version 1.1.1
<PackageReference Include="AngelSix.ThemeEngine.SourceGen" Version="1.1.1" />
<PackageVersion Include="AngelSix.ThemeEngine.SourceGen" Version="1.1.1" />
<PackageReference Include="AngelSix.ThemeEngine.SourceGen" />
paket add AngelSix.ThemeEngine.SourceGen --version 1.1.1
#r "nuget: AngelSix.ThemeEngine.SourceGen, 1.1.1"
#:package AngelSix.ThemeEngine.SourceGen@1.1.1
#addin nuget:?package=AngelSix.ThemeEngine.SourceGen&version=1.1.1
#tool nuget:?package=AngelSix.ThemeEngine.SourceGen&version=1.1.1
AngelSix.ThemeEngine.SourceGen
A Roslyn source generator that emits strongly-typed Avalonia markup extensions for every public property on classes marked with [Theme] (from the AngelSix.ThemeEngine runtime library).
Most users want
AngelSix.ThemeEngineinstead. That package bundles this analyzer along with the runtime types — one install gets you both. Install this standalone only if you ship your own runtime side.
What it does
For a theme like:
using AngelSix.ThemeEngine;
using Avalonia;
using Avalonia.Media;
[Theme]
public class DefaultTheme
{
public Color ThemeColor1 => Color.Parse("#FFFFFFFF");
public SolidColorBrush ThemeColor1Brush => new(ThemeColor1);
public CornerRadius ControlCornerRadius => new(3);
// ...
}
the generator emits, at compile time:
public sealed class ThemeColor1Extension : ThemeValueExtension { /* ... */ }
public sealed class ThemeColor1BrushExtension : ThemeValueExtension { /* ... */ }
public sealed class ControlCornerRadiusExtension : ThemeValueExtension { /* ... */ }
So your XAML can bind theme values directly:
xmlns:theme="using:AngelSix.ThemeEngine.Generated"
...
<Setter Property="Background" Value="{theme:ThemeColor1Brush}" />
<Setter Property="CornerRadius" Value="{theme:ControlCornerRadius}" />
Each extension returns an Avalonia.Data.Binding whose source is ThemeContext.Active, so swapping ThemeContext.Active = new DarkTheme() re-themes every bound value instantly.
Install
dotnet add package AngelSix.ThemeEngine.SourceGen
NuGet wires the generator automatically — no OutputItemType="Analyzer" attribute needed. You also need a reference to the AngelSix.ThemeEngine runtime library (which defines ThemeAttribute, ThemeContext, and the ThemeValueExtension base — emitted at build time by this generator).
Verification
The generator emits a marker type AngelSix.ThemeEngine.Generated.__ThemeEngineGenerated unconditionally on first run. The runtime ThemeContext constructor reflects for it and throws an actionable error if the analyzer didn't load, so wiring problems surface immediately rather than as obscure XAML errors.
Changelog
- 1.1.0 — Switched to attribute-based discovery (
[Theme]) instead of detecting subclasses of the previousThemebase class. The marker +ThemeValueExtensionbase are now emitted unconditionally so the runtime wiring check passes the moment the analyzer is loaded, even before any[Theme]class is added.
License
MIT
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.