R
ricolee99
Hi everyone,
I have a problem that i have been trying to solve for awhile. I'm
given a code where the purpose is to create a general dataset mapper.
Given any dataset, i have a class, "Mapper.cs" that's supposed to map
objects from any type of dataset to any type of object.
Inside Mapper.cs, there's a method,
object[] Map(Type typeOfObjectToMap, DataSet theDataSet)
{
//iterate DataSet();
}
which contains implementation to iterate through the dataset rows and
converts each column in the row to the appropriate type in the class
typeOfObjectToMap.
For instance:
DataSet=
FirstName | LastName | Age
John Doe 35
Rachel Gates 40
typeOfObjectToMap =
Class peopleInfo
{
public string FirstName;
public string LastName;
public string Age;
get...
set..
}
so in Map method, it would iterate thru the dataset and find the
corresponding column value in the peopleInfo class to identify what
type to convert the dataset value to. Thus, it will convert the John
value to a string, Doe value to a string and Age value to an int32.
I already have implementation in the code to iterate and convert each
value to the appropriate type and return each value in the column as an
object.
The problem is at the end of the Map method, I must return an object[]
.. Each object in the object[] must contain the boxed object of the
type passed in the Map argument: typeOfObjectToMap which essentially
contains a single row info. from the dataset. Can someone please tell
me how I can accomplish this?
Thanks so much, Sharon
I have a problem that i have been trying to solve for awhile. I'm
given a code where the purpose is to create a general dataset mapper.
Given any dataset, i have a class, "Mapper.cs" that's supposed to map
objects from any type of dataset to any type of object.
Inside Mapper.cs, there's a method,
object[] Map(Type typeOfObjectToMap, DataSet theDataSet)
{
//iterate DataSet();
}
which contains implementation to iterate through the dataset rows and
converts each column in the row to the appropriate type in the class
typeOfObjectToMap.
For instance:
DataSet=
FirstName | LastName | Age
John Doe 35
Rachel Gates 40
typeOfObjectToMap =
Class peopleInfo
{
public string FirstName;
public string LastName;
public string Age;
get...
set..
}
so in Map method, it would iterate thru the dataset and find the
corresponding column value in the peopleInfo class to identify what
type to convert the dataset value to. Thus, it will convert the John
value to a string, Doe value to a string and Age value to an int32.
I already have implementation in the code to iterate and convert each
value to the appropriate type and return each value in the column as an
object.
The problem is at the end of the Map method, I must return an object[]
.. Each object in the object[] must contain the boxed object of the
type passed in the Map argument: typeOfObjectToMap which essentially
contains a single row info. from the dataset. Can someone please tell
me how I can accomplish this?
Thanks so much, Sharon