Currently, I have a datatable and use a ForEach to loop over it and build objects to add to my list, List<MyClass>
.
Unfortunately, this approach requires a separate method for each type just to handle the column mappings. The columns in the datatable DO NOT have the same names as the object properties.
How can I create a generic method to achieve the column mapping? Ideally something like a generic BuildObjects<T>
method that can handle BuildObjects<Car>
, BuildObjects<Dog>
and BuildObjects<Tree>
and map the row column to the object property.