示例#1
0
        private static void Test(IContainer container, ConvertType ctype, int times)
        {
            IConvert convert = default(IConvert);

            if (ctype == ConvertType.AutoMapper)
            {
                convert = container.ResolveKeyed <IConvert>(ctype);
            }
            else if (ctype == ConvertType.EmitMapper)
            {
                convert = new EmitConverter();
            }
            else if (ctype == ConvertType.TinyMapper)
            {
                convert = new TinyConverter();
            }
            if (times < 1)
            {
                Test(convert, ctype);
                return;
            }
            Random r   = new Random();
            A2     obj = new A2 {
                Id = r.Next(1, 1000), Name = "A1"
            };
            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < times; i++)
            {
                A1 obj2 = convert.Convert <A2, A1>(obj);
            }
            sw.Stop();
            Log.Information($"{ctype}执行了{times}次,耗时{sw.ElapsedMilliseconds}毫秒");
        }
示例#2
0
        private static void Test(IConvert convert, ConvertType ctype)
        {
            A2 obj = new A2 {
                Id = 1, Name = "A1"
            };
            A1 obj2 = convert.Convert <A2, A1>(obj);

            Show(obj, obj2, ctype);
        }
示例#3
0
 private static void Show(A2 a2, A1 a1, ConvertType ctype)
 {
     if (a1 == null)
     {
         Log.Warning($"{ctype}转换失败");
     }
     else
     {
         Log.Debug($"a1==a2:{a2.Name==a1.Name}");
     }
 }