M
MattC
Hi,
I have a collection class derived from ArrayList, it stores colletions of
objects from my objet model. I Didn't want to have to create a specialised
collection for each object type so I created the following static method.
public static MyCollection CreateGenericCollection(DataTable rates, Assembly
a, Type t)
{
MyCollection c = new MyCollection(); // create new collection
Type[] types = new Type[1];
types[0] = typeof(DataRow); //all my BLL object have to take a DataRow in
a constructor
object obj=Activator.CreateInstance(t); //get the type of the object I
am creating collection of
ConstructorInfo ci = t.GetConstructor(types); //get its constructor info
object[] p=new object[1];
foreach(DataRow row in rates.Rows) //convert to for loop later
{
p[0] = row;
c.Add(ci.Invoke(p)); //invoke the constructor passing in the row and add
to Arraylist
}
return c; //send back filled collection when done?
}
Oringinally I had each BLL object to something like this.
public static MyCollection CreateLabourRateCollection(DataTable rates)
{
MyCollection c = new MyCollection();
foreach(DataRow row in rates.Rows)
{
c.Add(new LabourRate(row));
}
return c;
}
Ok my question.
How slow is Reflection given that the Assemblies to lookup are all located
in the same place?
Also any suggestions on the method would be cool, thanks.
TIA
MattC
I have a collection class derived from ArrayList, it stores colletions of
objects from my objet model. I Didn't want to have to create a specialised
collection for each object type so I created the following static method.
public static MyCollection CreateGenericCollection(DataTable rates, Assembly
a, Type t)
{
MyCollection c = new MyCollection(); // create new collection
Type[] types = new Type[1];
types[0] = typeof(DataRow); //all my BLL object have to take a DataRow in
a constructor
object obj=Activator.CreateInstance(t); //get the type of the object I
am creating collection of
ConstructorInfo ci = t.GetConstructor(types); //get its constructor info
object[] p=new object[1];
foreach(DataRow row in rates.Rows) //convert to for loop later
{
p[0] = row;
c.Add(ci.Invoke(p)); //invoke the constructor passing in the row and add
to Arraylist
}
return c; //send back filled collection when done?
}
Oringinally I had each BLL object to something like this.
public static MyCollection CreateLabourRateCollection(DataTable rates)
{
MyCollection c = new MyCollection();
foreach(DataRow row in rates.Rows)
{
c.Add(new LabourRate(row));
}
return c;
}
Ok my question.
How slow is Reflection given that the Assemblies to lookup are all located
in the same place?
Also any suggestions on the method would be cool, thanks.
TIA
MattC