示例#1
0
        public void Dispose_Initialized_Disposed()
        {
            var foo = new Foo();

            using (Disposable <Foo> .CreateInitialized(() => foo, f => f.Bar = "baz"))
            {
            }
            Assert.AreEqual("baz", foo.Bar);
        }
示例#2
0
 public IDisposable Apply()
 {
     return(Disposable <ConsoleStyle> .CreateInitialized(() =>
     {
         var restoreStyle = Current;
         Console.ForegroundColor = ForegroundColor;
         Console.BackgroundColor = BackgroundColor;
         return restoreStyle;
     }, restoreStyle =>
     {
         Console.ForegroundColor = restoreStyle.ForegroundColor;
         Console.BackgroundColor = restoreStyle.BackgroundColor;
     }));
 }