【问题标题】:UserError.Throw with non-default backing field naming convention使用非默认支持字段命名约定的 UserError.Throw
【发布时间】:2013-01-21 06:01:08
【问题描述】:

我无法理解我在使用 UserError 课程时做错了什么。

这是我的 ViewModel 中的代码:

this.CheckForUpdateCmd = new ReactiveAsyncCommand(Observable.Return(true));

UserError.RegisterHandler(
    uerror =>    
    {
        logger.Error(uerror.ErrorMessage, uerror.InnerException);
        if (dlgService.ShowMessageBox(  
            this, 
            uerror.ErrorMessage, 
            ClientStrings.AboutVM_ErrorCheckUpdates, 
            MessageBoxButton.YesNo, 
            MessageBoxImage.Warning) == MessageBoxResult.Yes)
        {
            return Observable.
                Return(RecoveryOptionResult.RetryOperation);
        }
        return Observable.  
            Return(RecoveryOptionResult.FailOperation);
    });

this.
        CheckForUpdateCmd.
        ThrownExceptions.
        SelectMany(ex => 
            UserError.Throw(
                ClientStrings.AboutVM_ErrorCheckUpdates, 
                ex)).
        Subscribe(
            recoverOption =>
            {
                if (recoverOption == RecoveryOptionResult.RetryOperation)
                {
                   this.CheckForUpdateCmd.Execute(null);
                }
            });

((ReactiveAsyncCommand)this.CheckForUpdateCmd).
    RegisterAsyncAction(_ =>
        { 
            throw new Exception("TESTING 123"); 
        });

在异步操作中引发异常后,它会正确传播到SelectMany 内的我的Usererror.Throw。在 Throw 方法中,RxUI 抛出一个 ArgumentException:“你必须为这个属性声明一个支持字段,名为:recoveryOptions”

我已经对此进行了调查,并且 UserError 类有一个 _RecoveryOptions,它是从 UserError 本身设置的。但是,我在我的 App 的 OnStartup 事件处理程序中使用了这个扳手:

RxApp.GetFieldNameForPropertyNameFunc = prop => prop.Length == 1 ? prop.ToLower() : char.ToLower(prop[0]) + prop.Substring(1);

基本上,我希望我的支持字段以小写字母开头,而不是下划线/大写字母。到目前为止,RxUI 已经兑现了这一点,直到我尝试使用 UserError。我错过了一步还是这是 RxUI 中的错误?

这适用于 Reactive UI 3.2.0

【问题讨论】:

    标签: reactiveui


    【解决方案1】:

    这是很久以前修复的old bug in ReactiveUI - 要么升级到 ReactiveUI 4.x,要么将 Errors.cs 复制到您的项目中并使用它

    【讨论】:

    • 感谢 Paul 提供的信息。感谢 ReactiveUI!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 1970-01-01
    • 2011-07-23
    • 2020-12-11
    • 1970-01-01
    • 2013-03-13
    • 2023-04-05
    相关资源
    最近更新 更多