SubjectBase.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System.Reactive.Subjects
  5. {
  6. /// <summary>
  7. /// Base class for objects that are both an observable sequence as well as an observer.
  8. /// </summary>
  9. /// <typeparam name="T">The type of the elements processed by the subject.</typeparam>
  10. public abstract class SubjectBase<T> : ISubject<T>, IDisposable
  11. {
  12. /// <summary>
  13. /// Indicates whether the subject has observers subscribed to it.
  14. /// </summary>
  15. public abstract bool HasObservers { get; }
  16. /// <summary>
  17. /// Indicates whether the subject has been disposed.
  18. /// </summary>
  19. public abstract bool IsDisposed { get; }
  20. /// <summary>
  21. /// Releases all resources used by the current instance of the subject and unsubscribes all observers.
  22. /// </summary>
  23. public abstract void Dispose();
  24. /// <summary>
  25. /// Notifies all subscribed observers about the end of the sequence.
  26. /// </summary>
  27. public abstract void OnCompleted();
  28. /// <summary>
  29. /// Notifies all subscribed observers about the specified exception.
  30. /// </summary>
  31. /// <param name="error">The exception to send to all currently subscribed observers.</param>
  32. /// <exception cref="ArgumentNullException"><paramref name="error"/> is <c>null</c>.</exception>
  33. public abstract void OnError(Exception error);
  34. /// <summary>
  35. /// Notifies all subscribed observers about the arrival of the specified element in the sequence.
  36. /// </summary>
  37. /// <param name="value">The value to send to all currently subscribed observers.</param>
  38. public abstract void OnNext(T value);
  39. /// <summary>
  40. /// Subscribes an observer to the subject.
  41. /// </summary>
  42. /// <param name="observer">Observer to subscribe to the subject.</param>
  43. /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
  44. /// <exception cref="ArgumentNullException"><paramref name="observer"/> is <c>null</c>.</exception>
  45. public abstract IDisposable Subscribe(IObserver<T> observer);
  46. }
  47. }