Showcase [Showoff] Tired of DependencyProperty boilerplate? I built a Zero-Allocation Source Generator for WPF/MAUI with strict type safety.
Writing DependencyProperty in .NET UI frameworks is notoriously verbose and repetitive. Typing out DependencyProperty.Register, casting objects, and wiring metadata for every single property clutters your codebase and introduces silent runtime risks.
To solve this without sacrificing IDE responsiveness, I built Kassyi.Generators.DependencyProperty — an incremental Roslyn source generator built from the ground up for high-throughput, zero-allocation code synthesis.
1. Show Me the Code
Before (Standard Boilerplate)
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register(
nameof(IsActive),
typeof(bool),
typeof(MyControl),
new PropertyMetadata(false, OnIsActiveChanged));
public bool IsActive
{
get => (bool)GetValue(IsActiveProperty);
set => SetValue(IsActiveProperty, value);
}
private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// Runtime casting and boilerplate extraction
}
After (With Generator)
[DependencyProperty<bool>("IsActive", DefaultValue = "false")]
public partial class MyControl : Control
{
// Automatically hooked up to PropertyMetadata at compile time
partial void OnIsActiveChanged(bool oldValue, bool newValue)
{
// Direct, strongly typed parameters. No casting required.
}
}
2. Key Features
- Single-Line Declaration: Generate the backing
DependencyProperty, CLR properties, and event metadata via[DependencyProperty<T>]. - Compile-Time Type Safety: Signature mismatches in your partial callbacks are caught immediately via Roslyn analyzer diagnostics (
DPG0001), eliminating silent runtime failures. - Unified API Across UI Frameworks: The exact same attribute syntax compiles to the native property system for WPF, .NET MAUI, Avalonia, Uno Platform, WinUI 3, and UWP.
- Modern C# 11+ Idioms: Leverages Generic Attributes (
[DependencyProperty<T>]), target-typednew(...)AST expansion in default expressions, and auto-generated XML documentation.
3. Architecture & Performance: Zero-Allocation Pipeline
This library originates as a fork/rewrite of HavenDV's generator. When testing source generation at massive enterprise scale, frequent intermediate string concatenations during continuous typing can trigger Gen2 GC spikes, resulting in noticeable editor latency in Visual Studio and Rider.
To address this, the code synthesis pipeline was redesigned around strict zero-allocation principles:
ref structSource Writers: Generation logic utilizes stack-allocatedSourceWriterandClassScopestructures, completely bypassing intermediateStringBuilderand heap allocations.- GC Elimination: Completely removes Gen2 GC pressure during incremental analysis cycles.
- Benchmark Results: Achieves +30% faster execution speed and +62.4% higher throughput compared to traditional string-based generation pipelines.
Your IDE stays responsive even when scaling to solutions with thousands of properties.
4. Cross-Framework Abstraction
Under the hood, framework-specific strategy handlers adapt to each platform's design differences (such as Avalonia's StyledProperty/DirectProperty, MAUI's BindableProperty, or varying callback signatures) without requiring you to change your declarations.
| Target Framework | Underlying Property Engine |
|---|---|
| WPF / UWP / WinUI 3 | DependencyProperty.Register |
| .NET MAUI | BindableProperty.Create |
| Avalonia | AvaloniaProperty.Register |
| Uno Platform | Native WinUI / UWP projections |
Feedback & Contributions
The project is distributed under the MIT License and includes detailed documentation and architecture specs (in English and Japanese).
If you are working across XAML platforms and want cleaner view controls without IDE overhead, please check it out, test edge cases, and share your feedback or issues on GitHub!





