DisableOptimizationsScheduler.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.Linq;
  5. using System.Runtime.CompilerServices;
  6. namespace System.Reactive.Concurrency
  7. {
  8. internal sealed class DisableOptimizationsScheduler : SchedulerWrapper
  9. {
  10. private readonly Type[] _optimizationInterfaces;
  11. public DisableOptimizationsScheduler(IScheduler scheduler)
  12. : base(scheduler)
  13. {
  14. _optimizationInterfaces = Scheduler.OPTIMIZATIONS;
  15. }
  16. public DisableOptimizationsScheduler(IScheduler scheduler, Type[] optimizationInterfaces)
  17. : base(scheduler)
  18. {
  19. _optimizationInterfaces = optimizationInterfaces;
  20. }
  21. public DisableOptimizationsScheduler(IScheduler scheduler, Type[] optimizationInterfaces, ConditionalWeakTable<IScheduler, IScheduler> cache)
  22. : base(scheduler, cache)
  23. {
  24. _optimizationInterfaces = optimizationInterfaces;
  25. }
  26. protected override SchedulerWrapper Clone(IScheduler scheduler, ConditionalWeakTable<IScheduler, IScheduler> cache)
  27. {
  28. return new DisableOptimizationsScheduler(scheduler, _optimizationInterfaces, cache);
  29. }
  30. protected override bool TryGetService(IServiceProvider provider, Type serviceType, out object service)
  31. {
  32. service = null;
  33. return _optimizationInterfaces.Contains(serviceType);
  34. }
  35. }
  36. }