OutWit.Common.MVVM.Avalonia.Generator 2.0.4

dotnet add package OutWit.Common.MVVM.Avalonia.Generator --version 2.0.4
                    
NuGet\Install-Package OutWit.Common.MVVM.Avalonia.Generator -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OutWit.Common.MVVM.Avalonia.Generator" Version="2.0.4">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OutWit.Common.MVVM.Avalonia.Generator" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="OutWit.Common.MVVM.Avalonia.Generator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OutWit.Common.MVVM.Avalonia.Generator --version 2.0.4
                    
#r "nuget: OutWit.Common.MVVM.Avalonia.Generator, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OutWit.Common.MVVM.Avalonia.Generator@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OutWit.Common.MVVM.Avalonia.Generator&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=OutWit.Common.MVVM.Avalonia.Generator&version=2.0.4
                    
Install as a Cake Tool

OutWit.Common.MVVM.Avalonia.Generator

Roslyn Source Generator for automatic Avalonia StyledProperty, DirectProperty, and AttachedProperty generation. This generator reads properties marked with the corresponding attributes and generates the necessary property fields and implementations at compile time.

?? Important: Don't Install Directly

This package should NOT be installed directly! It's automatically included when you install OutWit.Common.MVVM.Avalonia.

# ? Correct - Install the Avalonia package
dotnet add package OutWit.Common.MVVM.Avalonia

# ? Wrong - Don't install the generator directly
dotnet add package OutWit.Common.MVVM.Avalonia.Generator

What It Does

This source generator:

  1. Finds Properties - Scans your code for properties marked with:

    • [StyledProperty] - generates Avalonia StyledProperty
    • [DirectProperty] - generates Avalonia DirectProperty with backing field
    • [AttachedProperty] - generates Avalonia AttachedProperty
  2. Generates Code - Creates:

    • public static readonly StyledProperty<T> / DirectProperty<TOwner, T> / AttachedProperty<T> fields
    • Backing fields for DirectProperty
    • Get{PropertyName} and Set{PropertyName} methods for attached properties
  3. Convention-Based Discovery - Automatically finds callback methods:

    • On{PropertyName}Changed for property changed handlers
    • {PropertyName}Coerce for coerce callbacks

How It Works

Input (Your Code)

using Avalonia.Controls;
using OutWit.Common.MVVM.Avalonia.Attributes;

namespace MyApp.Controls
{
    public partial class CustomButton : Button
    {
        [StyledProperty(DefaultValue = "Click Me")]
        public string Label { get; set; }

        [DirectProperty(DefaultValue = 0)]
        public int ClickCount { get; set; }

        // Convention: On{PropertyName}Changed
        private void OnLabelChanged(AvaloniaPropertyChangedEventArgs<string> e)
        {
            UpdateLabel();
        }
    }
}

Output (Generated Code)

// <auto-generated/>
#nullable enable

namespace MyApp.Controls
{
    partial class CustomButton
    {
        public static readonly StyledProperty<string> LabelProperty =
            AvaloniaProperty.Register<CustomButton, string>(nameof(Label), "Click Me");

        private int m_clickCount = 0;

        public static readonly DirectProperty<CustomButton, int> ClickCountProperty =
            AvaloniaProperty.RegisterDirect<CustomButton, int>(
                nameof(ClickCount), 
                o => o.m_clickCount, 
                (o, v) => o.m_clickCount = v,
                unsetValue: 0);
    }
}

Features

? Three Property Types

Type Use Case Style System
StyledProperty Most properties Yes
DirectProperty Frequently changing values No
AttachedProperty Properties on other objects Yes

?? Convention-Based Callbacks

  • Automatically finds On{PropertyName}Changed methods
  • Automatically finds {PropertyName}Coerce methods

?? Attached Properties

public static partial class MyAttachedProperties
{
    [AttachedProperty(DefaultValue = false)]
    public static bool IsHighlighted { get; set; }
}

// Generates:
// - public static readonly AttachedProperty<bool> IsHighlightedProperty
// - public static bool GetIsHighlighted(AvaloniaObject obj)
// - public static void SetIsHighlighted(AvaloniaObject obj, bool value)

Requirements

  • .NET SDK: 6.0 or later
  • Target Framework: net6.0 or later
  • Platform: Cross-platform (Avalonia)

Troubleshooting

Generated Code Not Appearing

  1. Clean and rebuild: dotnet clean && dotnet build
  2. Ensure class is marked as partial
  3. Check using directive: using OutWit.Common.MVVM.Avalonia.Attributes;

View Generated Files

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
  • OutWit.Common.MVVM.Avalonia - Main Avalonia package (install this!)
  • OutWit.Common.MVVM - Cross-platform base classes

License

Licensed under the Apache License, Version 2.0. See LICENSE.

Attribution (optional)

If you use OutWit.Common.MVVM.Avalonia.Generator in a product, a mention is appreciated (but not required), for example: "Powered by OutWit.Common.MVVM.Avalonia.Generator (https://ratner.io/)".

Trademark / Project name

"OutWit" and the OutWit logo are used to identify the official project by Dmitry Ratner.

You may:

  • refer to the project name in a factual way (e.g., "built with OutWit.Common.MVVM.Avalonia.Generator");
  • use the name to indicate compatibility (e.g., "OutWit.Common.MVVM.Avalonia.Generator-compatible").

You may not:

  • use "OutWit.Common.MVVM.Avalonia.Generator" as the name of a fork or a derived product in a way that implies it is the official project;
  • use the OutWit.Common.MVVM.Avalonia.Generator logo to promote forks or derived products without permission.

Remember: This package is automatically included with OutWit.Common.MVVM.Avalonia. Don't install it separately!

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • 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.

Version Downloads Last Updated
2.0.4 127 1/25/2026
2.0.3 116 1/8/2026
2.0.2 120 1/2/2026
2.0.1 121 1/2/2026
2.0.0 116 1/2/2026