[英]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.