Just started studying reflection and im having a lot of issues. I want to cast to find the type of properties and then set them. So i wanted to cast to these properties type.
protected override object Load(SqlDataReader dr)
{
object item = Activator.CreateInstance(klass);
foreach (var p in klass.GetProperties())
{
MethodInfo pSet = p.GetSetMethod();
Type pType= p.PropertyType;
object setParam = dr[p.Name];
object[] paramArray = (object[])Array.CreateInstance(pType, 1);
paramArray[0] = setParam;
pSet.Invoke(item, paramArray);
}
return item;
}
Aucun commentaire:
Enregistrer un commentaire