ReactiveUI.SourceGenerators 1.0.2

ReactiveUI.SourceGenerators

Use source generators to generate ReactiveUI objects.

Not taking public contributions at this time

These Source Generators were designed to work in full with ReactiveUI V19.5.31 and newer supporting all features, currently:

  • [Reactive]
  • [ObservableAsProperty]
  • [ReactiveCommand]

Versions older than V19.5.31 to this:

  • [Reactive] fully supported,
  • [ObservableAsProperty] fully supported,
  • [ReactiveCommand] all supported except Cancellation Token asnyc methods.

Historical ways

Read-write properties

Typically properties are declared like this:

private string _name;
public string Name 
{
    get => _name;
    set => this.RaiseAndSetIfChanged(ref _name, value);
}

Before these Source Generators were avaliable we used ReactiveUI.Fody. With ReactiveUI.Fody the [Reactive] Attribute was placed on a Public Property with Auto get / set properties, the generated code from the Source Generator and the Injected code using Fody are very similar with the exception of the Attributes.

[Reactive]
public string Name { get; set; }

ObservableAsPropertyHelper properties

Similarly, to declare output properties, the code looks like this:

public partial class MyReactiveClass : ReactiveObject
{
    ObservableAsPropertyHelper<string> _firstName;

    public MyReactiveClass()
    {
        _firstName = firstNameObservable
            .ToProperty(this, x => x.FirstName);
    }

    public string FirstName => _firstName.Value;

    private IObservable<string> firstNameObservable() => Observable.Return("Test");
}

With ReactiveUI.Fody, you can simply declare a read-only property using the [ObservableAsProperty] attribute, using either option of the two options shown below.

[ObservableAsProperty]
public string FirstName { get; }

Welcome to a new way - Source Generators

Usage Reactive property [Reactive]

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass : ReactiveObject
{
    [Reactive]
    private string _myProperty;
}

Usage ObservableAsPropertyHelper [ObservableAsProperty]

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass : ReactiveObject
{
    [ObservableAsProperty]
    private string _myProperty;
}

Usage ReactiveCommand [ReactiveCommand]

Usage ReactiveCommand without parameter

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass
{
    public MyReactiveClass()
    {
        InitializeCommands();
    }

    [ReactiveCommand]
    private void Execute() { }
}

Usage ReactiveCommand with parameter

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass
{
    public MyReactiveClass()
    {
        InitializeCommands();
    }

    [ReactiveCommand]
    private void Execute(string parameter) { }
}

Usage ReactiveCommand with parameter and return value

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass
{
    public MyReactiveClass()
    {
        InitializeCommands();
    }

    [ReactiveCommand]
    private string Execute(string parameter) => parameter;
}

Usage ReactiveCommand with parameter and async return value

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass
{
    public MyReactiveClass()
    {
        InitializeCommands();
    }

    [ReactiveCommand]
    private async Task<string> Execute(string parameter) => await Task.FromResult(parameter);
}

Usage ReactiveCommand with IObservable return value

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass
{
    public MyReactiveClass()
    {
        InitializeCommands();
    }

    [ReactiveCommand]
    private IObservable<string> Execute(string parameter) => Observable.Return(parameter);
}

Usage ReactiveCommand with CancellationToken

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass
{
    public MyReactiveClass()
    {
        InitializeCommands();
    }

    [ReactiveCommand]
    private async Task Execute(CancellationToken token) => await Task.Delay(1000, token);
}

Usage ReactiveCommand with CancellationToken and parameter

using ReactiveUI.SourceGenerators;

public partial class MyReactiveClass
{
    public MyReactiveClass()
    {
        InitializeCommands();
    }

    [ReactiveCommand]
    private async Task<string> Execute(string parameter, CancellationToken token)
    {
        await Task.Delay(1000, token);
        return parameter;
    }
}

Showing the top 20 packages that depend on ReactiveUI.SourceGenerators.

Packages Downloads
ReactiveUI.WPF
Contains the ReactiveUI platform specific extensions for Windows Presentation Foundation (WPF)
12
ReactiveUI.WPF
Contains the ReactiveUI platform specific extensions for Windows Presentation Foundation (WPF)
11
ReactiveUI.WPF
Contains the ReactiveUI platform specific extensions for Windows Presentation Foundation (WPF)
10
ReactiveUI
A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. This is the base package with the base platform implementations
9
ReactiveUI.Core
Type-agnostic core shared by ReactiveUI and ReactiveUI.Reactive.
9
ReactiveUI.WPF
Contains the ReactiveUI platform specific extensions for Windows Presentation Foundation (WPF)
9
ReactiveUI
A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. This is the base package with the base platform implementations
8
ReactiveUI.Core
Type-agnostic core shared by ReactiveUI and ReactiveUI.Reactive.
8
ReactiveUI
A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. This is the base package with the base platform implementations
7
ReactiveUI.Core
Type-agnostic core shared by ReactiveUI and ReactiveUI.Reactive.
7
ReactiveUI
A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. This is the base package with the base platform implementations
6
ReactiveUI.Core
Type-agnostic core shared by ReactiveUI and ReactiveUI.Reactive.
5
ReactiveUI.Core
Type-agnostic core shared by ReactiveUI and ReactiveUI.Reactive.
4

.NET Standard 2.0

  • No dependencies.

Version Downloads Last updated
4.2.0 11 09/28/2026
4.1.0 7 09/28/2026
4.0.1 9 09/28/2026
4.0.0 7 09/29/2026
3.2.0 8 09/28/2026
3.1.0 8 09/28/2026
3.0.0 7 09/29/2026
2.6.1 8 09/28/2026
2.5.1 8 09/28/2026
2.4.1 10 09/28/2026
2.3.1 11 09/28/2026
2.2.4 8 09/28/2026
2.1.27 5 09/29/2026
2.1.8 9 09/28/2026
2.1.1 7 09/28/2026
2.0.17 9 09/28/2026
1.1.31 10 09/28/2026
1.1.26 9 09/29/2026
1.0.3 9 09/28/2026
1.0.2 8 09/28/2026