小编Ant*_*ada的帖子

VB.NET中只读集合属性的集合初始值设定项?

我正在尝试在我的框架上支持Basic.NET,所以我试图将C#4代码转换为Basic.NET 10.微软致力于"共同演化"这两个,但我遇到了集合初始化的问题. ..

我发现我可以像C#一样初始化一个集合:

Dim list = New List(Of Int32) From {1, 2, 3, 4, 5, 6, 7, 8, 9}
Run Code Online (Sandbox Code Playgroud)

大!但是,在初始化只读集合属性时,这不起作用.例如,如果我有这个类:

Public Class Class1

  Private ReadOnly list = New List(Of Int32)

  Public ReadOnly Property ListProp() As List(Of Int32)
    Get
      Return list
    End Get
  End Property

End Class
Run Code Online (Sandbox Code Playgroud)

我无法以这种方式初始化它:

Dim class1 = New Class1 With {.ListProp = New List(Of Int32) From {1, 2, 3, 4, 5, 6, 7, 8, 9}}
Run Code Online (Sandbox Code Playgroud)

或者这样:

Dim class1 = New Class1 With {.ListProp = {1, 2, …
Run Code Online (Sandbox Code Playgroud)

.net vb.net collections syntax properties

5
推荐指数
1
解决办法
2300
查看次数

ReactiveUI - 在交互处理程序中使用调度程序

我想在发生错误时显示带有两个按钮的警报对话框。据我所知,这是使用交互属性来做到这一点的方法:

this.ViewModel.ConnectionError.RegisterHandler(interaction =>
{
    var retry = await this.DisplayAlert("Connection failed", "Do you want to retry?", "RETRY", "ABORT");
    if (retry)
        interaction.SetOutput(DevicesViewModel.ErrorRecoveryOption.Retry);
    else
        interaction.SetOutput(DevicesViewModel.ErrorRecoveryOption.Abort);
});
Run Code Online (Sandbox Code Playgroud)

问题在于异常是在第三方库的线程内引发的。DisplayAlert 必须在主线程中调用。我尝试了以下方法:

this.ViewModel.ConnectionError.RegisterHandler(interaction =>
{
    RxApp.MainThreadScheduler.ScheduleAsync(interaction, async (scheduler, i, cancelationToken) =>
    {
        this.Log().Debug("ScheduleAsync");
        var retry = await this.DisplayAlert("Connection failed", "Do you want to retry?", "RETRY", "ABORT");
        if (retry)
            i.SetOutput(DevicesViewModel.ErrorRecoveryOption.Retry);
        else
            i.SetOutput(DevicesViewModel.ErrorRecoveryOption.Abort);

        return Disposable.Empty;
    });
});
Run Code Online (Sandbox Code Playgroud)

我可以在控制台中看到日志消息,但对话框不显示,并且应用程序在 ReactiveUI.dll 内崩溃。我究竟做错了什么?

system.reactive reactiveui

4
推荐指数
1
解决办法
1708
查看次数