使用linq动态查找和替换

使用linq动态查找和替换,linq,Linq,我必须更新我的集合,搜索作为参数发送的字段,并将其中的值替换为旧值 像p.ItemName一样,我必须为426个属性执行此操作,这是TEDIOUS作业。。我需要对斜体代码进行泛化 private void UpdateCollection(string fieldName, List<MarketRecord.FItemExtended> fitems , string oldVal , string newval) { PropertyI

我必须更新我的集合,搜索作为参数发送的字段,并将其中的值替换为旧值

像p.ItemName一样,我必须为426个属性执行此操作,这是TEDIOUS作业。。我需要对斜体代码进行泛化

 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);*
}

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