예제 #1
0
 public void MyLazyTest()
 {
     //tests HasValue, ValueCreated and ValueDestroyed
     int expectedLazyVal = 1;
     var lazy=new MyLazy<int>(()=> { return 1; });
     bool createdEvent = true;
     bool destroyedEvent = true;
     lazy.ValueCreated += sender =>
     {
         createdEvent = true;
         Assert.IsTrue(ReferenceEquals(sender, lazy));
     };
     lazy.ValueDestroyed += (sender, old) =>
     {
         destroyedEvent = true;
         Assert.IsTrue(ReferenceEquals(sender,lazy));
         Assert.IsTrue(old==expectedLazyVal);
     };
     Assert.IsFalse(lazy.HasValue);
     Assert.IsTrue(lazy.Value== expectedLazyVal);
     Assert.IsTrue(createdEvent);
     createdEvent = false;
     Assert.IsTrue(lazy.HasValue);
     int newVal = 2;
     lazy.ValueFactory = () => { return newVal; };
     Assert.IsTrue(destroyedEvent);
     Assert.IsTrue(lazy.Value== newVal);
     Assert.IsTrue(createdEvent);
 }
예제 #2
0
파일: Program.cs 프로젝트: anytao/insidenet
        static void Main5()
        {
            MyLazy<Big> myLazy = new MyLazy<Big>(() => BigFactory.Build());

            Console.WriteLine(myLazy.Value.ID);

            Console.WriteLine(myLazy.Value.ID);
        }
예제 #3
0
        public void Test()
        {
            personRepostitoy.Insert(new Person()
            {
            });

            personRepostitoy.GetPerson("111");

            MyLazy <Large> aaa = new MyLazy <Large>();

            Large a = aaa.Value;
        }