Beispiel #1
0
        /// <summary>
        /// 匹配映射比较
        /// 2个实体类做映射,将一个实体类的数据复制到另一个实体类上
        /// 在领域模型中BO与DTO的映射
        /// 可以使用:
        /// 1.硬编码
        /// 2.泛型+反射
        /// 3.泛型+表达式树
        /// </summary>
        public static void MapperCompare()
        {
            People p = new People()
            {
                Id     = 1001,
                Number = 10,
                Name   = "VesNing",
                Age    = 28
            };
            var result1 = HardCodingMapper.Mapper(p);

            result1.ToString();

            var result2 = ReflectionMapper.Mapper <People, PeopleCopy>(p);

            result2.ToString();

            var result3 = SerializeMapper.Mapper(p);

            result3.ToString();

            var result4 = ExpressionMapper.Mapper <People, PeopleCopy>(p);

            StopWatchRun((m) => { HardCodingMapper.Mapper(m); }, p, "硬编码");
            StopWatchRun((m) => { ReflectionMapper.Mapper <People, PeopleCopy>(m); }, p, "泛型+反射");
            StopWatchRun((m) => { SerializeMapper.Mapper(m); }, p, "NewtoneSoft序列化");
            StopWatchRun((m) => { ExpressionMapper.Mapper <People, PeopleCopy>(m); }, p, "表达式树+字典缓存");
        }