嗨,我是在C#中新,我想请问如何写这个代码更prety如何写得很漂亮?
public void Update(Product pr)
{
Product prod = GeProductById(pr.ProductID);
prod.Name = pr.Name;
prod.Count = pr.Count;
prod.InputPrice = pr.InputPrice;
prod.InputDate = pr.InputDate;
prod.OutPrice = pr.OutPrice;
prod.InputPriceByCurrency = pr.InputPriceByCurrency;
prod.InputPriceCurrency = pr.InputPriceCurrency;
prod.ComeOwner = pr.ComeOwner;
prod.GroupID = pr.GroupID;
prod.Discount = pr.Discount;
_context.SubmitChanges();
}
所有它不只是所有属性复制除ID。我可以很快写出来吗? Thanx和对不起我的英语不好
这有什么错呢?似乎完全可读,除了奇怪的标签和名字。直接保存`pr`会更好。你在这里使用框架吗? – Kobi 2010-12-04 15:39:55
@Kobi是的)但如果它将是10或20个属性))我想写一下。 Thanx的回应 – 2010-12-04 15:41:46
那么你会通过反射,但我不会建议这样做... – 2010-12-04 15:43:04