PlatformEnlightenmentProvider.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. using System.ComponentModel;
  5. using System.Reflection;
  6. namespace System.Reactive.PlatformServices
  7. {
  8. /// <summary>
  9. /// (Infrastructure) Interface for enlightenment providers.
  10. /// </summary>
  11. /// <remarks>
  12. /// This type is used by the Rx infrastructure and not meant for public consumption or implementation.
  13. /// No guarantees are made about forward compatibility of the type's functionality and its usage.
  14. /// </remarks>
  15. [EditorBrowsable(EditorBrowsableState.Never)]
  16. public interface IPlatformEnlightenmentProvider
  17. {
  18. /// <summary>
  19. /// (Infastructure) Tries to gets the specified service.
  20. /// </summary>
  21. /// <typeparam name="T">Service type.</typeparam>
  22. /// <param name="args">Optional set of arguments.</param>
  23. /// <returns>Service instance or null if not found.</returns>
  24. T GetService<T>(params object[] args) where T : class;
  25. }
  26. /// <summary>
  27. /// (Infrastructure) Provider for platform-specific framework enlightenments.
  28. /// </summary>
  29. /// <remarks>
  30. /// This type is used by the Rx infrastructure and not meant for public consumption or implementation.
  31. /// </remarks>
  32. [EditorBrowsable(EditorBrowsableState.Never)]
  33. public static class PlatformEnlightenmentProvider
  34. {
  35. private static IPlatformEnlightenmentProvider s_current = CreatePlatformProvider();
  36. /// <summary>
  37. /// (Infrastructure) Gets the current enlightenment provider. If none is loaded yet, accessing this property triggers provider resolution.
  38. /// </summary>
  39. /// <remarks>
  40. /// This member is used by the Rx infrastructure and not meant for public consumption or implementation.
  41. /// </remarks>
  42. [Obsolete("This mechanism will be removed in the next major version", false)]
  43. public static IPlatformEnlightenmentProvider Current
  44. {
  45. get
  46. {
  47. return s_current;
  48. }
  49. set
  50. {
  51. if (value == null) throw new ArgumentNullException(nameof(value));
  52. s_current = value;
  53. }
  54. }
  55. private static IPlatformEnlightenmentProvider CreatePlatformProvider()
  56. {
  57. return new CurrentPlatformEnlightenmentProvider();
  58. }
  59. }
  60. }