Skip to content

Getting started

Languages

简体中文

Install the package

bash
dotnet add package MvvmAIO.R3.SourceGenerators

The package is a DevelopmentDependency analyzer. Add:

csharp
using R3.SourceGenerators;

Generated interfaces and implementations are internal in namespace R3.SourceGenerators.

Partial types for R3Command

[R3Command] requires a partial declaring type. Fix R3SG0001 by making the type partial.

csharp
public partial class ShellViewModel
{
    [R3Command]
    private void Save() { }
}

Observable event APIs do not require partial types on the source type (only command generation does).

First observable event

csharp
public class Button : Control
{
    public event EventHandler<RoutedEventArgs>? Click;
}

// IButtonEvents (internal)
var clicks = button.FromEvents().Click;

See Observable events for hierarchy, generic constraints, and routed APIs.

WPF routed events

Enable WPF in the consumer project:

xml
<UseWPF>true</UseWPF>

Then use FromRoutedEvents() / FromRoutedEventHandlers() like standard routed events.

Avalonia

Routed events are detected when Avalonia.Interactivity.RoutedEvent metadata is present. Parameterless overloads use default routes (Direct | Bubble, handledEventsToo: false).

Verify your build

bash
dotnet build

Unresolved R3SG errors point to Diagnostics reference.

Reading order

  1. This page — install, partial types, first FromEvents() call
  2. Observable events — main guide (interface model, routed events, FromEventHandlers)
  3. R3Command — command properties
  4. Diagnostics reference — every R3SG id
  5. Changelog — releases and upgrade notes

Next steps

TopicLink
Observable events (primary guide)Observable events
Command generationR3Command
Repository layoutArchitecture overview
Runnable demosSamples

Released under the MIT License.

Released under the MIT License.