Filling in the properties of a class dynamic/automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • msjonathan
    New Member
    • Dec 2009
    • 24

    Filling in the properties of a class dynamic/automatically

    hi,
    I have the following problem: I have to write an import.
    I have a dataset with data from excel/txt/csv file. (Dataset is not bound to ImportEmployees )
    and I have a class: ImportEmployee:
    • FirstName
      LastName
      Mail
      etc ...


    The properties of class ImportEmployee should be filled in with the data from the dataset.
    The problem is I do not know if a column is that (FirstName,...) property or is it a column I should skip.

    I hope my explanation is clear.

    Has anyone an idea to fill in those properties?
  • msjonathan
    New Member
    • Dec 2009
    • 24

    #2
    I used this
    Eployee emp = new Employee();
    Type typeOfEmp = emp.GetType();
    foreach (PropertyInfo pro in typeOfEmp .GetProperties( ))
    {
    pro.SetValue(em p, DATA , null);
    }
    Greetz Jonathan

    Comment

    Working...