NuExt.Minimal.Mvvm.SourceGenerator 0.7.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package NuExt.Minimal.Mvvm.SourceGenerator --version 0.7.0
                    
NuGet\Install-Package NuExt.Minimal.Mvvm.SourceGenerator -Version 0.7.0
                    
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="NuExt.Minimal.Mvvm.SourceGenerator" Version="0.7.0">
  <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="NuExt.Minimal.Mvvm.SourceGenerator" Version="0.7.0" />
                    
Directory.Packages.props
<PackageReference Include="NuExt.Minimal.Mvvm.SourceGenerator">
  <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 NuExt.Minimal.Mvvm.SourceGenerator --version 0.7.0
                    
#r "nuget: NuExt.Minimal.Mvvm.SourceGenerator, 0.7.0"
                    
#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 NuExt.Minimal.Mvvm.SourceGenerator@0.7.0
                    
#: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=NuExt.Minimal.Mvvm.SourceGenerator&version=0.7.0
                    
Install as a Cake Addin
#tool nuget:?package=NuExt.Minimal.Mvvm.SourceGenerator&version=0.7.0
                    
Install as a Cake Tool

NuExt.Minimal.Mvvm.SourceGenerator

NuExt.Minimal.Mvvm.SourceGenerator is an extension for the lightweight MVVM framework NuExt.Minimal.Mvvm. This package includes a source generator that produces boilerplate code for your ViewModels at compile time, simplifying development and reducing routine work. By automating repetitive tasks, it helps you focus on implementing application-specific logic.

Features

  • Automatically generates boilerplate code for ViewModels:
    • Generates properties with notification change support.
    • Creates command properties for appropriate methods.
    • Generates static localization classes from JSON files.
  • Simplifies the development process by reducing repetitive coding tasks.
  • Seamlessly integrates with the NuExt.Minimal.Mvvm framework.
  • Enhances maintainability and readability of your codebase.

Commonly Used Types

  • Minimal.Mvvm.NotifyAttribute: Generates a property for a backing field or a command for a method.
  • Minimal.Mvvm.AlsoNotifyAttribute: Notifies additional properties when the annotated property changes.
  • Minimal.Mvvm.LocalizeAttribute: Localizes the target class using the provided JSON file.
  • Minimal.Mvvm.CustomAttributeAttribute: Specifies a fully qualified attribute name to be applied to a generated property.
  • Minimal.Mvvm.UseCommandManagerAttribute: Enables automatic CanExecute reevaluation for the generated command property by subscribing to the WPF CommandManager.RequerySuggested event.

Installation

Via NuGet:

dotnet add package NuExt.Minimal.Mvvm.SourceGenerator

Or via Visual Studio:

  1. Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution....
  2. Search for NuExt.Minimal.Mvvm.SourceGenerator.
  3. Click "Install".

Dependencies

To use this source generator effectively, you need to have any of these packages installed in your project: NuExt.Minimal.Mvvm, NuExt.Minimal.Mvvm.Wpf, or NuExt.Minimal.Mvvm.MahApps.Metro. You can add them via NuGet as well:

For the base MVVM framework:

dotnet add package NuExt.Minimal.Mvvm

For Wpf-specific extensions:

dotnet add package NuExt.Minimal.Mvvm.Wpf

For MahApps.Metro integration:

dotnet add package NuExt.Minimal.Mvvm.MahApps.Metro

Usage Examples

Example using auto-generated property notifications

Given a user class such as:

using Minimal.Mvvm;
using System.Threading.Tasks;

public partial class PersonModel : BindableBase
{
    [Notify, AlsoNotify(nameof(FullName))]
    private string? _name;

    [Notify, AlsoNotify(nameof(FullName))]
    private string? _surname;

    [Notify, AlsoNotify(nameof(FullName))]
    private string? _middleName;

    public string FullName => $"{Surname} {Name} {MiddleName}";

    /// <summary>
    /// Shows information.
    /// </summary>
    [Notify("ShowInfoCommand", Setter = AccessModifier.Private)]
    [CustomAttribute("System.Text.Json.Serialization.JsonIgnore")]
    private async Task ShowAsync(string fullName)
    {
        await Task.Delay(1000);
    }
}

The generator could produce the following:

partial class PersonModel
{
    public string? Name
    {
        get => _name;
        set
        {
            if (SetProperty(ref _name, value))
            {
                RaisePropertyChanged("FullName");
            }
        }
    }

    public string? Surname
    {
        get => _surname;
        set
        {
            if (SetProperty(ref _surname, value))
            {
                RaisePropertyChanged("FullName");
            }
        }
    }

    public string? MiddleName
    {
        get => _middleName;
        set
        {
            if (SetProperty(ref _middleName, value))
            {
                RaisePropertyChanged("FullName");
            }
        }
    }

    private IAsyncCommand<string>? _showInfoCommand;
    /// <summary>
    /// Shows information.
    /// </summary>
    [System.Text.Json.Serialization.JsonIgnore]
    public IAsyncCommand<string>? ShowInfoCommand
    {
        get => _showInfoCommand;
        private set => SetProperty(ref _showInfoCommand, value);
    }
}
UseCommandManagerAttribute

When applied to a command field or method, enables automatic CanExecute reevaluation for the generated command property by subscribing to the WPF CommandManager.RequerySuggested event. This attribute is used together with [Notify] for commands that should react to global UI state changes.

using Minimal.Mvvm;

public partial class MyViewModel : ViewModelBase
{
    [Notify, UseCommandManager]
    private IRelayCommand? _saveCommand;
}

The source generator creates the command property and automatically adds/removes the subscription:

public IRelayCommand? SaveCommand
{
    get => _saveCommand;
    set
    {
        if (SetProperty(ref _saveCommand, value, out var oldValue))
        {
            RequerySuggestedEventManager.RemoveHandler(oldValue);
            RequerySuggestedEventManager.AddHandler(value);
        }
    }
}

Now SaveCommand.CanExecute will be reevaluated whenever the WPF command manager detects a UI state change (e.g., focus, keyboard, window activation). No manual event wiring is required.

These examples demonstrate how the source generator automatically creates properties with notification changes for fields and methods marked with the [Notify] attribute, thereby reducing boilerplate code.

Contributing

Issues and PRs are welcome. Keep changes minimal and performance-conscious.

License

MIT. See LICENSE.

There are no supported framework assets in this package.

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.

Version Downloads Last Updated
0.7.2 97 3/16/2026
0.7.1 91 2/23/2026
0.7.0 108 2/13/2026
0.6.0 100 1/11/2026
0.5.2 291 12/15/2025
0.5.1 229 12/14/2025
0.4.1 440 12/10/2025
0.4.0 169 12/5/2025
0.3.2 159 1/26/2025
0.3.1 159 1/22/2025
0.3.0 150 1/21/2025
0.2.0 250 11/15/2024
0.1.0 257 11/11/2024