In specflow there is a class called Table
which has a method Table.CreateInstance<T>()
. T
basically is a class whose properties will get automatically mapped with contents of the table.
I have multiple classes that T
needs to be mapped to based on className that gets passed as a string.
Example:
public void ThenTheFollowingFieldsArePopulated(Table table, string className)
{
Type myType = Type.GetType($"abcd.Data.SecType.{className}, abcd.Data");
var obj = Activator.CreateInstance(myType);
var basicOrder = table.CreateInstance<obj>();
}
I am successfully populating both myType
and obj
. But...
I get a compilation error as:
"obj is a variable but used as a type".
Please could some one help on a fix for this?