Пример #1
0
 void TestUsing()
 {
     using (var myDisposable = new MyDisposable())
     {
         myDisposable.Dispose();
         myDisposable.close();
     }
     Console.WriteLine();
 }
Пример #2
0
        public void Using3()
        {
            var d = default(MyDisposable);

            var xs = EnumerableEx.Using<int, MyDisposable>(() => d = new MyDisposable(), d_ => { throw new MyException(); });
            Assert.IsNull(d);

            AssertThrows<MyException>(() => xs.ForEach(_ => { }));
            Assert.IsTrue(d.Done);
        }
Пример #3
0
        public void Using2()
        {
            var d = default(MyDisposable);

            var xs = EnumerableEx.Using(() => d = new MyDisposable(), d_ => EnumerableEx.Throw <int>(new MyException()));

            Assert.Null(d);

            AssertThrows <MyException>(() => xs.ForEach(_ => { }));
            Assert.True(d.Done);
        }
Пример #4
0
        public void Using1()
        {
            var d = default(MyDisposable);

            var xs = EnumerableEx.Using(() => d = new MyDisposable(), d_ => new[] { 1 });
            Assert.IsNull(d);

            var d1 = default(MyDisposable);
            xs.ForEach(_ => { d1 = d; Assert.IsNotNull(d1); Assert.IsFalse(d1.Done); });
            Assert.IsTrue(d1.Done);

            var d2 = default(MyDisposable);
            xs.ForEach(_ => { d2 = d; Assert.IsNotNull(d2); Assert.IsFalse(d2.Done); });
            Assert.IsTrue(d2.Done);

            Assert.AreNotSame(d1, d2);
        }