コード例 #1
0
        public static IObservable <T> AsObservable <T>(this INotifyDisposable disposable, Func <T> lastValue = null)
        {
            return(Observable.Create <T>(observer =>
            {
                if (disposable.IsDisposed)
                {
                    if (lastValue != null)
                    {
                        observer.OnNext(lastValue());
                    }
                    observer.OnCompleted();
                    return Disposables.Empty;
                }

                var handler = Disposables.Call(() =>
                {
                    if (lastValue != null)
                    {
                        observer.OnNext(lastValue());
                    }
                    observer.OnCompleted();
                });

                disposable.Attach(handler, keepAlive: true);

                return Disposables.Call(() =>
                {
                    disposable.Dettach(handler);
                });
            }));
        }
コード例 #2
0
        public static INotifyDisposable WhenDisposed(this INotifyDisposable source, Action action)
        {
            var call = Disposables.Call(action);

            source.Attach(call, keepAlive: true);

            return(source);
        }
コード例 #3
0
        public static T DisposedBy <T>(this T child, INotifyDisposable disposer)
            where T : IDisposable
        {
            if (child is Task)
            {
                throw new ArgumentException("Can not register Task for late disposal", nameof(child));
            }

            disposer.Attach(child);

            return(child);
        }
コード例 #4
0
ファイル: BaseDisposable.cs プロジェクト: kobi2294/MvvmKit
 public void Attach(IDisposable child, bool keepAlive = false) => _handler.Attach(child, keepAlive);