If I understand what you want correctly.
I've done that once, and you can look at it
here[
^], but it's a fairly advanced solution using not just reflection but also Expression trees for performance reasons.
But to answer the specifics of your question.
The first parts is to get the properties of the Target class:
Type TShirtType = typeof(TShirt);
And then you can loop the properties using:
foreach (PropertyInfo TShirtMember in TShirtType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (TShirtMember.CanWrite)
Then you need to compare with the fields in the datareader.
Make an inner loop for the fields:
for (int Ordinal = 0; Ordinal < reader.FieldCount; Ordinal++)
Now you can compare the names:
TShirtMember.Name.ToLower() == reader.GetName(Ordinal).ToLower()
If you have a match you can set the Property:
TargetMember.SetValue(t,reader.Getvalue(Ordinal))
Where t is your TShirt instance