Exemple #1
0
        private static long HandWtittenSimple(int mappingsCount)
        {
            var s = new B2();
            var d = new A2();

            return Benchmark(mappingsCount, () => d = Map(s, d));
        }
Exemple #2
0
        private static long OoMapperSimple(int mappingsCount)
        {
            var s = new B2();
            var d = new A2();

            return Benchmark(mappingsCount, () => d = Mapper.Map(s, d));
        }
 public void Test2()
 {
     A2 a = new A2();
     B2 b = new B2();
     Context.objMan.GetMapper<B2, A2>().Map(b, a);
     //DynamicAssemblyManager.SaveAssembly();
     Assert.AreEqual("99", a.fld3[0]);
 }
		static long EmitMapper_Custom(int mappingsCount)
		{
			var s = new B2();
			var d = new A2();

			var sw = new Stopwatch();
			sw.Start();
			for (int i = 0; i < mappingsCount; ++i)
			{
				d = emitMapper.Map(s, d);
			}
			sw.Stop();
			return sw.ElapsedMilliseconds;
		}
		static long BenchBLToolkit_Simple(int mappingsCount)
		{
			var s = new B2();
			var d = new A2();

			d = BLToolkit.Mapping.Map.ObjectToObject<A2>(s);

			var sw = new Stopwatch();
			sw.Start();
			for (int i = 0; i < mappingsCount; ++i)
			{
				d = BLToolkit.Mapping.Map.ObjectToObject<A2>(s);
			}
			sw.Stop();
			return sw.ElapsedMilliseconds;
		}
		static A2 HandwrittenMap(B2 s, A2 result)
		{
			result.str1 = s.str1;
			result.str2 = s.str2;
			result.str3 = s.str3;
			result.str4 = s.str4;
			result.str5 = s.str5;
			result.str6 = s.str6;
			result.str7 = s.str7;
			result.str8 = s.str8;
			result.str9 = s.str9;

			result.n1 = s.n1;
			result.n2 = (int)s.n2;
			result.n3 = s.n3;
			result.n4 = s.n4;
			result.n5 = (int)s.n5;
			result.n6 = (int)s.n6;
			result.n7 = s.n7;
			result.n8 = s.n8;

			return result;
		}
		static long AutoMapper_Simple(int mappingsCount)
		{
			var s = new B2();
			var d = new A2();

			var sw = new Stopwatch();
			sw.Start();
			for (int i = 0; i < mappingsCount; ++i)
			{
				d = AutoMapper.Mapper.Map<B2, A2>(s, d);
			}
			sw.Stop();
			return sw.ElapsedMilliseconds;
		}
 public TwoCtors(A1 a1, A2 a2)
 {
     CalledCtor = new[] { typeof(A1), typeof(A2) };
 }
        static long EmitMapper_Simple(int mappingsCount)
        {
            var mapper = ObjectMapperManager.DefaultInstance.GetMapper<B2, A2>();
            var s = new B2();
            var d = new A2();

            var sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < mappingsCount; ++i)
            {
                mapper.Map(s, d);
            }
            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
        private IList<IValidationItemResult> Check3007(A2 a2)
        {
            if ( (a2.MJSpecified && a2.MJ == MJType.ks && !string.IsNullOrEmpty(a2.TK)) ||
                 (a2.MJSpecified && a2.MJ != MJType.ks && a2.TDSpecified))
                return new ValidationItemResult[] { Validation3007Failed(a2) };

            return new ValidationItemResult[0];
        }
        private IList<IValidationItemResult> Check3002(A2 a2)
        {
            if (a2.MJSpecified || a2.MnSpecified)
                if (string.IsNullOrEmpty(a2.TK) && !a2.TDSpecified)
                    return new ValidationItemResult[] { Validation3002Failed(a2) };

            return new ValidationItemResult[0];
        }
Exemple #12
0
		public APropCtor(A2 a)
		{
			this.a = a;
		}
        private IList<IValidationItemResult> Check3005(A2 a2)
        {
            if (a2.MJSpecified && a2.MJ == MJType.ks && a2.MnSpecified && !isInt32(a2.Mn))
                return new ValidationItemResult[] { Validation3005Failed(a2) };

            return new ValidationItemResult[0];
        }
