二维对象数组返回类型 - NSubstitute [英] Two dimensional object array return type - NSubstitute
问题描述
我得到一个转换异常
System.InvalidCastException:无法转换类型的对象System.Object的[]'输入'System.Object的[,]。 在Castle.Proxies.ITestProxy.Get2DArray() 在Scratch.TestFixture.Get2DArray()在TestTest.cs:17行
System.InvalidCastException : Unable to cast object of type 'System.Object[]' to type 'System.Object[,]'. at Castle.Proxies.ITestProxy.Get2DArray() at Scratch.TestFixture.Get2DArray() in TestTest.cs: line 17
从下面的:
[TestFixture]
public class TestFixture
{
[Test]
public void Get2DArray()
{
Substitute.For<ITest>().Get2DArray().Returns(new object[1,1]);
}
}
public interface ITest
{
object[,] Get2DArray();
}
任何人都可以抛出任何光线对此怎么看?我想这是一个 NSubstitute 错误?
推荐答案
NSubstitute取决于城堡,它依赖于Reflection.Emit的,所以他们指责Reflection.Emit的。
NSubstitute depends on Castle, which depends on Reflection.Emit, so they blame Reflection.Emit.
http://issues.castleproject.org/issue/DYNPROXY-154
的解决方法,你的问题,看起来你无法使用多维数组。请注意,您的异常实际发生在 Get2DArray()
,不是返回
。
For a workaround to your problem, looks like you cannot use multidimensional arrays. Note that your exception actually occurs on Get2DArray()
, not Returns
.
请注意,我个人而言,我工作的一个嘲弄框架不使用Reflection.Emit的(也不城堡为此事),这将需要几个星期前,甚至是Alpha是准备好了,但它是一个相当强大的工具。在很多情况城堡失败,我不会(我的网站会列出这些)。如果您有兴趣,请按照 HTTP://smug.$c$cplex.com
Please note that I, personally, am working on a mocking framework that does NOT use Reflection.Emit (nor Castle for that matter) It's going to take a few weeks before even an Alpha is ready, but it is quite a powerful tool. There are many scenarios Castle fails that I don't (my site will list these). If you are interested, please follow http://smug.codeplex.com
这篇关于二维对象数组返回类型 - NSubstitute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!