Exemplo n.º 1
0
        /// <summary>
        /// 查重添加
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="t1">集合1</param>
        /// <param name="t2">集合2</param>
        /// <returns></returns>
        private static void AddCnki <T>(this List <T> t1, List <T> t2)
        {
            List <T> resultList = new CloneableClass().DeepClone(t1);

            foreach (var item in t2)
            {
                if (t1.Contains(item))
                {
                    continue;
                }
                resultList.Add(item);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查重添加
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="t1">集合1</param>
        /// <param name="t2">集合2</param>
        /// <returns></returns>
        private static List <T> AddCnki <T>(this List <T> t1, List <T> t2)
        {
            var      cloneClass = new CloneableClass();
            List <T> resultList = new List <T>();

            t1.ForEach(item => { resultList.Add(cloneClass.DeepClone(item)); });
            foreach (var item in t2)
            {
                if (t1.Contains(item))
                {
                    continue;
                }
                resultList.Add(item);
            }

            return(resultList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 查重添加
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="t1">集合1</param>
        /// <param name="t2">集合2</param>
        /// <returns></returns>
        private static List <T> AddCnki <T>(this List <T> t1, List <T> t2)
        {
            List <T>      resultList    = new CloneableClass().DeepClone(t1);
            List <string> resultStrList = new List <string>();

            foreach (var item in t2)
            {
                if (IsExist(item))
                {
                    continue;
                }
                resultList.Add(item);
            }

            return(resultList);

            bool IsExist(T t)
            {
                if (t is string)
                {
                    return(t1.Contains(t));
                }

                return(GetResultList().Contains(new NewtonsoftJsonProvider().Serializer(t)));
            }

            List <string> GetResultList()
            {
                if (resultStrList.Count == 0 && resultList.Count != 0)
                {
                    t1.ForEach(item =>
                    {
                        resultStrList.Add(new NewtonsoftJsonProvider().Serializer(item));
                    });
                }

                return(resultStrList);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 查重添加
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="t1">集合1</param>
        /// <param name="t2">集合2</param>
        /// <returns></returns>
        private static List <T> MinusExcept <T>(this List <T> t1, List <T> t2) where T : class, new()
        {
            IJsonProvider jsonProvider = new NewtonsoftJsonProvider();

            List <T>      resultList    = new CloneableClass().DeepClone(t1);
            List <string> resultStrList = new List <string>();

            if (resultStrList.Count == 0 && resultList.Count != 0)
            {
                t1.ForEach(item => { resultStrList.Add(jsonProvider.Serializer(item)); });
            }

            foreach (var item in t2)
            {
                var str = jsonProvider.Serializer(item);
                if (resultStrList.Contains(str))
                {
                    resultStrList.Remove(str);
                }
            }

            return(resultStrList.Select(x => jsonProvider.Deserialize <T>(x)).ToList());
        }