If you resulting object is completely dynamic you could use a dictionary instead of a strongly typed object. Or, if you want at least an object, go with dynamic objects. Either use the dynamic
keyword and a List<dynamic>
or use DynamicObject
.
The difference to a dictionary is not that big though...
Something like this could do it:
SqlDataReader reader = command.ExecuteReader();
var listOfValues = new Dictionary<string, object>();
while (reader.Read())
{
for(int i = 0; i <reader.FieldCount;i++)
{
listOfValues.Add(reader.GetName(i), reader.GetValue(i));
}
}