Observable.Queryable.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #pragma warning disable 1591
  5. namespace System.Reactive.Linq
  6. {
  7. public static partial class Qbservable
  8. {
  9. #pragma warning disable IDE1006 // Naming Styles: 3rd party code is known to reflect for this specific field name
  10. private static IQbservableProvider s_provider;
  11. #pragma warning restore IDE1006 // Naming Styles
  12. /// <summary>
  13. /// Gets the local query provider which will retarget Qbservable-based queries to the corresponding Observable-based query for in-memory execution upon subscription.
  14. /// </summary>
  15. public static IQbservableProvider Provider
  16. {
  17. get
  18. {
  19. if (s_provider == null)
  20. {
  21. s_provider = new ObservableQueryProvider();
  22. }
  23. return s_provider;
  24. }
  25. }
  26. /// <summary>
  27. /// Converts an in-memory observable sequence into an <see cref="IQbservable{T}"/> sequence with an expression tree representing the source sequence.
  28. /// </summary>
  29. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  30. /// <param name="source">Source sequence.</param>
  31. /// <returns><see cref="IQbservable{T}"/> sequence representing the given observable source sequence.</returns>
  32. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  33. public static IQbservable<TSource> AsQbservable<TSource>(this IObservable<TSource> source)
  34. {
  35. if (source == null)
  36. {
  37. throw new ArgumentNullException(nameof(source));
  38. }
  39. return new ObservableQuery<TSource>(source);
  40. }
  41. }
  42. }
  43. #pragma warning restore 1591