當我想延長現有對象創建我自己的,並使用繼承條款,以及夢幻般的工作......問題是,當我想用的,而不是原來的這個新對象,填充部分是一個「痛苦」。繼承對象和自動填充
有沒有這樣做的自動人羣的方式?
原來的對象:客戶 我的對象: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(" ", " ");
}
}
}
,我填充它是這樣的:
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 });
}
這是一個一串代碼!你可以想象爲真正的大物體做這件事!
Ins't有說服力的方式,像
喜對象,請加載所有的基地成員從該對象!
newCG = new CustomerWithGroup().LoadFromBase(c);
newCG.groupName = "my group";
customerswithgroup.Add(newCG);
有沒有我們可以使用任何把戲?
你的意思是「class」而不是「object」,對吧? – 2010-01-31 13:10:24
如果它只有一個組,它爲什麼叫'CustomerWithGroups'? – SLaks 2010-01-31 13:14:30
@Konrad:Class == Business Object,不是對象的類型。 @SLaks:輸入錯誤:D – balexandre 2010-01-31 13:35:04