[英]Preferring non-generic version of method over generic version in c#
我正在尝试使用JustMock存根NHibernate ICriteria。
具体来说,我正在尝试使用对象数组调用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}
});
当我执行第二行(编配)时,出现错误:
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
方法版本,有人知道如何强制执行此操作吗? 或者,如果是另一个问题,谁能指出我该如何解决呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.