I have a Task where I have to read an csv file and write the content into a c# List. Since the csv file can change its layout (caption/order) in the future I want to use a configuration file for mapping the attributes.
Now I am wondering if there is an example out there so I don't have to reinvent the weel :D
My datasource looks like this (tab stop seperated)
Customer No. Customer Name Created Discount
10215 John Doe 2010-08-25 5050.23
And my class like this:
Class Customer
{
string CustomerNo {get;set;}
string CustomerName {get;set;}
DateTime CreatedOn {get;set;}
decimal Discount {get;set;}
}
Now I want to have an external xml file with the definition so I can modify it at runtime without recompiling the code.
<customermapping mapstoclass="my.namespace.Customer">
<attribute csvcaption="Customer No." mapstoproperty="CustomerNo"
typeof="System.String" required="true">
<attribute csvcaption="Customer Name" mapstoproperty="CustomerName"
typeof="System.String" required="true">
<attribute csvcaption="Created" mapstoproperty="CreatedOn"
typeof="System.DateTime" required="false">
<attribute csvcaption="Discount" mapstoproperty="Discount"
typeof="System.Decimal" required="false">
</customermapping>
At the end of the Day I want to do the following: (I already can read all the values from the csv file (the first line is the caption and is in a seperate array)
List<Customer> customers =
CreateCustomerList(string[] csvCaptions, string[] csvLines,
"c:\customermapping.xml");
Shouldn't be to complicated but as I said, if someone already did something similar, any examples are welcome.