1
在我的场景中,我使用命令从数据库中删除了一些东西。我已经ReactiveCollection势必DataGrid的WPF中,并按照处理删除代码:ReactiveCommand:在ThrownExceptions中获取命令参数
RemoveProductCommand = ReactiveCommand.CreateFromTask<Product>(async product =>
{
await _licensingModel.RemoveProduct(product.Id);
});
RemoveProductCommand.ThrownExceptions.Subscribe(async ex =>
{
await ShowToUserInteraction.Handle("Could not remove product ");
});
Products.ItemsRemoved.Subscribe(async p =>
{
await RemoveProductCommand.Execute(p);
});
我的问题是,有没有获得在ThrownExceptions产品(命令参数)内置的方式吗?
我当然可以做这样的事情:
RemoveProductCommand = ReactiveCommand.CreateFromTask<Product>(async product =>
{
try
{
await _licensingModel.RemoveProduct(product.Id);
}
catch (Exception e)
{
throw new ProductRemoveException(product, e);
}
});
我的理由是,我想通知与信息用户“无法删除产品X”。
编辑: 好的,我编辑粘贴在这里的代码,并注意到等待command.Execute()和订阅之间的区别。 是可能的:
Products.ItemsRemoved.Subscribe(async p =>
{
try
{
await RemoveProductCommand.Execute(p);
}
catch (Exception e)
{
}
});
但什么ThrownExceptions?
太糟糕了,我希望统一解决方案,不管我如何调用命令 –