模拟帮助?我找不到问题所在

发布于 2024-08-21 00:48:01 字数 419 浏览 15 评论 0原文

我有一个这样定义的接口:

public interface IDatabase{ void Get<TTypeToFetch> ();}

当我尝试这样做时: Mockery 嘲讽 = new Mockery(); IDatabase db = mockery.NewMock(); 我收到以下错误:

System.TypeLoadException:System.TypeLoadException:方法实现中的主体签名和声明不匹配

了什么问题? (我使用 Visual Studio 2008 和 nmock2) 请大家给我一个答案,我必须尽快完成这个工作。 谢谢, 路易莎

I have an interface definded like this:

public interface IDatabase{ void Get<TTypeToFetch> ();}

and when I try to do:
Mockery mockery = new Mockery();
IDatabase db = mockery.NewMock<IDatabase>();

I get the following error:

System.TypeLoadException: System.TypeLoadException: Signature of the body and declaration in a method implementation do not match

What is wrong? (I am using Visual Studio 2008 with nmock2)
Please could everyone give me an answer, I have to finish this soon.
Thanks,
Luisa

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2024-08-28 00:48:01

我认为这可能是 NMock 的问题,甚至可能是一个错误。类型 IDatabase 不是通用的,因此当您调用 Get 时,可以在运行时使用不同的 T。但是当 NMock 生成模拟时,它似乎并不理解这种情况,并且 kablammo ——每个方法签名都是不同的,具体取决于提供的类型参数。

尝试这样做:

public interface IDatabase<T> {
  void Get<T>();
}

另外,Get 的类型不应该是 T,而不是 void 吗?

I think this may be a problem with NMock, possibly even a bug. The type IDatabase is not generic, so when you invoke Get<T>, different Ts could be used at runtime. But when NMock is generating the mock, it doesn't appear to understand that this is the case, and kablammo -- each method signature is different, depending on the type parameter supplied.

Try doing this instead:

public interface IDatabase<T> {
  void Get<T>();
}

Also, shouldn't the type of Get be T, not void?

深爱不及久伴 2024-08-28 00:48:01

我自己的界面也有同样的例外。当我将界面更改为公共时,一切运行正常。

I had the same exception with my own interface. When i change interface to be public everything runs ok.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文