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); }
static void Main5() { MyLazy<Big> myLazy = new MyLazy<Big>(() => BigFactory.Build()); Console.WriteLine(myLazy.Value.ID); Console.WriteLine(myLazy.Value.ID); }
public void Test() { personRepostitoy.Insert(new Person() { }); personRepostitoy.GetPerson("111"); MyLazy <Large> aaa = new MyLazy <Large>(); Large a = aaa.Value; }