r.LoadTranQuo-6ren">
gpt4 book ai didi

c# - RhinoMocks 错误 "Only assignment, call, increment, decrement, and new object expressions can be used as a statement"

转载 作者:太空狗 更新时间:2023-10-30 01:24:34 26 4
gpt4 key购买 nike

var CoreDataManagerMock = MockRepository.GenerateMock<ICoreDataManager>();
CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedBasicRates).Return(new List<int>());
CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedCompoundRates).Return(new List<int>());
CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedResetRates).Return(new List<int>());

所以我想设置它,以便对模拟对象的这三个调用返回 new List<int>() ,但我得到了这个编译器错误:

Only assignment, call, increment, decrement, and new object expressions can be used as a statement

我是不是设置错了?实际方法返回类型 List<int> .

最佳答案

因为这些是方法,所以在设置 Stub 时需要括号:

CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedBasicRates())
.Return(new List<int>());

关于c# - RhinoMocks 错误 "Only assignment, call, increment, decrement, and new object expressions can be used as a statement",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8902281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com