与c#中的泛型版本相比,更喜欢方法的非泛型版本

本文关键字:泛型 版本 更喜欢 方法 | 更新日期: 2023-09-27 18:28:33

我正试图使用JustLock来存根一个NHibernate ICriteria。

特别是,我正在尝试截断列表<>方法(当使用对象数组调用时):

var mockCriteria = Mock.Create<ICriteria>();
Mock.Arrange(() => mockCriteria.List<object[]>()).Returns(
    new object[]
    {
        new object[] {"CompanyX", 1, 1, 1, 0}, 
        new object[] {"CompanyX", 1, 1, 1, 0}, 
        new object[] {"CompanyY", 2, 1, 1, 0}
    });

当我执行第二行(排列)时,我得到了错误:

System.InvalidOperationExceptionSystem.Collections.IList List() is not a GenericMethodDefinition. MakeGenericMethod may only be called on a method for which MethodBase.IsGenericMethodDefinition is true.
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   at 'x7'x5'x2.'x8'x2.'x3'x15'x2(Type 'x8, MethodBase , BindingFlags 'x1C'xF'x2)   at 'x6'x2.'x6'x2.Create(Object , MethodInfo 'x6, Boolean 'x6'x2)   at 'x7'x5'x2.'x11'x14'x2.'x11'x13'x2('xF'x2 'x5'xF)   at Telerik.JustMock.Mock.'x1F.'x15'x2('x11'x14'x2 'x2)   at 'x7'x5'x2.'x5'x14'x2.'x1C['x4'x14'x2,'x5'x2]('xF'x2 'xF'x2, Func`2 'x3'x14'x2)   atThreshold.DeviceManagerGateway.UnitTests.Queries.DeviceNetworkStatusQueryFacts.RetrieveDevicesAsDeviceNetworkStats() in DeviceNetworkStatusQueryFacts.cs: line 24

ICriteria同时具有List()List<T>()方法,并且看起来编译器正在获取List方法的非泛型版本而不是泛型版本。假设我是正确的,并且它使用了错误版本的List方法,有人知道如何强制执行吗?或者,如果这是一个不同的问题,有人能告诉我如何解决吗?

与c#中的泛型版本相比,更喜欢方法的非泛型版本

我在最近版本的JustLock中尝试过,但没有出现问题。

从混淆的存在来看,你似乎在使用一个相当旧的版本。

您可以从NuGet或Telerik帐户下载最新版本的JustLock。