I\'m writing a specific kind of object-mapper. Basically I want to convert from a DataTable
that has the fields a
, b
and c
Late to the party, but Marc Gravell has a nice utility called FastMember. With FastMember, you can map from a DataTable to an object, even a dynamic.
var accessor = TypeAccessor.Create(type);
string propName = // something known only at runtime
while( /* some loop of data */ ) {
accessor[obj, propName] = rowValue;
}
I'ved used this in production and it performs nicely.