Exemple #14
0
        public void T4_CountMismatchResetBatch_WriteMany()
        {
            using (var ms = new MemoryStream())
            {
              var s1 = new SlimSerializer();
              s1.TypeMode= TypeRegistryMode.Batch;
              var o1a = new A1{ I1 = 12};
              var o1b = new A2{ I2 = 13};
              var o1c = new A1{ I1 = 14};
              var o1d = new A1{ I1 = 15};
              var o1e = new A1{ I1 = 16};

              s1.Serialize(ms, o1a);  Assert.IsTrue( s1.BatchTypesAdded );
              s1.Serialize(ms, o1b);  Assert.IsTrue( s1.BatchTypesAdded );
              s1.Serialize(ms, o1c);  Assert.IsFalse( s1.BatchTypesAdded );
              s1.Serialize(ms, o1d);  Assert.IsFalse( s1.BatchTypesAdded );
              s1.Serialize(ms, o1e);  Assert.IsFalse( s1.BatchTypesAdded );
              ms.Seek(0, SeekOrigin.Begin);

              var buf = ms.GetBuffer();
              Console.WriteLine( buf.ToDumpString(DumpFormat.Printable, 0,(int) ms.Length) );

              var s2 = new SlimSerializer();
              s2.TypeMode= TypeRegistryMode.Batch;
              var o2a = (A1)s2.Deserialize(ms); Assert.IsTrue( s2.BatchTypesAdded );
              Assert.AreEqual(12, o2a.I1);

              s2.ResetCallBatch();
              var o2b = (A2)s2.Deserialize(ms); //Exception
            }
        }
        public void Test_WPFBrowserNavigator_Navition_Resolve_OnBaseType_2()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                =>
            {
                wpfnav.Should().NotBeNull();
                wpfbuild.Register<A>("javascript\\navigation_1.html");
                wpfbuild.Register<A1>("javascript\\navigation_2.html", "Special");

                wpfnav.UseINavigable = true;
                var a1 = new A2();
                var mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
               () =>
               {
                   wpfnav.NavigateAsync(a1).ContinueWith(t => mre.Set());
               });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    a1.Navigation.Should().NotBeNull();
                    wpfnav.Source.Should().EndWith(@"javascript\navigation_1.html");
                });

            });
        }
        public void Test_WPFBrowserNavigator_Navition_Debug_One()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                =>
            {
                WindowTest.RunOnUIThread(() =>
                {
                    wpfnav.IsDebug.Should().BeTrue();
                    Action safe = ()=>
                    wpfnav.ShowDebugWindow();
                    safe.ShouldNotThrow<Exception>();
                });

               

                wpfnav.Should().NotBeNull();
                wpfbuild.Register<A>("javascript\\navigation_1.html");
                wpfbuild.Register<A1>("javascript\\navigation_2.html", "Special");

                wpfnav.UseINavigable = true;
                wpfnav.UseINavigable.Should().BeTrue();

                wpfnav.EnableBrowserDebug = true;
                wpfnav.EnableBrowserDebug.Should().BeTrue();

                wpfnav.OnNavigate += wpfnav_OnNavigate;
                wpfnav.OnNavigate -= wpfnav_OnNavigate;

             

                var a1 = new A2();
                var mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
               () =>
               {
                   wpfnav.NavigateAsync(a1).ContinueWith(t => mre.Set());
               });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    a1.Navigation.Should().NotBeNull();
                    wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html");
                    wpfnav.ShowDebugWindow();
                    wpfnav.OpenDebugBrowser();     
                });


                WindowTest.RunOnUIThread(() =>
                {
                    wpfnav.Focus();

                    wpfnav.RaiseEvent(
                      new System.Windows.Input.KeyEventArgs(
                        Keyboard.PrimaryDevice,
                        PresentationSource.FromVisual(wpfnav),
                        0,
                        Key.F5) { RoutedEvent = Keyboard.PreviewKeyDownEvent }
                    );
                });
            },true);
        }
        public void Test_WPFBrowserNavigator_Navition_Simple()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                =>
            {
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                wpfnav.UseINavigable = true;
                var a1 = new A1();
                var a2 = new A2();
                var mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
               () =>
               {
                   wpfnav.NavigateAsync(a1).ContinueWith(t => mre.Set());
               });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });

                WindowTest.RunOnUIThread(
                () =>
                wpfnav.Source.Should().EndWith(@"javascript\navigation_1.html"));

                mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
              () =>
              {
                  wpfnav.NavigateAsync(a2).ContinueWith(t => mre.Set());
              });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a2.Navigation.Should().NotBeNull();
                    a1.Navigation.Should().BeNull();
                });

                WindowTest.RunOnUIThread(() =>
                     wpfnav.Source.Should().EndWith(@"javascript\navigation_2.html"));

            });
        }
        public void Test_WPFBrowserNavigator_Navition_Resolve_NotFound()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                =>
            {
                wpfnav.Should().NotBeNull();

                wpfnav.UseINavigable = true;
                var a1 = new A2();

                WindowTest.RunOnUIThread(
               () =>
               {
                   Action wf = () => wpfnav.NavigateAsync(a1);
                   wf.ShouldThrow<Exception>();
               });

            });
        }
