示例#1
0
        /// <summary>
        /// 拷贝数组
        /// </summary>
        /// <typeparam name="TElement">源数组元素类型</typeparam>
        /// <param name="source">源List</param>
        /// <returns>深拷贝完成的数组</returns>
        public static TElement[] CopyArray <TElement>(TElement[] source) where TElement : class
        {
            TElement[] result = new TElement[source.Length];
            if (MapperTools.IsRefTypeExceptString(typeof(TElement)))
            {
                for (int i = 0; i < source.Length; i++)
                {
                    result[i] = ExpressionGenericMapper <TElement, TElement> .Copy(source[i]);
                }
            }
            else
            {
                for (int i = 0; i < source.Length; i++)
                {
                    result[i] = source[i];
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// 拷贝List
        /// </summary>
        /// <typeparam name="T">源ICollection实现类类型</typeparam>
        /// <typeparam name="TElement">源ICollection元素类型</typeparam>
        /// <param name="source">源ICollection对象</param>
        /// <returns>深拷贝完成的ICollection对象</returns>
        public static T CopyICollection <T, TElement>(T source) where T : ICollection <TElement> where TElement : class
        {
            T result = (T)MapperTools.CreateNewInstance(source.GetType());

            if (MapperTools.IsRefTypeExceptString(typeof(TElement)))
            {
                foreach (TElement item in source)
                {
                    result.Add(ExpressionGenericMapper <TElement, TElement> .Copy(item));
                }
            }
            else
            {
                foreach (TElement item in source)
                {
                    result.Add(item);
                }
            }

            return(result);
        }
示例#3
0
 /// <summary>
 /// 复制一个新对象
 /// </summary>
 /// <typeparam name="TSource"></typeparam>
 /// <param name="source"></param>
 /// <returns></returns>
 public static TSource Copy <TSource>(this TSource source) where TSource : class => ExpressionGenericMapper <TSource, TSource> .Copy(source);