[英]Preferring non-generic version of method over generic version in c#
I'm trying to stub an NHibernate ICriteria using JustMock. 我正在尝试使用JustMock存根NHibernate ICriteria。
Specifically I'm trying to stub the List<> method when it is called with an array of object: 具体来说,我正在尝试使用对象数组调用List <>方法时:
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}
});
When I execute the second line (the Arrange) I'm getting the error: 当我执行第二行(编配)时,出现错误:
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
has both a List()
and a List<T>()
method and it looks like the compiler is picking up the non-generic version of the List
method instead of the generic version. ICriteria
同时具有List()
和List<T>()
方法,看起来编译器选择的是非通用版本的List
方法,而不是通用版本。 Assuming that I'm correct and that it's picking up the wrong version of the List
method, does anybody know how to force this? 假设我是正确的并且选择了错误的
List
方法版本,有人知道如何强制执行此操作吗? Or if it's a different problem can anyone point me to how to solve this? 或者,如果是另一个问题,谁能指出我该如何解决呢?
I tried it with a recent version of JustMock and the problem doesn't crop up. 我用JustMock的最新版本进行了尝试,但问题并没有出现。
Judging by the presence of obfuscation, it seems that you're using a pretty old version. 从混淆的存在来看,似乎您使用的是旧版本。
You can download the latest version of JustMock from NuGet or from your Telerik account. 您可以从NuGet或您的Telerik帐户下载最新版本的JustMock。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.