Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Internal/Helpers.cs

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