For our (internal) automated test project, I am writing a part where parameters can be passed to an SSIS Package before it gets executed. The tester delivers the parameter name, value and desired datatype in a table format. I get the datatype and parses it to the correct type. We assume a happy flow (when testers do something wrong, no pretty feedback is needed, they can read the exceptions).
The following code is the snippet I am not happy with:
foreach (var row in parametersTable.Rows)
{
object value;
if (parametersTable.ContainsColumn("DataType") && !String.IsNullOrEmpty(row["DataType"]))
{
string dataType = row["DataType"].ToLower();
if ("int64".Equals(dataType))
{
value = Int64.Parse(row["Value"]);
}
else if ("datetime".Equals(dataType))
{
value = DateTime.Parse(row["Value"]);
}
else
{
throw new ArgumentException("DataType " + row["DataType"] + " is not supported");
}
}
else
{
value = row["Value"];
}
pfe.AddParameter(row["Name"], value);
}
I think, my string manipulation and testing can be improved and I'd like to make the "test and parse" section more expandable. Maybe an Enum or an helper object where I just have to add a single value to make it work for additional datatypes.
pfe
? \$\endgroup\$ – Heslacher Oct 31 '14 at 10:35SqlDbType
liked347hm4n
assumes? \$\endgroup\$ – Heslacher Oct 31 '14 at 10:57