我必须更新我的collection
搜索field
parameter
发送replace
和values
old values
p.ItemName
。
喜欢 private void UpdateCollection(string fieldName, List<MarketRecord.FItemExtended> fitems , string oldVal , string newval)
{
PropertyInfo[] properties = typeof(MarketRecord.FItemExtended).GetProperties();
*var collectionToUpdate = fitems.Where(p => p.ItemName == oldVal).ToList();
collectionToUpdate.ForEach(x => x.ItemName = newval);*
}
我必须为426个属性执行此操作,这是tediuos的工作..我需要概括斜体代码..
{{1}}
答案 0 :(得分:0)
您可以迭代PropertyInfo对象,并使用反射在每个属性上调用getter和setter。它不一定在Linq中,因为这里的循环可能更具可读性。