错误:当我在泛型方法中使用泛型类型时,无法解析符号' xxxx'

时间:2014-07-06 15:12:10

标签: c# generics moq

我在尝试在方法中使用泛型类型时遇到错误。

我的方法有太多的逻辑,我只是​​添加了一个代码片段

泛型方法:

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#中的泛型。请帮我解决。

0 个答案:

没有答案