Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
Exemplo n.º 4
0
 /// <summary>
 /// 将对象TSource的值赋给给TDest
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 public static void MapTo <TSource, TDest>(this TSource source, TDest target) where TSource : class where TDest : class => ExpressionGenericMapper <TSource, TDest> .Map(source, target);
Exemplo n.º 5
0
 /// <summary>
 /// 集合元素映射
 /// </summary>
 /// <param name="sources"></param>
 /// <returns></returns>
 public static List <TDest> MapList <TSource, TDest>(this IEnumerable <TSource> sources) where TDest : class where TSource : class => ExpressionGenericMapper <TSource, TDest> .MapList(sources);
Exemplo n.º 6
0
 /// <summary>
 /// 将对象TSource转换为TDest
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static TDest Map <TSource, TDest>(this TSource source) where TDest : class where TSource : class => ExpressionGenericMapper <TSource, TDest> .Map(source);