コード例 #1
0
 public IDisposable Subscribe(IObserver <int> observer)
 {
     observer.OnNext(1);
     observer.OnNext(2);
     observer.OnNext(3);
     observer.OnNext(4);
     observer.OnNext(5);
     return(GenericDisposable.Create(() => {}));
 }
コード例 #2
0
        protected virtual void StartRecording(RenderRenderingArgs args)
        {
            var writer = MinificationHelpers.ShouldMinify() ? new OptimizedRecordingTextWriter(args.Writer) : new RecordingTextWriter(args.Writer);
            var item   = new GenericDisposable(delegate
            {
                writer.Flush();
            });

            args.Disposables.Add(item);
            args.Writer = writer;
        }
コード例 #3
0
        public void TestGenericDisposable()
        {
            var value = 0;

            using (var dispose = GenericDisposable.Create(() => value++))
            {
                Assert.AreEqual(0, value);
            }

            Assert.AreEqual(1, value);
        }
コード例 #4
0
        public void Disposables_will_be_disposed_on_dispose()
        {
            var disposable1 = new GenericDisposable();
            var disposable2 = new GenericDisposable();

            try
            {
                using (var tx1 = CreateDefaultScope())
                {
                    tx1.AddDisposable(disposable1);
                    tx1.AddDisposable(disposable2);
                }
                Assert.True(disposable1.Disposed);
                Assert.True(disposable2.Disposed);
            }
            finally
            {
                disposable1?.Dispose();
                disposable2?.Dispose();
            }
        }
コード例 #5
0
 public IDisposable TraceMethod(string message = null, [CallerMemberName] string method = "")
 {
     this.logger.LogDebug(method);
     return(GenericDisposable.Create(() => { this.logger.LogDebug(method); }));
 }
コード例 #6
0
 public IDisposable Subscribe(IObserver <int> observer)
 {
     _observers.Add(observer);
     return(GenericDisposable.Create(() => _observers.Remove(observer)));
 }