Dreamine.MVVM.Generators 1.0.13

dotnet add package Dreamine.MVVM.Generators --version 1.0.13
                    
NuGet\Install-Package Dreamine.MVVM.Generators -Version 1.0.13
                    
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="Dreamine.MVVM.Generators" Version="1.0.13" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dreamine.MVVM.Generators" Version="1.0.13" />
                    
Directory.Packages.props
<PackageReference Include="Dreamine.MVVM.Generators" />
                    
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 Dreamine.MVVM.Generators --version 1.0.13
                    
#r "nuget: Dreamine.MVVM.Generators, 1.0.13"
                    
#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 Dreamine.MVVM.Generators@1.0.13
                    
#: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=Dreamine.MVVM.Generators&version=1.0.13
                    
Install as a Cake Addin
#tool nuget:?package=Dreamine.MVVM.Generators&version=1.0.13
                    
Install as a Cake Tool

Dreamine.MVVM.Generators

Dreamine.MVVM.Generators is a Roslyn incremental source generator package used by the Dreamine MVVM ecosystem.

This package generates MVVM boilerplate code at compile time based on declarative attributes.

The main attributes currently handled are:

  • DreamineProperty
  • DreamineEntry
  • DreamineModel
  • DreamineEvent
  • DreamineCommand

The goal of this package is to reduce repetitive code while keeping generation rules and constraints explicit.

➡️ 한국어 문서 보기


What this package does

MVVM projects repeatedly need the following patterns:

  • backing field → property exposure
  • method → ICommand property generation
  • model / event reference exposure
  • application entry bootstrap generation
  • declarative command forwarding generation

Dreamine.MVVM.Generators moves those repetitive patterns into the generation layer so ViewModel and App code can stay smaller.


Key Features

  • Built on Roslyn Incremental Source Generators
  • Can be packaged as an analyzer package
  • Generates code from Dreamine attributes
  • Supports entry bootstrap generation
  • Supports field-based auto wiring
  • Supports DreamineCommand-based direct and forwarding command generation
  • Can be packed into analyzers/dotnet/cs
  • Supports automatic analyzer registration through buildTransitive

Requirements

  • Target Framework: netstandard2.0
  • Usually used together with:
    • Dreamine.MVVM.Attributes
    • Dreamine.MVVM.Core
    • WPF / .NET MVVM applications

Installation

Option A) NuGet

dotnet add package Dreamine.MVVM.Generators

Option B) PackageReference

<ItemGroup>
  <PackageReference Include="Dreamine.MVVM.Generators" Version="1.0.6" />
</ItemGroup>

This package is intended to be used as an analyzer package, and buildTransitive is the recommended way to register it automatically in consuming projects.


Project Structure

Dreamine.MVVM.Generators
├── DreamineAutoWiringGenerator.cs
├── DreamineCommandSourceGenerator.cs
├── DreamineEntryGenerator.cs
├── AnalyzerReleases.Shipped.md
├── AnalyzerReleases.Unshipped.md
├── buildTransitive/
│   └── Dreamine.MVVM.Generators.targets
└── Dreamine.MVVM.Generators.csproj

Architecture Role

This package belongs to the generation layer of the Dreamine MVVM stack.

ViewModel / App Source Code
        │
        ├─ Dreamine.MVVM.Attributes
        │     (markers / metadata)
        │
        ├─ Dreamine.MVVM.Generators
        │     (compile-time code generation)
        │
        └─ Dreamine.MVVM.Core
              (runtime MVVM infrastructure)

The responsibility split is:

  • Attributes: declare intent
  • Generators: emit source code
  • Core: executes runtime behavior

Supported Generators

1) DreamineEntryGenerator

Generates application bootstrap code for types marked with [DreamineEntry].

Current responsibilities
  • Generates application startup initialization code
  • Calls DMContainer.AutoRegisterAll(...)
  • Calls ViewModelLocator.RegisterAll(...)
  • Hooks FrameworkElement.Loaded to attach View ↔ ViewModel automatically
  • Generates RegisterBefore, RegisterAfter, and ShowMainWindow partial hooks
Current constraints
  • The target type must be partial
  • The target type must inherit System.Windows.Application
  • The design assumes only one valid entry type
Example
using Dreamine.MVVM.Attributes;

[DreamineEntry]
public partial class App : Application
{
}

2) DreamineAutoWiringGenerator

Generates helper properties from fields marked with [DreamineProperty], [DreamineModel], and [DreamineEvent].

Current responsibilities
  • _titleTitle
  • _modelModel
  • _eventEvent
Current behavior
  • Handles field-based generation only
  • Does not regenerate from property declarations
  • Adds helper properties to a partial class
  • Skips generation when a member name conflict already exists
