public void Dispose_Initialized_Disposed() { var foo = new Foo(); using (Disposable <Foo> .CreateInitialized(() => foo, f => f.Bar = "baz")) { } Assert.AreEqual("baz", foo.Bar); }
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; })); }