/// <summary> /// 当需要持久化数据Provider中没有的信息时,用此类来合并Provider的数据 /// 和本地json数据文件。 /// </summary> /// <returns>合并后的数据列表</returns> public IEnumerable <AppRole> GetData() { var dbData = mProvider.GetData(); lock (mCachedData) { foreach (AppRole dbItem in dbData) { AppRole chItem = mCachedData.FirstOrDefault(ch => ch.Id == dbItem.Id); if (chItem != null) { dbItem.FunctionIds = chItem.FunctionIds; mCachedData[mCachedData.IndexOf(chItem)] = dbItem; } else { mCachedData.Add(dbItem); } } //移除Provider中没有的值 for (int i = mCachedData.Count - 1; i >= 0; i--) { if (!dbData.Any(d => d.Id == mCachedData[i].Id)) { mCachedData.RemoveAt(i); } } return(mCachedData); } }