SubjectBase.cs 2.2 KB

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