使用linq动态查找和替换

时间:2013-06-05 05:45:39

标签: linq

我必须更新我的collection搜索field parameter发送replacevalues 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}}

1 个答案:

答案 0 :(得分:0)

您可以迭代PropertyInfo对象,并使用反射在每个属性上调用getter和setter。它不一定在Linq中,因为这里的循环可能更具可读性。