Hey Alex,
I've been nosing around the Reflection class you posted, interesting stuff so far. I have a question about the planned features, especially about the 'on the fly' generation of types from various inputs. How generic are you able to make this? I mean, I can imagine creating objects froma DataTable like this (i'm using some NVigorate functions in the code below):
public static object[] CreateObjectsFromDataTable(DataTable aTable, Type aType)
{
object[] ObjList = new object[aTable.Rows.Count];
for(int i=0;i<aTable.Rows.Count;i++)
{
ObjList[i] = CreateObjectFromDataRow(aTable.Rows[i], aType);
}
return ObjList;
}
public static object CreateObjectFromDataRow(DataRow aRow, Type aType)
{
ConstructorInfo aConstrInf = aType.GetConstructor(new Type[0]);
if (aConstrInf.GetParameters().Length > 0)
{
Throw(String.Format("{0} does not have a parameterless contructor", aType.FullName));
}
object aObj = aConstrInf.Invoke(new object[0]);
foreach (DataColumn aColumn in aRow.Table.Columns)
{
WriteProperty(aObj, aColumn.ColumnName, aRow[aColumn.ColumnName], new object[0]);
}
return aObj;
}
In this example I'm assuming that the column names are the same as the property names in the targeted type. Should they not be the same then I guess the DataTable would need additional 'massaging' before its passed to the function.
Is this roughly the type of strategy you have in mind? So how would this work for filling an object from XML? Would you simply pass in a node collection that uses the element's name as the property binding?
Anyways, I think the Reflection class shows great potential for all sorts of object factory type of work, I'll be watching NVigorate's progress closely. Thank you very much for your efforts so far.
cheers,
Roland





