コード例 #1
0
 public void DisposableActionCalledOnDispose()
 {
     bool disposableCalled = false;
     using (DisposableAction action = new DisposableAction(delegate { disposableCalled = true; }))
     {}
     Assert.IsTrue(disposableCalled);
 }
コード例 #2
0
		public void Dispose_ActionIsCalled()
		{
			var count = 0;
			Action action = () => ++count;
			var disposable = new DisposableAction(action);

			disposable.Dispose();
			Assert.AreEqual(1, count);
		}
コード例 #3
0
        public void DisposableActionGetsCorrectParameterFromCtor()
        {
            int expected = 4543;
            int actual = 0;
            DisposableAction<int> action = new DisposableAction<int>(delegate(int i)
            {
                actual = i;
            }, expected);
            action.Dispose();

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
ファイル: LogTimedExtensions.cs プロジェクト: elanwu123/dnx
 public static IDisposable LogTimed(this ILogger self, string activity)
 {
     if (self.IsEnabled(LogLevel.Debug))
     {
         self.LogDebug("Started " + activity);
         Stopwatch sw = new Stopwatch();
         var ret = new DisposableAction(() =>
         {
             sw.Stop();
             self.LogDebug($"Finished {activity} in {sw.ElapsedMilliseconds:0.00}ms");
         });
         sw.Start();
         return ret;
     }
     else
     {
         return DisposableAction.Null;
     }
 }