Helpers.cs 1.1 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.Collections.Generic;
  5. namespace System.Reactive
  6. {
  7. internal static class Helpers
  8. {
  9. public static int? GetLength<T>(IEnumerable<T> source)
  10. {
  11. var array = source as T[];
  12. if (array != null)
  13. return array.Length;
  14. var list = source as IList<T>;
  15. if (list != null)
  16. return list.Count;
  17. return null;
  18. }
  19. public static IObservable<T> Unpack<T>(IObservable<T> source)
  20. {
  21. var hasOpt = default(bool);
  22. do
  23. {
  24. hasOpt = false;
  25. var eval = source as IEvaluatableObservable<T>;
  26. if (eval != null)
  27. {
  28. source = eval.Eval();
  29. hasOpt = true;
  30. }
  31. } while (hasOpt);
  32. return source;
  33. }
  34. }
  35. }