我有一个对象数组,我想将它传递给一个只接受DOUBLE
、NULL
或的STRING
方法DATETIME
。因此,当我尝试传入该值时,它会给出一个错误,指出我不能传入任何任意对象,并且必须将其解析为、DOUBLE
或NULL
首先。STRING
DATETIME
foreach (var currRow in dataSet.Tables[0].Rows)
{
var tuple = Com.Tibco.As.Space.Tuple.Create();
//here is where i loop through the object array
for (int i = 0; i < currRow.Values.Length; i++)
{
//here is where i try to pass it to the method (which doesn't accept it)
tuple.Put(dataSet.Tables[0].ColumnNames[i], currRow.Values[i]);
}
inSpace_.Put(tuple);
}
简而言之,我需要一种方法来解析每个对象并将其转换为适当的对象,然后将其放入元组中。
编辑:
这是我试图做的,但没有奏效:
foreach (var currRow in dataSet.Tables[0].Rows)
{
var tuple = Com.Tibco.As.Space.Tuple.Create();
for (int i = 0; i < currRow.Values.Length; i++)
{
if (currRow.Values[i] != null)
{
if (dataSet.Tables[0].ColumnNames[i].GetType().IsEquivalentTo(typeof(DateTime)))
{
DateTime value = DateTime.Parse(dataSet.Tables[0].ColumnNames[i].ToString());
tuple.Put(dataSet.Tables[0].ColumnNames[i], value);
}
else if (dataSet.Tables[0].ColumnNames[i].GetType().IsEquivalentTo(typeof(Double)))
{
Double value = Convert.ToDouble(dataSet.Tables[0].ColumnNames[i]);
tuple.Put(dataSet.Tables[0].ColumnNames[i], value);
}
else
{
string value = dataSet.Tables[0].ColumnNames[i].ToString();
tuple.Put(dataSet.Tables[0].ColumnNames[i], value);
}
}
}
inSpace_.Put(tuple);
}