Exemple #19
0
 public A1()
 {
     A2 = new A2();
 }
 public void Int3()
 {
     A2 a1 = new A2();
     Assert.AreEqual(0,Conversion.Int(a1));
 }
		static long HandWtitten_Simple(int mappingsCount)
		{
			var s = new B2();
			var d = new A2();

			var sw = new Stopwatch();
			sw.Start();
			for (int i = 0; i < mappingsCount; ++i)
			{
				d = HandwrittenMap(s, d);
			}
			sw.Stop();
			return sw.ElapsedMilliseconds;
		}
        private IList<IValidationItemResult> Check3003(A2 a2)
        {
            if (!string.IsNullOrEmpty(a2.TK) && a2.TDSpecified)
                return new ValidationItemResult[] { Validation3003Failed(a2) };

            return new ValidationItemResult[0];
        }
        public void Test_WPFBrowserNavigator_Navition_3_screens()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                =>
            {
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                wpfbuild.Register<A1>("javascript\\navigation_3.html", "NewPath");
                wpfnav.UseINavigable = true;
                var a1 = new A1();
                var a2 = new A2();
                var mre = new ManualResetEvent(false);


                WindowTest.RunOnUIThread(
               () =>
               {
                   wpfnav.NavigateAsync(a1).ContinueWith(t => mre.Set());
               });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });

                WindowTest.RunOnUIThread(
                () =>
                wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html"));

                mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
               () =>
               {
                   wpfnav.NavigateAsync(a2).ContinueWith(t => mre.Set());
               });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    a2.Navigation.Should().NotBeNull();
                    a1.Navigation.Should().BeNull();
                });

                WindowTest.RunOnUIThread(() =>
                     wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_2.html"));


                WindowTest.RunOnUIThread(
            () =>
            {
                wpfnav.NavigateAsync(a1, "NewPath").ContinueWith
           (
               t =>
               {
                   //a1.Navigation.Should().Be(wpfnav);
                   a1.Navigation.Should().NotBeNull();
                   a2.Navigation.Should().BeNull();
                   mre.Set();
               });
            });
                mre.WaitOne();

                Thread.Sleep(2000);


                WindowTest.RunOnUIThread(() =>
                     wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_3.html"));

            });
        }
