ReactiveUI.SourceGenerators
1.0.2
Prefix Reserved
See the version list below for details.
dotnet add package ReactiveUI.SourceGenerators --version 1.0.2
NuGet\Install-Package ReactiveUI.SourceGenerators -Version 1.0.2
<PackageReference Include="ReactiveUI.SourceGenerators" Version="1.0.2" />
paket add ReactiveUI.SourceGenerators --version 1.0.2
#r "nuget: ReactiveUI.SourceGenerators, 1.0.2"
// Install ReactiveUI.SourceGenerators as a Cake Addin #addin nuget:?package=ReactiveUI.SourceGenerators&version=1.0.2 // Install ReactiveUI.SourceGenerators as a Cake Tool #tool nuget:?package=ReactiveUI.SourceGenerators&version=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;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on ReactiveUI.SourceGenerators:
Package | Downloads |
---|---|
Helium.Core
Package Description |
|
Helium.Visible
Package Description |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on ReactiveUI.SourceGenerators:
Repository | Stars |
---|---|
gui-cs/Terminal.Gui
Cross Platform Terminal UI toolkit for .NET
|
|
reactiveui/ReactiveUI.Validation
Validation helpers for ReactiveUI-based apps.
|
|
reactiveui/ReactiveMvvm
Cross-platform ReactiveUI sample app built for a talk at MSK .NET conf.
|