/// <summary> /// get minus element into list by model /// </summary> /// <typeparam name="T">model type</typeparam> /// <param name="listA">model list 1</param> /// <param name="listB">model list 2</param> /// <returns>minus element list</returns> public static List <T> GetMinus <T>(List <T> listA, List <T> listB) where T : class { if (listA == null || listA.Count <= 0) { return(null); } if (listB == null || listB.Count <= 0) { return(listA); } List <T> res = new List <T>(); listA.ForEach(a => { bool flag = true; foreach (T item in listB) { if (ModelTool.ACompareB(a, item)) { flag = false; break; } } if (flag) { res.Add(a); } }); return(res.Count == 0 ? null : res); }
/// <summary> /// get same element into list by model /// </summary> /// <typeparam name="T">model type</typeparam> /// <param name="listA">model list 1</param> /// <param name="listB">model list 2</param> /// <returns>same element list</returns> public static List <T> GetJoin <T>(List <T> listA, List <T> listB) where T : class { if (listA == null || listA.Count <= 0) { return(null); } if (listB == null || listB.Count <= 0) { return(null); } List <T> res = new List <T>(); listB.ForEach(a => { foreach (T item in listA) { if (ModelTool.ACompareB(a, item)) { res.Add(a); break; } } }); return(res.Count == 0 ? null : res); }