public static class DataSetUtil
{
public static DataSet GetDataSetFromInstance(object instance)
{
DataSet result = new DataSet();
DataTable dt = new DataTable();
Type t = instance.GetType();
List<object> values = new List<object>();
foreach (PropertyInfo pi in t.GetProperties())
{
dt.Columns.Add(new DataColumn(pi.Name, pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericArguments()[0] : pi.PropertyType));
values.Add(pi.GetValue(instance, null));
}
result.Tables.Add(dt);
dt.Rows.Add(values.ToArray());
return result;
}
}