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:
DreaminePropertyDreamineEntryDreamineModelDreamineEventDreamineCommand
The goal of this package is to reduce repetitive code while keeping generation rules and constraints explicit.
MVVM projects repeatedly need the following patterns:
- backing field → property exposure
- method →
ICommandproperty 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.
- 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
- Target Framework:
netstandard2.0 - Usually used together with:
Dreamine.MVVM.AttributesDreamine.MVVM.Core- WPF / .NET MVVM applications
dotnet add package Dreamine.MVVM.Generators<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.
Dreamine.MVVM.Generators
├── DreamineAutoWiringGenerator.cs
├── DreamineCommandSourceGenerator.cs
├── DreamineEntryGenerator.cs
├── AnalyzerReleases.Shipped.md
├── AnalyzerReleases.Unshipped.md
├── buildTransitive/
│ └── Dreamine.MVVM.Generators.targets
└── Dreamine.MVVM.Generators.csproj
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
Generates application bootstrap code for types marked with [DreamineEntry].
- Generates application startup initialization code
- Calls
DMContainer.AutoRegisterAll(...) - Calls
ViewModelLocator.RegisterAll(...) - Hooks
FrameworkElement.Loadedto attach View ↔ ViewModel automatically - Generates
RegisterBefore,RegisterAfter, andShowMainWindowpartial hooks
- The target type must be partial
- The target type must inherit
System.Windows.Application - The design assumes only one valid entry type
using Dreamine.MVVM.Attributes;
[DreamineEntry]
public partial class App : Application
{
}Generates helper properties from fields marked with [DreamineProperty], [DreamineModel], and [DreamineEvent].
_title→Title_model→Model_event→Event
- 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
using Dreamine.MVVM.Attributes;
public partial class MainViewModel
{
[DreamineProperty]
private string _title;
[DreamineModel]
private MainModel _model;
[DreamineEvent]
private MainEvent _event;
}Title→ field-backed propertyModel→ model access propertyEvent→ event access property
[DreamineProperty]generation assumesSetProperty(ref field, value)is available
so the target type must provideSetProperty[DreamineModel]and[DreamineEvent]currently should not be used on readonly fieldsDreamineModeluses anew T()initialization pathDreamineEventuses aDMContainer.Resolve<T>()initialization path- Generated code no longer forces inheritance from
ViewModelBase
Generates ICommand properties from methods marked with [DreamineCommand].
- Generates a
{MethodName}Commandproperty - Supports
CommandNameoverride when provided - Directly wraps the annotated method when
TargetMethodis not specified - Generates
TargetMethodinvocation code when forwarding is requested - Assigns the result to the
BindToproperty when forwarding with a return value - Generates a forwarding body when the method has no implementation body and
TargetMethodis specified - Avoids direct dependency on an external
RelayCommandtype by emitting an internal generatedICommandwrapper
using Dreamine.MVVM.Attributes;
public partial class MainViewModel
{
[DreamineCommand]
private void Save()
{
}
[DreamineCommand("Event.ReadmeClick", BindTo = "Readme")]
partial void LoadReadme();
}- 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
<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>using Dreamine.MVVM.Attributes;
public partial class MainViewModel
{
[DreamineProperty]
private string _title;
[DreamineCommand]
private void Save()
{
}
[DreamineCommand("Event.ReadmeClick", BindTo = "Readme")]
partial void LoadReadme();
}During build, partial source files are generated.
Typical outputs include:
TitlepropertySaveCommandLoadReadmeCommand- forwarding method body
Generated code still assumes some Dreamine runtime concepts exist.
Examples:
DMContainerViewModelLocatorSetProperty
This package is intended to be used inside the Dreamine MVVM stack.
Under the current implementation:
DreamineEntry→ App / bootstrap layerDreamineProperty→ ViewModel layer withSetPropertyDreamineModel,DreamineEvent→ field access generationDreamineCommand→ method-based command generation
The current generator implementations prioritize:
- partial type validation
- method signature validation
- name conflict prevention
- diagnostics for invalid usage
The current project assumes analyzer-style packaging.
Typical configuration points are:
PackageType=AnalyzerOutputItemType=AnalyzerIncludeBuildOutput=false- package the generator DLL into
analyzers/dotnet/cs - use
buildTransitivefor automatic registration
| 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
MIT License