-
Notifications
You must be signed in to change notification settings - Fork 0
EN 04_framework_strategies
🇺🇸 English | 🇯🇵 日本語 | Introduction
The DependencyPropertyGenerator generates framework-specific boilerplate code for WPF, UWP, WinUI, Uno, Avalonia, and MAUI based on a single [DependencyProperty] attribute.
Use this document as the API mapping dictionary when you implement framework-specific bug fixes or feature extensions. The IFrameworkGeneratorStrategy implementation classes in the Sources/Strategies/ directory abstract away all architectural differences between platforms.
The core value of this generator is the ability to write a single C# syntax [DependencyProperty] and deploy it natively across any XAML UI framework. This "Write Once, Run Everywhere" capability is achieved by strictly separating data extraction from code emission:
flowchart TD
subgraph Input ["1. User Code"]
Code["[DependencyProperty<bool>('IsActive')]"]
end
subgraph Core ["2. Unified Model (Pure DTOs)"]
DTO["DependencyPropertyData<br>・Name: 'IsActive'<br>・Type: 'bool'<br>・OnChanged: 'OnIsActiveChanged'"]
end
subgraph Strategies ["3. Framework Strategies"]
WPF["WpfFrameworkGenerator ➡ WPF Code"]
AVA["AvaloniaFrameworkGenerator ➡ Avalonia Code"]
MAUI["MauiFrameworkGenerator ➡ MAUI Code"]
WINUI["UwpFrameworkGenerator ➡ WinUI/Uno Code"]
end
Input --> DTO
DTO --> WPF
DTO --> AVA
DTO --> MAUI
DTO --> WINUI
-
Extraction (Model): The Roslyn pipeline parses attributes into pure value-type DTOs (e.g.,
DependencyPropertyData). -
Emission (Strategy): The
IFrameworkGeneratorStrategyclasses read the unified DTOs and synthesize native boilerplate for the detected target platform.
WPF uses System.Windows.DependencyProperty and DependencyPropertyKey as the foundation for its property system.
-
Registration: Calls
DependencyProperty.RegisterorRegisterAttached. -
Read-Only: Uses
RegisterReadOnlyandRegisterAttachedReadOnly. -
Metadata: Manages metadata via
System.Windows.FrameworkPropertyMetadataorPropertyMetadata. -
Callbacks: Wires callbacks using dedicated delegate types (
PropertyChangedCallback,CoerceValueCallback,ValidateValueCallback).
Note
The WPF FrameworkPropertyMetadata contains an extensive set of layout and data binding flags (for example, AffectsMeasure, BindsTwoWayByDefault). The generator relies on the FrameworkMetadataData fields to securely emit these WPF-specific flags.
Avalonia builds upon Avalonia.AvaloniaProperty, typically defining properties as StyledProperty<T>, AttachedProperty<T>, or DirectProperty<T>.
-
Registration: Calls
AvaloniaProperty.RegisterorRegisterAttached. -
Direct Properties: When you enable the
IsDirectflag, the generator emits the specializedRegisterDirectgeneric method for fast, field-backed access. - Metadata: Passes metadata directly as arguments or manages it via Avalonia's native metadata classes.
-
Callbacks: Routes callbacks through Observables or event-based subscription models like
AvaloniaPropertyChanged.
MAUI uses a distinct type system based on Microsoft.Maui.Controls.BindableProperty and BindablePropertyKey.
-
Registration: Calls
BindableProperty.CreateorCreateAttached. -
Read-Only: Uses
CreateReadOnlyorCreateAttachedReadOnly. - Metadata: Passes metadata as flat arguments to the API rather than encapsulating it in a dedicated class.
-
Callbacks: Maps callbacks to specific delegates (
BindingPropertyChangedDelegate,CoerceValueDelegate,ValidateValueDelegate).
UWP and Uno rely on Windows.UI.Xaml.DependencyProperty, while WinUI 3 relies on Microsoft.UI.Xaml.DependencyProperty.
-
Registration: Limits registration strictly to
DependencyProperty.RegisterandRegisterAttached. -
Metadata: Handles metadata using
PropertyMetadata. -
Callbacks: Natively provides only the
PropertyChangedCallback.
Warning
These platforms lack native API support for coercion and validation. The generator emits fallback implementations that manually clamp or correct values inside the property's getter and setter, or within the PropertyChanged event itself.
Follow these architectural principles when you add support for new UI frameworks or address breaking API changes (for example, Avalonia v12):
Important
1. Preserve the DTOs
Never mutate the shared DTO models (for example, DependencyPropertyData). You must isolate all platform-specific differences by overriding methods in the corresponding generator class (for example, XxxFrameworkGenerator.cs) under the Sources/Strategies/ directory.
Tip
2. Method extraction for signature variances
Extract methods to resolve API signature differences. For example, use the GenerateRegisterMethodArguments method to construct the exact argument string passed to the Register method, gracefully accommodating varying parameter configurations.
Note
3. Zero-allocation generation rules
For strict performance optimization rules, including the prohibition of LINQ or unnecessary string.Join calls within string generation paths (SourceWriter), see 05. Code synthesis and performance.
During Roslyn pipeline initialization, the generator automatically resolves the target UI framework using the following priority cascade:
-
High-precision symbol inspection (
Compilation.TryRecognizeFramework) The generator inspects the compilation context for core framework type symbols:-
Microsoft.Maui.Controls.BindableObject$\rightarrow$ Framework.Maui -
Avalonia.AvaloniaObject$\rightarrow$ Framework.Avalonia -
Uno.UI.FeatureConfiguration$\rightarrow$ Framework.UnoorFramework.UnoWinUi -
Microsoft.UI.Xaml.DependencyObject$\rightarrow$ Framework.WinUi -
Windows.UI.Xaml.DependencyObject$\rightarrow$ Framework.Uwp -
System.Windows.DependencyObject$\rightarrow$ Framework.Wpf
-
-
MSBuild property and compilation constant fallback (
AnalyzerConfigOptionsProvider) If the generator cannot resolve symbols, it inspectsDefineConstants(HAS_WPF,HAS_WINUI,HAS_UWP,HAS_UNO,HAS_UNO_WINUI,HAS_AVALONIA,HAS_MAUI) or theUseMauiproperty in project files. -
Unrecognized framework fallback (
Framework.None) If no framework matches, the generator assignsFramework.None. In this state, it emits theDPG0000(Framework is not recognized) diagnostic and skips platform-specificusingimports and registrations. It safely emits only the raw attribute definitions to prevent compilation failure. For detailed causes and project configuration remedies forDPG0000, see 08. Diagnostics reference.
This wiki is automatically synchronized from spec/ in the repository.
- Introduction
- 01. FAQ & Design Rationale
- 02. Foundation & Domain
- 03. Pipeline Architecture
- 04. Framework Strategies
- 05. Synthesis & Performance
- 06. Complexity Model
- 07. Test Specification
- 08. Diagnostics Reference
- 概要
- 01. 設計思想とFAQ
- 02. 基盤とドメイン
- 03. パイプライン構造
- 04. フレームワーク別生成仕様
- 05. コード生成と最適化
- 06. 計算量モデル
- 07. テスト仕様書
- 08. 診断機能リファレンス