|
-
April 29th, 2009, 08:17 PM
#1
BindingList<T> and reflection?
If I have a business object, Order, where Order contains OrderDetails, where OrderDetails is a BindingList<OrderDetail>. How can I create this using relfection?
I have an object builder that dynamically creates the SQL statements and gets a list of order details. Now I need to place those order details in the BindingList<OrderDetail> details member of my object?
Code:
/// obj - Container object which holds the BindingList<T> object.
/// property - The PropertyInfo object for the BindingList<T> object.
/// targetType - The type of object that the data reader has and the BindingList<T> should contain.
/// rdr - The date reader with the records?
void LoadObjects(ObjectBase obj, PropertyInfo property, Type targetType, IDataReader rdr)
{
//// I need to create the binding list???????
BindingList<????targetType????> list = Activator.CreateInstance(????);
while(rdr.Read())
{
ObjectBase newObj = Activator.CreateInstance(targetType);
FillObject(newObj, rdr);
list.Add(newObj);
}
property.SetValue(obj, list, null);
}
Any help at all with this?
Mike B
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|