Thanks for the response chanmm.
I guess i didn't really explain it that well in my posting. Here's the
code from the map method:
public object[] Map(Type type, DataSet ds)
{
// get the public properties from the type class so i can cross ref. w/
the dataset
PropertyInfo[] propertyInfoFromType =
type.GetProperties(BindingFlags.Public|BindingFlag s.Instance);
if(ds.Tables[0].Columns.Count != propertyInfoFromType.Length)
{
throw new ApplicationException("Number of Columns from DataSet does
not match number of properties from Type : " + type.FullName);
}
/*iterate thru each item in dataset and convert to appropriate type*/
foreach (DataRow r in ds.Tables[0].Rows)
{
foreach(PropertyInfo propertyInfo in propertyInfoFromType)
{
//1 converted parameter
object [] array = basicPropertyArgumentConverter.GetValue
(propertyInfo.PropertyType.Name, r[propertyInfo.Name]);
}
}
}
Here's a sample of a Type being passed as a parameter into the map:
public class CustomerTarget
{
private string firstName = String.Empty;
private string lastName = String.Empty;
private int age = 0;
private DateTime birthDate = DateTime.MinValue;
public CustomerTarget() {}
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
public DateTime BirthDate
{
get { return birthDate; }
set { birthDate = value; }
}
}
I have two questions:
How do I create the type objects passed into the method and how do I
assign the properties of those objects that I created to the array
objects passed back from basicPropertyArgumentConverter.GetValue()???
The idea is this mapper is intended to take in any type of class type
to map to any corresponding dataset.
The goal for me is to pass back an array of objects, each object can be
unboxed back to the class object.
please this is really urgent for me, any help would be appreciated!
Thank you
Sharon
chanmm wrote:
Create an Object array inside the method, assign the object to generic
Object array and return it. Have a try. It is good to attach your cs files.
chanmm
<ri*******@gmail.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com... 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