【发布时间】:2013-03-07 18:42:34
【问题描述】:
我有一个对象数组,我想将它传递给一个只接受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);
}
【问题讨论】:
标签: c# oop parsing data-structures tibco