最近正在与Rx合作,我在合并两个可观察对象并试图从它们发出命令时遇到了麻烦.
我有两个observable,所以我想从它们发出一个命令,只有当那些observable为真时,命令才能执行.这是我的代码:
BuyCommand = playerData.Gold.Select(x => x >= boosterStoreItem.price)
.Merge(inventoryItem.CanAddItem.Select(x => x))
.ToReactiveCommand();
Run Code Online (Sandbox Code Playgroud)
那么这段代码有点工作,但问题是,我有多个BuyCommands(它们之间没有共享任何可观察对象),如果任何CanAddItem改变状态,所有BuyCommands CanExecute都变为true.
我相信我在合并时犯了一个错误,应该以其他方式完成.那我该怎么办呢?
请注意,它是UniRx(统一的Rx),但它们几乎相同.
有没有办法在继承类型中使返回类型逆变?请参阅下面的示例代码.我需要这个实体框架.
public class InvoiceDetail
{
public virtual ICollection<Invoice> Invoices { get; set; }
}
public class SalesInvoiceDetail : InvoiceDetail
{
//This is not allowed by the compiler, but what we are trying to achieve is that the return type
//should be ICollection<SalesInvoice> instead of ICollection<Invoice>
public override ICollection<SalesInvoice> Invoices { get; set; }
}
Run Code Online (Sandbox Code Playgroud)