Exemple #24
0
        public void T5_Batch_WriteReadMany()
        {
            using (var ms = new MemoryStream())
            {
              var s1 = new SlimSerializer();
              s1.TypeMode= TypeRegistryMode.Batch;
              var s2 = new SlimSerializer();
              s2.TypeMode= TypeRegistryMode.Batch;

              var o1a = new A1{ I1 = 12};
              var o1b = new A2{ I2 = 13};
              var o1c = new A1{ I1 = 14};
              var o1d = new A1{ I1 = 15};
              var o1e = new A1{ I1 = 16};

              s1.Serialize(ms, o1a);  Assert.IsTrue( s1.BatchTypesAdded );
              ms.Position = 0;
              var o2a = (A1)s2.Deserialize(ms); Assert.IsTrue( s2.BatchTypesAdded );

              ms.Position = 0;
              s1.Serialize(ms, o1b);  Assert.IsTrue( s1.BatchTypesAdded );
              ms.Position = 0;
              var o2b = (A2)s2.Deserialize(ms); Assert.IsTrue( s2.BatchTypesAdded );

              ms.Position = 0;
              s1.Serialize(ms, o1c);  Assert.IsFalse( s1.BatchTypesAdded );
              ms.Position = 0;
              var o2c = (A1)s2.Deserialize(ms); Assert.IsFalse( s2.BatchTypesAdded );

              ms.Position = 0;
              s1.Serialize(ms, o1d);  Assert.IsFalse( s1.BatchTypesAdded );
              ms.Position = 0;
              var o2d = (A1)s2.Deserialize(ms); Assert.IsFalse( s2.BatchTypesAdded );

              ms.Position = 0;
              s1.Serialize(ms, o1e);  Assert.IsFalse( s1.BatchTypesAdded );
              ms.Position = 0;
              var o2e = (A1)s2.Deserialize(ms); Assert.IsFalse( s2.BatchTypesAdded );

              Assert.AreEqual(12, o2a.I1);
              Assert.AreEqual(13, o2b.I2);
              Assert.AreEqual(14, o2c.I1);
              Assert.AreEqual(15, o2d.I1);
              Assert.AreEqual(16, o2e.I1);
            }
        }
        public void Test_WPFBrowserNavigator_Navition_Resolve_OnName_alernativesignature()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                =>
            {
                wpfnav.Should().NotBeNull();
                wpfbuild.RegisterAbsolute<A2>(string.Format("{0}\\{1}", Assembly.GetExecutingAssembly().GetPath(), "javascript\\navigation_1.html"), "Special1");
                wpfbuild.Register<A2>(new Uri(string.Format("{0}\\{1}", Assembly.GetExecutingAssembly().GetPath(), "javascript\\navigation_2.html")), "Special2");

                wpfnav.UseINavigable = true;
                var a1 = new A2();
                var mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
                () =>
                {
                    wpfnav.NavigateAsync(a1, "Special1").ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });

                WindowTest.RunOnUIThread(
                () =>
                wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html"));

                mre = new ManualResetEvent(false);
                WindowTest.RunOnUIThread(
                () =>
                {
                    wpfnav.NavigateAsync(a1, "Special2").ContinueWith(t => mre.Set());
                });

                mre.WaitOne();


                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });

                Thread.Sleep(1000);

                WindowTest.RunOnUIThread(
                () =>
                wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_2.html"));

            });
        }
        public void Test_WPFBrowserNavigator_Navition_Resolve_OnName()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                =>
            {
                wpfnav.Should().NotBeNull();
                wpfbuild.Register<A2>("javascript\\navigation_1.html", "Special1");
                wpfbuild.Register<A2>("javascript\\navigation_2.html", "Special2");

                wpfnav.UseINavigable = true;
                wpfnav.UseINavigable = true;
                var a1 = new A2();
                var mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
               () =>
               {
                   wpfnav.NavigateAsync(a1, "Special1").ContinueWith(t => mre.Set());
               });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });



                Thread.Sleep(1000);

                WindowTest.RunOnUIThread(
                () =>
                wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html"));


                mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
             () =>
             {
                 wpfnav.NavigateAsync(a1, "Special2").ContinueWith(t => mre.Set());
             });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });

                Thread.Sleep(1000);

                WindowTest.RunOnUIThread(
                () =>
                wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_2.html"));

            });
        }
 public void Test_StructToStruct()
 {
     A2 a = new A2();
     B2 b = new B2();
     b.fld1 = 99;
     a = Context.objMan.GetMapper<B2, A2>().Map(b, a);
     Assert.AreEqual(a.fld1, 99);
 }
