ReactiveUI.SourceGenerators 1.0.3

前缀已保留
dotnet add package ReactiveUI.SourceGenerators --version 1.0.3                
NuGet\Install-Package ReactiveUI.SourceGenerators -Version 1.0.3                
此命令意在在Visual Studio的包管理器控制台中使用,因为它使用了NuGet模块的Install-Package版本。
<PackageReference Include="ReactiveUI.SourceGenerators" Version="1.0.3" />                
对于支持PackageReference的项目,请将此XML节点复制到项目文件中以引用该包。
paket add ReactiveUI.SourceGenerators --version 1.0.3                
#r "nuget: ReactiveUI.SourceGenerators, 1.0.3"                
#r 指令可用于F# Interactive和Polyglot Notebooks。请将此复制到交互式工具或脚本的源代码中以引用包。
// Install ReactiveUI.SourceGenerators as a Cake Addin
#addin nuget:?package=ReactiveUI.SourceGenerators&version=1.0.3

// Install ReactiveUI.SourceGenerators as a Cake Tool
#tool nuget:?package=ReactiveUI.SourceGenerators&version=1.0.3                

ReactiveUI.SourceGenerators

使用源生成器生成ReactiveUI对象。

目前不接受公开贡献

这些源生成器被设计为与ReactiveUI V19.5.31及其更高版本完全兼容,当前支持所有功能:

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

V19.5.31之前的版本

  • [Reactive] 完全支持,
  • [ObservableAsProperty] 完全支持,
  • [ReactiveCommand] 除Cancellation Token异步方法外所有支持。

历史方法

读写属性

通常属性声明如下

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

在这些源生成器可用之前,我们使用了ReactiveUI.Fody。对于ReactiveUI.Fody,[Reactive] 属性被放置在具有自动 get/set 属性的公共属性上,源生成器生成的代码和Fody注入的代码在属性之外非常相似。

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

ObservableAsPropertyHelper属性

同样,为了声明输出属性,代码看起来如下

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");
}

使用ReactiveUI.Fody,你只需使用[ObservableAsProperty]属性简单地声明只读属性,下面展示了两种选项之一。

[ObservableAsProperty]
public string FirstName { get; }

欢迎使用新的方式 - 源生成器

使用响应式属性 [Reactive]

using ReactiveUI.SourceGenerators;

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

使用 ObservableAsPropertyHelper [ObservableAsProperty]

using ReactiveUI.SourceGenerators;

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

使用 ReactiveCommand [ReactiveCommand]

使用不带参数的 ReactiveCommand

using ReactiveUI.SourceGenerators;

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

    [ReactiveCommand]
    private void Execute() { }
}

使用带参数的 ReactiveCommand

using ReactiveUI.SourceGenerators;

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

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

使用带参数和返回值的 ReactiveCommand

using ReactiveUI.SourceGenerators;

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

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

使用带参数和异步返回值的 ReactiveCommand

using ReactiveUI.SourceGenerators;

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

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

使用 IObservable 返回值的 ReactiveCommand

using ReactiveUI.SourceGenerators;

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

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

使用 CancellationToken 的 ReactiveCommand

using ReactiveUI.SourceGenerators;

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

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

使用 CancellationToken 和参数的 ReactiveCommand

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;
    }
}
产品 兼容的和额外的计算目标框架版本。
.NET net5.0 已计算。 net5.0-windows 已计算。 net6.0 已计算。 net6.0-android 已计算。 net6.0-ios 已计算。 net6.0-maccatalyst 已计算。 net6.0-macos 已计算。 net6.0-tvos 已计算。 net6.0-windows 已计算。 net7.0 已计算。 net7.0-android 已计算。 net7.0-ios 已计算。 net7.0-maccatalyst 已计算。 net7.0-macos 已计算。 net7.0-tvos 已计算。 net7.0-windows 已计算。 net8.0 已计算。 net8.0-android 已计算。 net8.0-browser 已计算。 net8.0-ios 已计算。 net8.0-maccatalyst 已计算。 net8.0-macos 已计算。 net8.0-tvos 已计算。 net8.0-windows 已计算。
.NET Core netcoreapp2.0 已计算。 netcoreapp2.1 已计算。 netcoreapp2.2 已计算。 netcoreapp3.0 已计算。 netcoreapp3.1 已计算。
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET 框架 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. 
兼容的目标框架
包括的目标框架(在包中)
了解更多关于目标框架.NET Standard的信息。
  • .NETStandard 2.0

    • 无依赖项。

NuGet 包

此包不受任何 NuGet 包的引用。

GitHub 仓库

此包不受任何流行 GitHub 仓库的引用。

版本 下载 最后更新
1.0.3 684 7/19/2024
1.0.2 56 7/18/2024