反射的使用:通过字符串查找属性,并给属性赋值
private void InitDicData(List<BD_DataDictionary> listDic, List<OM_Enterprise> listAll, string cDicType) { var listTemp = listDic.Where(p => p.字典类型.Equals(cDicType)).ToList(); var propertyInfo = new OM_Enterprise().GetType().GetProperty(cDicType); foreach (var item in listAll) { var propertyValue = propertyInfo.GetValue(item, null); var objDic = listTemp.Where(p => p.字典项.Equals(propertyValue.ToString())).FirstOrDefault(); if (objDic != null) { propertyInfo.SetValue(item, objDic.字典项长文本); } } }