匿名对象解析

  class Program
    {
        static void Main(string[] args)
        {
            List<object> obj = new List<object>();
            obj.Add(new { aa=1,bb=1});
            obj.Add(new { aa = 1, bb = 2 });

            var objs = obj.Select(t => t.Cast(new { aa = 0, bb = 0 })).ToList();
            Console.ReadKey();
        }

       
    }
    static class Extensions
    {
        public static T Cast<T>(this object obj, T sample)
        {
            return (T)obj;
        }
    }

  

posted @ 2018-05-16 14:31 凉生凉忆亦凉心 阅读(...) 评论(...) 编辑 收藏