alexmen

专注.net软件开发,项目管理体系PMBOK.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
/// <summary>
        /// 泛型LIst<T>转泛型list<V>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="inList"></param>
        /// <returns></returns>
        public static List<T> ListToList<T, V>( List<V> inList)
            where T : class
            where V : class
        {
            if (inList.Count > 0)
            {
                var resultList = new List<T>(inList.Count);
                inList.ForEach((inmodel) =>
                {
                    T result = Activator.CreateInstance<T>();
                    var propList = typeof (T).GetProperties().ToList();
                    foreach (var p in propList)
                    {
                        var properties = typeof (V).GetProperties().ToList();
                        properties.ForEach(pv =>
                        {
                            if (p.Name == pv.Name)
                            {
                                p.SetValue(result, pv.GetValue(inmodel, null), null);
                            }

                        });
                    }
                    resultList.Add(result);
                });

                return resultList;
            }
            return default (List<T>);
        }

 

posted on 2016-08-02 22:57  alexmen  阅读(444)  评论(0编辑  收藏  举报