Exemple #28
0
        static void Main(string[] args)
        {
            //A1就是類別名稱,Happy就是類別的方法
            //就像是我們裝好電腦之後,就可以做開機的動作,new就是裝好這台電腦
            A1 _PC = new A1();
            //然後我們就是做開機動作,
            string _Happy=_PC.Happy();

            //-----------------------------------------------

            A2 _PC2 = new A2("龍魂GE60"); //可以在裝好電腦時,為他取名,這樣大家才會知道是哪台,當然建構式可以多個

            string _strPC2 = _PC2.Happy();

            //A3 方法重載
            A2 _PC3 = new A2();
            string _strPC3 = _PC3.Happy("自爽");

            //--------------------------------------------------

            //A4 屬性與修飾子
            A4 _PC4 = new A4();
            _PC4.ReStartNum = 5;
            Console.WriteLine(_PC4.ReStart());

            //A5 封裝,剛才都是在使用封裝的
            //假設現在A5是NB,他也一樣會有ReStart
            A5 _NB = new A5();
            _NB.ReStartNum = 5;
            Console.WriteLine(_NB.ReStart());

            //A9 介面
            //抽象類別可以給初一些成員的實現,抽象類別的抽象成員可被子類別部分實現
            //介面的成員需要實現類別完全實現,一個類別只能繼承一個抽象類別,但可以實現多個介面等
            //第一類別是對物件的抽象;抽象類別是對類別的抽象;介面是對行為的抽象
            //第二如果行為跨越不同類別的物件,可使用介面;對於一些相似的類別物件,用繼承抽象類別
            //舉例 貓 狗都是動物,所以它們去繼承動物這抽象類別
            //但悟空和超人都會飛,但是悟空會變身,神話的悟空也會變身,所以此時可以用介面來完成
            //第三,抽象類別是從子類別中發現了公共的東西,泛化出父類別,然後子類別繼承父類別
            //,而介面是根本不知子類別的存在,方法如何實現還不確認,預先定義
            //例如在寫程式時候,是先寫了貓類別後,在寫出狗類別,最後發現有相同類似的,就泛化出動物類別,
            //不可能只有貓類別時候就想到動物類別
            //而介面是一同思考,定義一些項目,但不知道會有什麼動物,要如何實現,能做的就是是先定義這些比賽項目的行為介面
            //抽象類別是自底而上抽象類別的,而介面則是自頂而下設定的
            //(從狗貓衍伸出動物)(從項目延伸出不知那些動物會來參加預先定義好項目)

            A9_Interface _A9 = new A9_Interface("測試介面");

            IA9_Interface _A9_2 = new A9_Interface("測試介面2");
            Console.WriteLine(_A9.ChangeThing("第一個"));
            Console.WriteLine(_A9_2.ChangeThing("第二個"));

            //A10 泛型
            IList<Animal> arrayAnimal = new List<Animal>();
            arrayAnimal.Add(new Cat_Extend("tt"));
            arrayAnimal.Add(new Dog_Extend("tt2"));
            arrayAnimal.Add(new Cat_Extend("tt3"));
            Console.WriteLine(arrayAnimal.Count.ToString());

            //A11 泛型

            cat_deleget _cat = new cat_deleget("T");
            mouse_deleget _mo1 = new mouse_deleget("Ja");
            mouse_deleget _mo2 = new mouse_deleget("Jb");

            //表示將Mouse的Run方法透過實體化委託給CatShoutEventHandler登記到Cat的事件CatShout當中,+=是為了加進去add_CatShout的意思
            _cat.CatShout += new cat_deleget.CatShoutEventHandler(_mo1.Run);
            _cat.CatShout += new cat_deleget.CatShoutEventHandler(_mo2.Run);
            _cat.Shout();

            cat_deleget2 _cat2 = new cat_deleget2("T");
            mouse_deleget2 _mo21 = new mouse_deleget2("Ja");
            mouse_deleget2 _mo22 = new mouse_deleget2("Jb");
            _cat2.CatShout += new cat_deleget2.CatShoutEventHandler(_mo21.Run);
            _cat2.CatShout += new cat_deleget2.CatShoutEventHandler(_mo22.Run);
            _cat2.Shout();

            //A12-yieldreturn
            yieldreturn _yield = new yieldreturn();
            var _return = _yield.returnACD();
            string _strreturn = "";
            foreach (var item in _return)
            {
                _strreturn += item;
            }
            Console.WriteLine(_strreturn);

            Console.Read();
        }