隐式类型的三元组数组
我有一个单元测试方法:
private bool TestCompatibility(string type1, string type2, bool shouldBeCompatible)
{
}
因为它“知道”哪些类型(设计)兼容,所以它调用正在测试的单元并查找错误。仅当类型不兼容时才会出现错误,因此方法测试单元类型检查代码是否正确实现。
问题:我如何编写三胞胎集合?
我想要类似的东西:
var ar = { { "Num", "Num", true }, { "Num", "Datetime", false } };
foreach (var triplet in ar)
{
// ???
}
使用隐式类型。
PS 我知道我可以将属性与 NUnit 一起使用。尽管如此,我想看看如何在没有库的情况下编写它。
问候,
I have a unit test method:
private bool TestCompatibility(string type1, string type2, bool shouldBeCompatible)
{
}
As it "knows" which types are (designed) compatible, it makes a call to the unit that is being tested and looks for errors. Errors should appear for incompatible types only, so the method tests, is units type-checking code right-implemented or not.
The question: how have I write the triplets collection?
I want something like:
var ar = { { "Num", "Num", true }, { "Num", "Datetime", false } };
foreach (var triplet in ar)
{
// ???
}
with implicit typing.
P.S. I know that I can use attributes along with NUnit. Nevertheless, I want to see, how it can be written without libraries.
Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这是否是您正在寻找的,但您可以使用匿名类型:
I don't know if this is what you are looking for, but you could make use of anonymous types: