Helpers.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if !NO_PERF
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Reactive.Linq.ObservableImpl;
  6. namespace System.Reactive
  7. {
  8. internal static class Helpers
  9. {
  10. public static int? GetLength<T>(IEnumerable<T> source)
  11. {
  12. var array = source as T[];
  13. if (array != null)
  14. return array.Length;
  15. var list = source as IList<T>;
  16. if (list != null)
  17. return list.Count;
  18. return null;
  19. }
  20. public static IObservable<T> Unpack<T>(IObservable<T> source)
  21. {
  22. var hasOpt = default(bool);
  23. do
  24. {
  25. hasOpt = false;
  26. var eval = source as IEvaluatableObservable<T>;
  27. if (eval != null)
  28. {
  29. source = eval.Eval();
  30. hasOpt = true;
  31. }
  32. } while (hasOpt);
  33. return source;
  34. }
  35. }
  36. }
  37. #endif