Hi,
When I want to extend an existing Object I create my own and use inherits clause, and works fantastic... problem is when I want to use this new Object instead of the original, the populate part is a "pain".
is there any AUTO POPULATE way of doing this?
Original Object: Customer My Object: CustomerWithGroup
public class CustomerWithGroup : Customer
{
public CustomerWithGroup() { }
public string GroupName { get; set; }
public string Fullname
{
get
{
return string.Format("{0} {1} {2}", firstname, middlename, lastname).Replace(" ", " ");
}
}
}
and I'm populating it like this:
customerswithgroup = new List<CustomerWithGroup>();
string groupname;
foreach (Customer c in customers)
{
groupname = customergroup.Find(x => x.customer_group_id == c.group_id).customer_group_code;
customerswithgroups.Add(
new CustomerWithGroup {
GroupName = groupname,
created_at = c.created_at, customer_id = c.customer_id, default_billing = c.default_billing, default_shipping = c.default_shipping, email = c.email, firstname = c.firstname, group_id = c.group_id, increment_id = c.increment_id, lastname = c.lastname, middlename = c.middlename, password_hash = c.password_hash, prefix = c.prefix, store_id = c.store_id, suffix = c.suffix, taxvat = c.taxvat, updated_at = c.updated_at, website_id = c.website_id });
}
It's a bunch of code! and you can imagine doing this for really big objects!
Ins't there a way of telling, like
Hei object, please load all the base members from this Object!
newCG = new CustomerWithGroup().LoadFromBase(c);
newCG.groupName = "my group";
customerswithgroup.Add( newCG );
Is there any trick we can use?