Example
using Dreamine.MVVM.Attributes;

public partial class MainViewModel
{
    [DreamineProperty]
    private string _title;

    [DreamineModel]
    private MainModel _model;

    [DreamineEvent]
    private MainEvent _event;
}
Generated intent
  • Title → field-backed property
  • Model → model access property
  • Event → event access property
Notes
  • [DreamineProperty] generation assumes SetProperty(ref field, value) is available
    so the target type must provide SetProperty
  • [DreamineModel] and [DreamineEvent] currently should not be used on readonly fields
  • DreamineModel uses a new T() initialization path
  • DreamineEvent uses a DMContainer.Resolve<T>() initialization path
  • Generated code no longer forces inheritance from ViewModelBase

3) DreamineCommandSourceGenerator

Generates ICommand properties from methods marked with [DreamineCommand].

Current responsibilities
  • Generates a {MethodName}Command property
  • Supports CommandName override when provided
  • Directly wraps the annotated method when TargetMethod is not specified
  • Generates TargetMethod invocation code when forwarding is requested
  • Assigns the result to the BindTo property when forwarding with a return value
  • Generates a forwarding body when the method has no implementation body and TargetMethod is specified
  • Avoids direct dependency on an external RelayCommand type by emitting an internal generated ICommand wrapper
Example
using Dreamine.MVVM.Attributes;

public partial class MainViewModel
{
    [DreamineCommand]
    private void Save()
    {
    }

    [DreamineCommand("Event.ReadmeClick", BindTo = "Readme")]
    partial void LoadReadme();
}
Current constraints
  • The containing type must be partial
  • The target method must be parameterless void
  • Forwarding methods without a body must be partial
  • Generation is skipped when the command property name conflicts with an existing member

Quick Start

1) Add the required packages

<ItemGroup>
  <PackageReference Include="Dreamine.MVVM.Attributes" Version="1.0.6" />
  <PackageReference Include="Dreamine.MVVM.Core" Version="1.0.9" />
  <PackageReference Include="Dreamine.MVVM.Generators" Version="1.0.11" PrivateAssets="all" OutputItemType="Analyzer" />
</ItemGroup>

2) Declare attributes

using Dreamine.MVVM.Attributes;

public partial class MainViewModel
{
    [DreamineProperty]
    private string _title;

    [DreamineCommand]
    private void Save()
    {
    }

    [DreamineCommand("Event.ReadmeClick", BindTo = "Readme")]
    partial void LoadReadme();
}

3) Build

During build, partial source files are generated.

Typical outputs include:

  • Title property
  • SaveCommand
  • LoadReadmeCommand
  • forwarding method body

Important Notes Based on the Current Code

1) The generator package is not a standalone runtime framework

Generated code still assumes some Dreamine runtime concepts exist.

Examples:

  • DMContainer
  • ViewModelLocator
  • SetProperty

This package is intended to be used inside the Dreamine MVVM stack.

2) Not all attributes have the same usage scope

Under the current implementation:

  • DreamineEntry → App / bootstrap layer
  • DreamineProperty → ViewModel layer with SetProperty
  • DreamineModel, DreamineEvent → field access generation
  • DreamineCommand → method-based command generation

3) The generation rules are intentionally becoming stricter

The current generator implementations prioritize:

  • partial type validation
  • method signature validation
  • name conflict prevention
  • diagnostics for invalid usage

Packaging Notes

The current project assumes analyzer-style packaging.

Typical configuration points are:

  • PackageType=Analyzer
  • OutputItemType=Analyzer
  • IncludeBuildOutput=false
  • package the generator DLL into analyzers/dotnet/cs
  • use buildTransitive for automatic registration

Comparison

Package Role Runtime Logic Compile-Time Generation
Dreamine.MVVM.Attributes declaration layer No No
Dreamine.MVVM.Generators generation layer No Yes
Dreamine.MVVM.Core runtime layer Yes No

This separation keeps the system layered by responsibility.


This package is usually used together with:

Dreamine.MVVM.Attributes
Dreamine.MVVM.Core
Dreamine WPF / UI / App packages

License

MIT License

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
1.0.13 102 7/8/2026
1.0.12 109 4/30/2026
1.0.11 107 4/29/2026
1.0.10 120 3/24/2026
1.0.9 117 3/22/2026
1.0.8 116 3/21/2026
1.0.7 116 3/21/2026
1.0.6 129 2/20/2026
1.0.5 114 2/20/2026
1.0.4 120 2/18/2026
1.0.3 212 5/31/2025
1.0.2 217 5/26/2025
1.0.1 213 5/25/2025
1.0.0 226 5/25/2025