我在尝试在方法中使用泛型类型时遇到错误。
我的方法有太多的逻辑,我只是添加了一个代码片段
泛型方法:
public void MyGenericMethod<T, T1>(List<T1> arg1) where T : IInterface, new()
{
var useMethod = typeof(T);
Moq.Setup(x => x.useMethod(It.IsAny<DateTime>(), It.IsAny<string>()))
.Throws(new Exception("MoqException"));
var returnDataList = MyService.arg1(new DateTime(), "12345");
}
实际方法:
public void SampleMethod()
{
Moq.Setup(x => x.GetCustomerMethod(It.IsAny<DateTime>(), It.IsAny<string>()))
.Throws(new Exception("MoqException"));
var returnDataList = MyService.GetServiceMethod(new DateTime(), "12345");
}
错误:对于useMethod,此行Moq.Setup(x => x.useMethod (It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new Exception("MoqException"));
会抛出。
我正在学习c#中的泛型。请帮我解决。