private void button_add_Click(object sender, EventArgs e) { string name = ((Button)sender).Name.Split('_')[1]; string propertyName = name.Substring(0, 1).ToUpper() + name.Substring(1); Goods selectedGoods = goodService.QueryGoods(name); int count = (int)this.GetType().GetProperty(propertyName).GetValue(this); itemList.Add(new OrderDetails(count, selectedGoods)); MessageBox.Show("已加入购物车"); }