【发布时间】:2014-01-29 08:17:18
【问题描述】:
我正在使用 ReactiveUI 及其路由器。
我的一些IRoutableViewModels 实现了一个接口IHaveCommands,它有一个属性IEnumerable<IReactiveCommand> Commands { get; }
所以,我想要的是我的IScreen 实现AppBootstrapper 中当前视图模型的命令列表。
什么是“正确”的实现方式?
我已经让它与以下代码一起工作,但我的直觉告诉我还有其他更好的方法来做到这一点......
public class AppBootstrapper : ReactiveObject, IScreen
{
public IRoutingState Router { get; private set; }
public AppBootstrapper(IMutableDependencyResolver dependencyResolver = null, IRoutingState testRouter = null)
{
Router = testRouter ?? new RoutingState();
Router.CurrentViewModel.Where(x => x != null)
.Select(x => typeof(IHaveCommands).IsAssignableFrom(x.GetType()) ? ((IHaveCommands)x).Commands : null)
.ToProperty(this, x => x.Commands, out _toolbarCommands);
...
}
readonly ObservableAsPropertyHelper<IEnumerable<CommandSpec>> _toolbarCommands;
public IEnumerable<CommandSpec> ToolbarCommands { get { return _toolbarCommands.Value; } }
}
有什么建议吗?
【问题讨论】:
标签: c# system.reactive reactiveui