I'm creating a generic object from DB data:
object[] data = new object[dataReader.FieldCount];
dataReader.GetValues(data);
T t = (T)Activator.CreateInstance(typeof(T), data);
But, types with no constructor error on the third line. I want to add an if:
if (typeof(T).GetConstructor(data.TypesOf()) != null)
data.TypesOf() is actually an array - Type[] - that contains all types of the objects in data.
What is the equivalent to data.TypesOf() that really works?
Or do I need to iterate data and build it myself?
datais always anobject[]- it has no relation totypeof(T)whatsoever, since it is just the values from the reader. What are you trying to represent withdata.TypesOf()?data.TypesOf()is aType[]array which contains the types ofdata. In order, at that. Added to question.