是否可以自动检测 Specflow 表中的类型?
Is it possible to automatically detect types in Specflow tables?
如果我有一个 Techtalk.Specflow.Table,是否可以自动检测 table 中元素的适当类型?
例如,如果我有以下步骤:
Given the following ticket sold on the 2019-01-01
|TicketId|Owner |Amount|Seat|
|0033 |John Doe |20.00 |3F |
如果我这样定义步骤
[Given(@"Given the following ticket sold on the (.*)")]
public void GivenTheFollowingPosition(DateTime date, Table table)
{
}
Specflow 能够正确检测和投射日期。因此我认为它也应该能够对 table 的元素这样做。您知道是否有可能实现它以及如何实现吗?
祝你有愉快的一天
查看 SpecFlow Assist Helpers. There are a few helpful methods, you can try to use table.CreateInstance<T>
method to convert row in your table to object for future use. You can also specify the custom mapping using TableAliases
attribute, see Working Effectively with SpecFlow Tables 文章了解详情
如果我有一个 Techtalk.Specflow.Table,是否可以自动检测 table 中元素的适当类型?
例如,如果我有以下步骤:
Given the following ticket sold on the 2019-01-01
|TicketId|Owner |Amount|Seat|
|0033 |John Doe |20.00 |3F |
如果我这样定义步骤
[Given(@"Given the following ticket sold on the (.*)")]
public void GivenTheFollowingPosition(DateTime date, Table table)
{
}
Specflow 能够正确检测和投射日期。因此我认为它也应该能够对 table 的元素这样做。您知道是否有可能实现它以及如何实现吗?
祝你有愉快的一天
查看 SpecFlow Assist Helpers. There are a few helpful methods, you can try to use table.CreateInstance<T>
method to convert row in your table to object for future use. You can also specify the custom mapping using TableAliases
attribute, see Working Effectively with SpecFlow Tables 文章了解详情