1
0
Scott Blomquist 12 жил өмнө
parent
commit
7209d8f45a
100 өөрчлөгдсөн 3841 нэмэгдсэн , 298 устгасан
  1. 0 8
      .gitignore
  2. 0 0
      Ix/NET/.gitattributes
  3. 0 0
      Ix/NET/.gitignore
  4. 0 0
      Ix/NET/Common.targets
  5. 2696 0
      Ix/NET/Enumerable.cs
  6. 0 0
      Ix/NET/Import.targets
  7. 0 0
      Ix/NET/Interactive Extensions.sln
  8. 0 0
      Ix/NET/Interactive Extensions.vsmdi
  9. 0 0
      Ix/NET/Interactive Extensions.vssscc
  10. 0 0
      Ix/NET/Local.testsettings
  11. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerable.Aggregates.cs
  12. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerable.Conversions.cs
  13. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerable.Creation.cs
  14. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerable.Exceptions.cs
  15. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerable.Generated.cs
  16. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerable.Multiple.cs
  17. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerable.Single.cs
  18. 0 0
      Ix/NET/System.Interactive.Async/AsyncEnumerator.cs
  19. 0 0
      Ix/NET/System.Interactive.Async/Disposables.cs
  20. 0 0
      Ix/NET/System.Interactive.Async/EnumerableGrouping.cs
  21. 0 0
      Ix/NET/System.Interactive.Async/IAsyncEnumerable.cs
  22. 0 0
      Ix/NET/System.Interactive.Async/IAsyncEnumerator.cs
  23. 0 0
      Ix/NET/System.Interactive.Async/IAsyncGrouping.cs
  24. 0 0
      Ix/NET/System.Interactive.Async/IOrderedAsyncEnumerable.cs
  25. 0 0
      Ix/NET/System.Interactive.Async/Properties/AssemblyInfo.cs
  26. 0 0
      Ix/NET/System.Interactive.Async/System.Interactive.Async.csproj
  27. 0 0
      Ix/NET/System.Interactive.Async/TaskExt.cs
  28. 0 0
      Ix/NET/System.Interactive.Providers/Properties/AssemblyInfo.cs
  29. 0 0
      Ix/NET/System.Interactive.Providers/QueryableEx.cs
  30. 0 0
      Ix/NET/System.Interactive.Providers/System.Interactive.Providers.csproj
  31. 0 0
      Ix/NET/System.Interactive/EnumerableEx.Aggregates.cs
  32. 0 0
      Ix/NET/System.Interactive/EnumerableEx.Buffering.cs
  33. 0 0
      Ix/NET/System.Interactive/EnumerableEx.Creation.cs
  34. 0 0
      Ix/NET/System.Interactive/EnumerableEx.Exceptions.cs
  35. 0 0
      Ix/NET/System.Interactive/EnumerableEx.Imperative.cs
  36. 0 0
      Ix/NET/System.Interactive/EnumerableEx.Multiple.cs
  37. 0 0
      Ix/NET/System.Interactive/EnumerableEx.Single.cs
  38. 0 0
      Ix/NET/System.Interactive/Properties/AssemblyInfo.cs
  39. 0 0
      Ix/NET/System.Interactive/System.Interactive.csproj
  40. 0 0
      Ix/NET/Tests/App.cs
  41. 0 0
      Ix/NET/Tests/AsyncTests.Aggregates.cs
  42. 0 0
      Ix/NET/Tests/AsyncTests.Bugs.cs
  43. 0 0
      Ix/NET/Tests/AsyncTests.Conversions.cs
  44. 0 0
      Ix/NET/Tests/AsyncTests.Creation.cs
  45. 0 0
      Ix/NET/Tests/AsyncTests.Exceptions.cs
  46. 0 0
      Ix/NET/Tests/AsyncTests.Multiple.cs
  47. 0 0
      Ix/NET/Tests/AsyncTests.Single.cs
  48. 0 0
      Ix/NET/Tests/AsyncTests.cs
  49. 0 0
      Ix/NET/Tests/Properties/AppManifest.xml
  50. 0 0
      Ix/NET/Tests/Properties/AssemblyInfo.cs
  51. 0 0
      Ix/NET/Tests/Tests.Aggregates.cs
  52. 0 0
      Ix/NET/Tests/Tests.Buffering.cs
  53. 0 0
      Ix/NET/Tests/Tests.Creation.cs
  54. 0 0
      Ix/NET/Tests/Tests.Exceptions.cs
  55. 0 0
      Ix/NET/Tests/Tests.Imperative.cs
  56. 0 0
      Ix/NET/Tests/Tests.Multiple.cs
  57. 0 0
      Ix/NET/Tests/Tests.Qbservable.cs
  58. 0 0
      Ix/NET/Tests/Tests.Single.cs
  59. 0 0
      Ix/NET/Tests/Tests.cs
  60. 0 0
      Ix/NET/Tests/Tests.csproj
  61. 0 0
      Ix/NET/TraceAndTestImpact.testsettings
  62. 0 0
      Ix/NET/license.txt
  63. BIN
      Rx.NET/RX.snk
  64. 0 6
      Rx.NET/Rx.vsmdi
  65. 0 10
      Rx.NET/Rx.vssscc
  66. 0 28
      Rx.NET/System.Reactive.Linq/Reactive/Internal/HashSet.cs
  67. 0 66
      Rx.NET/System.Reactive.Linq/Reactive/Internal/Sink.cs
  68. 0 64
      Rx.NET/System.Reactive.Linq/Reactive/Linq/QueryLanguage.Awaiter.cs
  69. 0 116
      Rx.NET/Tests.System.Reactive/Tests/ObservableExtensionsTest.cs
  70. BIN
      Rx/NET/Resources/Artwork/Logo.ico
  71. BIN
      Rx/NET/Resources/Artwork/Logo.png
  72. BIN
      Rx/NET/Resources/Artwork/Logo_Color.png
  73. BIN
      Rx/NET/Resources/Artwork/Logo_Zip.ico
  74. 29 0
      Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample.sln
  75. 6 0
      Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/App.config
  76. 77 0
      Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/EventCorrelationSample.csproj
  77. 234 0
      Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/Program.cs
  78. 36 0
      Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/Properties/AssemblyInfo.cs
  79. 58 0
      Rx/NET/Samples/HOL/CS/Excercise1/Start/Excercise1.csproj
  80. 20 0
      Rx/NET/Samples/HOL/CS/Excercise1/Start/Excercise1.sln
  81. 15 0
      Rx/NET/Samples/HOL/CS/Excercise1/Start/Program.cs
  82. 36 0
      Rx/NET/Samples/HOL/CS/Excercise1/Start/Properties/AssemblyInfo.cs
  83. 58 0
      Rx/NET/Samples/HOL/CS/Excercise2/Start/Excercise2.csproj
  84. 20 0
      Rx/NET/Samples/HOL/CS/Excercise2/Start/Excercise2.sln
  85. 25 0
      Rx/NET/Samples/HOL/CS/Excercise2/Start/Program.cs
  86. 36 0
      Rx/NET/Samples/HOL/CS/Excercise2/Start/Properties/AssemblyInfo.cs
  87. 58 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step03/Excercise2.csproj
  88. 20 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step03/Excercise2.sln
  89. 25 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step03/Program.cs
  90. 36 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step03/Properties/AssemblyInfo.cs
  91. 58 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step04/Excercise2.csproj
  92. 20 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step04/Excercise2.sln
  93. 25 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step04/Program.cs
  94. 36 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step04/Properties/AssemblyInfo.cs
  95. 58 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step05/Excercise2.csproj
  96. 20 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step05/Excercise2.sln
  97. 25 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step05/Program.cs
  98. 36 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step05/Properties/AssemblyInfo.cs
  99. 58 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step06/Excercise2.csproj
  100. 20 0
      Rx/NET/Samples/HOL/CS/Excercise2/Step06/Excercise2.sln

+ 0 - 8
.gitignore

@@ -1,8 +0,0 @@
-[Oo]bj
-[Bb]in
-TestResults
-*.user
-*.suo
-*.[Cc]ache
-*.bak
-*.ncb

+ 0 - 0
Ix/.gitattributes → Ix/NET/.gitattributes


+ 0 - 0
Ix/.gitignore → Ix/NET/.gitignore


+ 0 - 0
Ix/Common.targets → Ix/NET/Common.targets


+ 2696 - 0
Ix/NET/Enumerable.cs

@@ -0,0 +1,2696 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+
+// Include Silverlight's managed resources
+#if SILVERLIGHT
+using System.Core;
+#endif //SILVERLIGHT
+
+namespace System.Linq
+{
+    public static class Enumerable
+    {
+        public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            if (source is Iterator<TSource>) return ((Iterator<TSource>)source).Where(predicate);
+            if (source is TSource[]) return new WhereArrayIterator<TSource>((TSource[])source, predicate);
+            if (source is List<TSource>) return new WhereListIterator<TSource>((List<TSource>)source, predicate);
+            return new WhereEnumerableIterator<TSource>(source, predicate);
+        }
+
+        public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            return WhereIterator<TSource>(source, predicate);
+        }
+
+        static IEnumerable<TSource> WhereIterator<TSource>(IEnumerable<TSource> source, Func<TSource, int, bool> predicate) {
+            int index = -1;
+            foreach (TSource element in source) {
+                checked { index++; }
+                if (predicate(element, index)) yield return element;
+            }
+        }
+
+        public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (selector == null) throw Error.ArgumentNull("selector");
+            if (source is Iterator<TSource>) return ((Iterator<TSource>)source).Select(selector);
+            if (source is TSource[]) return new WhereSelectArrayIterator<TSource, TResult>((TSource[])source, null, selector);
+            if (source is List<TSource>) return new WhereSelectListIterator<TSource, TResult>((List<TSource>)source, null, selector);
+            return new WhereSelectEnumerableIterator<TSource, TResult>(source, null, selector);
+        }
+
+        public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, int, TResult> selector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (selector == null) throw Error.ArgumentNull("selector");
+            return SelectIterator<TSource, TResult>(source, selector);
+        }
+
+        static IEnumerable<TResult> SelectIterator<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, int, TResult> selector) {
+            int index = -1;
+            foreach (TSource element in source) {
+                checked { index++; }
+                yield return selector(element, index);
+            }
+        }
+
+        static Func<TSource, bool> CombinePredicates<TSource>(Func<TSource, bool> predicate1, Func<TSource, bool> predicate2) {
+            return x => predicate1(x) && predicate2(x);
+        }
+
+        static Func<TSource, TResult> CombineSelectors<TSource, TMiddle, TResult>(Func<TSource, TMiddle> selector1, Func<TMiddle, TResult> selector2) {
+            return x => selector2(selector1(x));
+        }
+
+        abstract class Iterator<TSource> : IEnumerable<TSource>, IEnumerator<TSource>
+        {
+            int threadId;
+            internal int state;
+            internal TSource current;
+
+            public Iterator() {
+                threadId = Thread.CurrentThread.ManagedThreadId;
+            }
+
+            public TSource Current {
+                get { return current; }
+            }
+
+            public abstract Iterator<TSource> Clone();
+
+            public virtual void Dispose() {
+                current = default(TSource);
+                state = -1;
+            }
+
+            public IEnumerator<TSource> GetEnumerator() {
+                if (threadId == Thread.CurrentThread.ManagedThreadId && state == 0) {
+                    state = 1;
+                    return this;
+                }
+                Iterator<TSource> duplicate = Clone();
+                duplicate.state = 1;
+                return duplicate;
+            }
+
+            public abstract bool MoveNext();
+
+            public abstract IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector);
+
+            public abstract IEnumerable<TSource> Where(Func<TSource, bool> predicate);
+
+            object IEnumerator.Current {
+                get { return Current; }
+            }
+
+            IEnumerator IEnumerable.GetEnumerator() {
+                return GetEnumerator();
+            }
+
+            void IEnumerator.Reset() {
+                throw new NotImplementedException();
+            }
+        }
+
+        class WhereEnumerableIterator<TSource> : Iterator<TSource>
+        {
+            IEnumerable<TSource> source;
+            Func<TSource, bool> predicate;
+            IEnumerator<TSource> enumerator;
+
+            public WhereEnumerableIterator(IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+                this.source = source;
+                this.predicate = predicate;
+            }
+
+            public override Iterator<TSource> Clone() {
+                return new WhereEnumerableIterator<TSource>(source, predicate);
+            }
+
+            public override void Dispose() {
+                if (enumerator is IDisposable) ((IDisposable)enumerator).Dispose();
+                enumerator = null;
+                base.Dispose();
+            }
+
+            public override bool MoveNext() {
+                switch (state) {
+                    case 1:
+                        enumerator = source.GetEnumerator();
+                        state = 2;
+                        goto case 2;
+                    case 2:
+                        while (enumerator.MoveNext()) {
+                            TSource item = enumerator.Current;
+                            if (predicate(item)) {
+                                current = item;
+                                return true;
+                            }
+                        }
+                        Dispose();
+                        break;
+                }
+                return false;
+            }
+
+            public override IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector) {
+                return new WhereSelectEnumerableIterator<TSource, TResult>(source, predicate, selector);
+            }
+
+            public override IEnumerable<TSource> Where(Func<TSource, bool> predicate) {
+                return new WhereEnumerableIterator<TSource>(source, CombinePredicates(this.predicate, predicate));
+            }
+        }
+
+        class WhereArrayIterator<TSource> : Iterator<TSource>
+        {
+            TSource[] source;
+            Func<TSource, bool> predicate;
+            int index;
+
+            public WhereArrayIterator(TSource[] source, Func<TSource, bool> predicate) {
+                this.source = source;
+                this.predicate = predicate;
+            }
+
+            public override Iterator<TSource> Clone() {
+                return new WhereArrayIterator<TSource>(source, predicate);
+            }
+
+            public override bool MoveNext() {
+                if (state == 1) {
+                    while (index < source.Length) {
+                        TSource item = source[index];
+                        index++;
+                        if (predicate(item)) {
+                            current = item;
+                            return true;
+                        }
+                    }
+                    Dispose();
+                }
+                return false;
+            }
+
+            public override IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector) {
+                return new WhereSelectArrayIterator<TSource, TResult>(source, predicate, selector);
+            }
+
+            public override IEnumerable<TSource> Where(Func<TSource, bool> predicate) {
+                return new WhereArrayIterator<TSource>(source, CombinePredicates(this.predicate, predicate));
+            }
+        }
+
+        class WhereListIterator<TSource> : Iterator<TSource>
+        {
+            List<TSource> source;
+            Func<TSource, bool> predicate;
+            List<TSource>.Enumerator enumerator;
+
+            public WhereListIterator(List<TSource> source, Func<TSource, bool> predicate) {
+                this.source = source;
+                this.predicate = predicate;
+            }
+
+            public override Iterator<TSource> Clone() {
+                return new WhereListIterator<TSource>(source, predicate);
+            }
+
+            public override bool MoveNext() {
+                switch (state) {
+                    case 1:
+                        enumerator = source.GetEnumerator();
+                        state = 2;
+                        goto case 2;
+                    case 2:
+                        while (enumerator.MoveNext()) {
+                            TSource item = enumerator.Current;
+                            if (predicate(item)) {
+                                current = item;
+                                return true;
+                            }
+                        }
+                        Dispose();
+                        break;
+                }
+                return false;
+            }
+
+            public override IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector) {
+                return new WhereSelectListIterator<TSource, TResult>(source, predicate, selector);
+            }
+
+            public override IEnumerable<TSource> Where(Func<TSource, bool> predicate) {
+                return new WhereListIterator<TSource>(source, CombinePredicates(this.predicate, predicate));
+            }
+        }
+
+        class WhereSelectEnumerableIterator<TSource, TResult> : Iterator<TResult>
+        {
+            IEnumerable<TSource> source;
+            Func<TSource, bool> predicate;
+            Func<TSource, TResult> selector;
+            IEnumerator<TSource> enumerator;
+
+            public WhereSelectEnumerableIterator(IEnumerable<TSource> source, Func<TSource, bool> predicate, Func<TSource, TResult> selector) {
+                this.source = source;
+                this.predicate = predicate;
+                this.selector = selector;
+            }
+
+            public override Iterator<TResult> Clone() {
+                return new WhereSelectEnumerableIterator<TSource, TResult>(source, predicate, selector);
+            }
+
+            public override void Dispose() {
+                if (enumerator is IDisposable) ((IDisposable)enumerator).Dispose();
+                enumerator = null;
+                base.Dispose();
+            }
+
+            public override bool MoveNext() {
+                switch (state) {
+                    case 1:
+                        enumerator = source.GetEnumerator();
+                        state = 2;
+                        goto case 2;
+                    case 2:
+                        while (enumerator.MoveNext()) {
+                            TSource item = enumerator.Current;
+                            if (predicate == null || predicate(item)) {
+                                current = selector(item);
+                                return true;
+                            }
+                        }
+                        Dispose();
+                        break;
+                }
+                return false;
+            }
+
+            public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector) {
+                return new WhereSelectEnumerableIterator<TSource, TResult2>(source, predicate, CombineSelectors(this.selector, selector));
+            }
+
+            public override IEnumerable<TResult> Where(Func<TResult, bool> predicate) {
+                return new WhereEnumerableIterator<TResult>(this, predicate);
+            }
+        }
+
+        class WhereSelectArrayIterator<TSource, TResult> : Iterator<TResult>
+        {
+            TSource[] source;
+            Func<TSource, bool> predicate;
+            Func<TSource, TResult> selector;
+            int index;
+
+            public WhereSelectArrayIterator(TSource[] source, Func<TSource, bool> predicate, Func<TSource, TResult> selector) {
+                this.source = source;
+                this.predicate = predicate;
+                this.selector = selector;
+            }
+
+            public override Iterator<TResult> Clone() {
+                return new WhereSelectArrayIterator<TSource, TResult>(source, predicate, selector);
+            }
+
+            public override bool MoveNext() {
+                if (state == 1) {
+                    while (index < source.Length) {
+                        TSource item = source[index];
+                        index++;
+                        if (predicate == null || predicate(item)) {
+                            current = selector(item);
+                            return true;
+                        }
+                    }
+                    Dispose();
+                }
+                return false;
+            }
+
+            public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector) {
+                return new WhereSelectArrayIterator<TSource, TResult2>(source, predicate, CombineSelectors(this.selector, selector));
+            }
+
+            public override IEnumerable<TResult> Where(Func<TResult, bool> predicate) {
+                return new WhereEnumerableIterator<TResult>(this, predicate);
+            }
+        }
+
+        class WhereSelectListIterator<TSource, TResult> : Iterator<TResult>
+        {
+            List<TSource> source;
+            Func<TSource, bool> predicate;
+            Func<TSource, TResult> selector;
+            List<TSource>.Enumerator enumerator;
+
+            public WhereSelectListIterator(List<TSource> source, Func<TSource, bool> predicate, Func<TSource, TResult> selector) {
+                this.source = source;
+                this.predicate = predicate;
+                this.selector = selector;
+            }
+
+            public override Iterator<TResult> Clone() {
+                return new WhereSelectListIterator<TSource, TResult>(source, predicate, selector);
+            }
+
+            public override bool MoveNext() {
+                switch (state) {
+                    case 1:
+                        enumerator = source.GetEnumerator();
+                        state = 2;
+                        goto case 2;
+                    case 2:
+                        while (enumerator.MoveNext()) {
+                            TSource item = enumerator.Current;
+                            if (predicate == null || predicate(item)) {
+                                current = selector(item);
+                                return true;
+                            }
+                        }
+                        Dispose();
+                        break;
+                }
+                return false;
+            }
+
+            public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector) {
+                return new WhereSelectListIterator<TSource, TResult2>(source, predicate, CombineSelectors(this.selector, selector));
+            }
+
+            public override IEnumerable<TResult> Where(Func<TResult, bool> predicate) {
+                return new WhereEnumerableIterator<TResult>(this, predicate);
+            }
+        }
+
+        //public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+        //    if (source == null) throw Error.ArgumentNull("source");
+        //    if (predicate == null) throw Error.ArgumentNull("predicate");
+        //    return WhereIterator<TSource>(source, predicate);
+        //}
+
+        //static IEnumerable<TSource> WhereIterator<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+        //    foreach (TSource element in source) {
+        //        if (predicate(element)) yield return element;
+        //    }
+        //}
+
+        //public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) {
+        //    if (source == null) throw Error.ArgumentNull("source");
+        //    if (selector == null) throw Error.ArgumentNull("selector");
+        //    return SelectIterator<TSource, TResult>(source, selector);
+        //}
+
+        //static IEnumerable<TResult> SelectIterator<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, TResult> selector) {
+        //    foreach (TSource element in source) {
+        //        yield return selector(element);
+        //    }
+        //}
+
+        public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (selector == null) throw Error.ArgumentNull("selector");
+            return SelectManyIterator<TSource, TResult>(source, selector);
+        }
+
+        static IEnumerable<TResult> SelectManyIterator<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector) {
+            foreach (TSource element in source) {
+                foreach (TResult subElement in selector(element)) {
+                    yield return subElement;
+                }
+            }
+        }
+
+        public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (selector == null) throw Error.ArgumentNull("selector");
+            return SelectManyIterator<TSource, TResult>(source, selector);
+        }
+
+        static IEnumerable<TResult> SelectManyIterator<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector) {
+            int index = -1;
+            foreach (TSource element in source) {
+                checked { index++; }
+                foreach (TResult subElement in selector(element, index)) {
+                    yield return subElement;
+                }
+            }
+        }
+        public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
+        {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (collectionSelector == null) throw Error.ArgumentNull("collectionSelector");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            return SelectManyIterator<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
+        }
+
+        static IEnumerable<TResult> SelectManyIterator<TSource, TCollection, TResult>(IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector){
+            int index = -1;
+            foreach (TSource element in source){
+                checked { index++; }
+                foreach (TCollection subElement in collectionSelector(element, index)){
+                    yield return resultSelector(element, subElement);
+                }
+            }
+        }
+
+        public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (collectionSelector == null) throw Error.ArgumentNull("collectionSelector");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            return SelectManyIterator<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
+        }
+
+        static IEnumerable<TResult> SelectManyIterator<TSource, TCollection, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector) {
+            foreach (TSource element in source) {
+                foreach (TCollection subElement in collectionSelector(element)) {
+                    yield return resultSelector(element, subElement);
+                }
+            }
+        }
+
+        public static IEnumerable<TSource> Take<TSource>(this IEnumerable<TSource> source, int count) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return TakeIterator<TSource>(source, count);
+        }
+
+        static IEnumerable<TSource> TakeIterator<TSource>(IEnumerable<TSource> source, int count) {
+            if (count > 0) {
+                foreach (TSource element in source) {
+                    yield return element;
+                    if (--count == 0) break;
+                }
+            }
+        }
+
+        public static IEnumerable<TSource> TakeWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            return TakeWhileIterator<TSource>(source, predicate);
+        }
+
+        static IEnumerable<TSource> TakeWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            foreach (TSource element in source) {
+                if (!predicate(element)) break;
+                yield return element;
+            }
+        }
+
+        public static IEnumerable<TSource> TakeWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            return TakeWhileIterator<TSource>(source, predicate);
+        }
+
+        static IEnumerable<TSource> TakeWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, int, bool> predicate) {
+            int index = -1;
+            foreach (TSource element in source) {
+                checked { index++; }
+                if (!predicate(element, index)) break;
+                yield return element;
+            }
+        }
+
+        public static IEnumerable<TSource> Skip<TSource>(this IEnumerable<TSource> source, int count) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return SkipIterator<TSource>(source, count);
+        }
+
+        static IEnumerable<TSource> SkipIterator<TSource>(IEnumerable<TSource> source, int count) {
+            using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                while (count > 0 && e.MoveNext()) count--;
+                if (count <= 0) {
+                    while (e.MoveNext()) yield return e.Current;
+                }
+            }
+        }
+
+        public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            return SkipWhileIterator<TSource>(source, predicate);
+        }
+
+        static IEnumerable<TSource> SkipWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            bool yielding = false;
+            foreach (TSource element in source) {
+                if (!yielding && !predicate(element)) yielding = true;
+                if (yielding) yield return element;
+            }
+        }
+
+        public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            return SkipWhileIterator<TSource>(source, predicate);
+        }
+
+        static IEnumerable<TSource> SkipWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, int, bool> predicate) {
+            int index = -1;
+            bool yielding = false;
+            foreach (TSource element in source) {
+                checked { index++; }
+                if (!yielding && !predicate(element, index)) yielding = true;
+                if (yielding) yield return element;
+            }
+        }
+
+        public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector) {
+            if (outer == null) throw Error.ArgumentNull("outer");
+            if (inner == null) throw Error.ArgumentNull("inner");
+            if (outerKeySelector == null) throw Error.ArgumentNull("outerKeySelector");
+            if (innerKeySelector == null) throw Error.ArgumentNull("innerKeySelector");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            return JoinIterator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, null);
+        }
+
+        public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer) {
+            if (outer == null) throw Error.ArgumentNull("outer");
+            if (inner == null) throw Error.ArgumentNull("inner");
+            if (outerKeySelector == null) throw Error.ArgumentNull("outerKeySelector");
+            if (innerKeySelector == null) throw Error.ArgumentNull("innerKeySelector");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            return JoinIterator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
+        }
+
+        static IEnumerable<TResult> JoinIterator<TOuter, TInner, TKey, TResult>(IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer) {
+            Lookup<TKey, TInner> lookup = Lookup<TKey, TInner>.CreateForJoin(inner, innerKeySelector, comparer);
+            foreach (TOuter item in outer) {
+                Lookup<TKey, TInner>.Grouping g = lookup.GetGrouping(outerKeySelector(item), false);
+                if (g != null) {
+                    for (int i = 0; i < g.count; i++) {
+                        yield return resultSelector(item, g.elements[i]);
+                    }
+                }
+            }
+        }
+
+        public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector) {
+            if (outer == null) throw Error.ArgumentNull("outer");
+            if (inner == null) throw Error.ArgumentNull("inner");
+            if (outerKeySelector == null) throw Error.ArgumentNull("outerKeySelector");
+            if (innerKeySelector == null) throw Error.ArgumentNull("innerKeySelector");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            return GroupJoinIterator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, null);
+        }
+
+        public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer) {
+            if (outer == null) throw Error.ArgumentNull("outer");
+            if (inner == null) throw Error.ArgumentNull("inner");
+            if (outerKeySelector == null) throw Error.ArgumentNull("outerKeySelector");
+            if (innerKeySelector == null) throw Error.ArgumentNull("innerKeySelector");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            return GroupJoinIterator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
+        }
+
+        static IEnumerable<TResult> GroupJoinIterator<TOuter, TInner, TKey, TResult>(IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer) {
+            Lookup<TKey, TInner> lookup = Lookup<TKey, TInner>.CreateForJoin(inner, innerKeySelector, comparer);
+            foreach (TOuter item in outer) {
+                yield return resultSelector(item, lookup[outerKeySelector(item)]);
+            }
+        }
+
+        public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) {
+            return new OrderedEnumerable<TSource, TKey>(source, keySelector, null, false);
+        }
+
+        public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer) {
+            return new OrderedEnumerable<TSource, TKey>(source, keySelector, comparer, false);
+        }
+
+        public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) {
+            return new OrderedEnumerable<TSource, TKey>(source, keySelector, null, true);
+        }
+
+        public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer) {
+            return new OrderedEnumerable<TSource, TKey>(source, keySelector, comparer, true);
+        }
+
+        public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return source.CreateOrderedEnumerable<TKey>(keySelector, null, false);
+        }
+
+        public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return source.CreateOrderedEnumerable<TKey>(keySelector, comparer, false);
+        }
+
+        public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return source.CreateOrderedEnumerable<TKey>(keySelector, null, true);
+        }
+
+        public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return source.CreateOrderedEnumerable<TKey>(keySelector, comparer, true);
+        }
+
+        public static IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) {
+            return new GroupedEnumerable<TSource, TKey, TSource>(source, keySelector, IdentityFunction<TSource>.Instance, null);
+        }
+
+        public static IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer) {
+            return new GroupedEnumerable<TSource, TKey, TSource>(source, keySelector, IdentityFunction<TSource>.Instance, comparer);
+        }
+
+        public static IEnumerable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) {
+            return new GroupedEnumerable<TSource, TKey, TElement>(source, keySelector, elementSelector, null);
+        }
+
+        public static IEnumerable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer) {
+            return new GroupedEnumerable<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
+        }
+
+       public static IEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector){
+           return  new GroupedEnumerable<TSource, TKey, TSource, TResult>(source, keySelector, IdentityFunction<TSource>.Instance, resultSelector, null);
+        }
+
+        public static IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector){
+           return new GroupedEnumerable<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, null);
+        }
+
+        public static IEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer){
+            return  new GroupedEnumerable<TSource, TKey, TSource, TResult>(source, keySelector, IdentityFunction<TSource>.Instance, resultSelector, comparer);
+        }
+
+        public static IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer){
+            return  new GroupedEnumerable<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer);
+        }
+
+        public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            return ConcatIterator<TSource>(first, second);
+        }
+
+        static IEnumerable<TSource> ConcatIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second) {
+            foreach (TSource element in first) yield return element;
+            foreach (TSource element in second) yield return element;
+        }
+
+        public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector) {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            return ZipIterator(first, second, resultSelector);
+        }
+
+        static IEnumerable<TResult> ZipIterator<TFirst, TSecond, TResult>(IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector) {
+            using (IEnumerator<TFirst> e1 = first.GetEnumerator())
+                using (IEnumerator<TSecond> e2 = second.GetEnumerator())
+                    while (e1.MoveNext() && e2.MoveNext())
+                        yield return resultSelector(e1.Current, e2.Current);
+        }
+
+
+        public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return DistinctIterator<TSource>(source, null);
+        }
+
+        public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> comparer) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return DistinctIterator<TSource>(source, comparer);
+        }
+
+        static IEnumerable<TSource> DistinctIterator<TSource>(IEnumerable<TSource> source, IEqualityComparer<TSource> comparer) {
+            Set<TSource> set = new Set<TSource>(comparer);
+            foreach (TSource element in source)
+                if (set.Add(element)) yield return element;
+        }
+
+        public static IEnumerable<TSource> Union<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            return UnionIterator<TSource>(first, second, null);
+        }
+
+        public static IEnumerable<TSource> Union<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            return UnionIterator<TSource>(first, second, comparer);
+        }
+
+        static IEnumerable<TSource> UnionIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        {
+            Set<TSource> set = new Set<TSource>(comparer);
+            foreach (TSource element in first)
+                if (set.Add(element)) yield return element;
+            foreach (TSource element in second)
+                if (set.Add(element)) yield return element;
+        }
+
+        public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            return IntersectIterator<TSource>(first, second, null);
+        }
+
+        public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            return IntersectIterator<TSource>(first, second, comparer);
+        }
+
+        static IEnumerable<TSource> IntersectIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        {
+            Set<TSource> set = new Set<TSource>(comparer);
+            foreach (TSource element in second) set.Add(element);
+            foreach (TSource element in first)
+                if (set.Remove(element)) yield return element;
+        }
+
+        public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
+        {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            return ExceptIterator<TSource>(first, second, null);
+        }
+
+        public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        {
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            return ExceptIterator<TSource>(first, second, comparer);
+        }
+
+        static IEnumerable<TSource> ExceptIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer) {
+            Set<TSource> set = new Set<TSource>(comparer);
+            foreach (TSource element in second) set.Add(element);
+            foreach (TSource element in first)
+                if (set.Add(element)) yield return element;
+        }
+
+        public static IEnumerable<TSource> Reverse<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return ReverseIterator<TSource>(source);
+        }
+
+        static IEnumerable<TSource> ReverseIterator<TSource>(IEnumerable<TSource> source) {
+            Buffer<TSource> buffer = new Buffer<TSource>(source);
+            for (int i = buffer.count - 1; i >= 0; i--) yield return buffer.items[i];
+        }
+
+        public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) {
+            return SequenceEqual<TSource>(first, second, null);
+        }
+
+        public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
+        {
+            if (comparer == null) comparer = EqualityComparer<TSource>.Default;
+            if (first == null) throw Error.ArgumentNull("first");
+            if (second == null) throw Error.ArgumentNull("second");
+            using (IEnumerator<TSource> e1 = first.GetEnumerator())
+            using (IEnumerator<TSource> e2 = second.GetEnumerator())
+            {
+                while (e1.MoveNext())
+                {
+                    if (!(e2.MoveNext() && comparer.Equals(e1.Current, e2.Current))) return false;
+                }
+                if (e2.MoveNext()) return false;
+            }
+            return true;
+        }
+
+        public static IEnumerable<TSource> AsEnumerable<TSource>(this IEnumerable<TSource> source)
+        {
+            return source;
+        }
+
+        public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return new Buffer<TSource>(source).ToArray();
+        }
+
+        public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return new List<TSource>(source);
+        }
+
+        public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) {
+            return ToDictionary<TSource, TKey, TSource>(source, keySelector, IdentityFunction<TSource>.Instance, null);
+        }
+
+        public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer) {
+            return ToDictionary<TSource, TKey, TSource>(source, keySelector, IdentityFunction<TSource>.Instance, comparer);
+        }
+
+        public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) {
+            return ToDictionary<TSource, TKey, TElement>(source, keySelector, elementSelector, null);
+        }
+
+        public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (keySelector == null) throw Error.ArgumentNull("keySelector");
+            if (elementSelector == null) throw Error.ArgumentNull("elementSelector");
+            Dictionary<TKey, TElement> d = new Dictionary<TKey, TElement>(comparer);
+            foreach (TSource element in source) d.Add(keySelector(element), elementSelector(element));
+            return d;
+        }
+
+        public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) {
+            return Lookup<TKey, TSource>.Create(source, keySelector, IdentityFunction<TSource>.Instance, null);
+        }
+
+        public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer) {
+            return Lookup<TKey, TSource>.Create(source, keySelector, IdentityFunction<TSource>.Instance, comparer);
+        }
+
+        public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) {
+            return Lookup<TKey, TElement>.Create(source, keySelector, elementSelector, null);
+        }
+
+        public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer) {
+            return Lookup<TKey, TElement>.Create(source, keySelector, elementSelector, comparer);
+        }
+
+        public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source) {
+            return DefaultIfEmpty(source, default(TSource));
+        }
+
+        public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source, TSource defaultValue) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return DefaultIfEmptyIterator<TSource>(source, defaultValue);
+        }
+
+        static IEnumerable<TSource> DefaultIfEmptyIterator<TSource>(IEnumerable<TSource> source, TSource defaultValue) {
+            using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                if (e.MoveNext()) {
+                    do {
+                        yield return e.Current;
+                    } while (e.MoveNext());
+                }
+                else {
+                    yield return defaultValue;
+                }
+            }
+        }
+
+        public static IEnumerable<TResult> OfType<TResult>(this IEnumerable source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            return OfTypeIterator<TResult>(source);
+        }
+
+        static IEnumerable<TResult> OfTypeIterator<TResult>(IEnumerable source) {
+            foreach (object obj in source) {
+                if (obj is TResult) yield return (TResult)obj;
+            }
+        }
+
+        public static IEnumerable<TResult> Cast<TResult>(this IEnumerable source) {
+            IEnumerable<TResult> typedSource = source as IEnumerable<TResult>;
+            if (typedSource != null) return typedSource;
+            if (source == null) throw Error.ArgumentNull("source");
+            return CastIterator<TResult>(source);
+        }
+
+        static IEnumerable<TResult> CastIterator<TResult>(IEnumerable source) {
+            foreach (object obj in source) yield return (TResult)obj;
+        }
+
+        public static TSource First<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            IList<TSource> list = source as IList<TSource>;
+            if (list != null) {
+                if (list.Count > 0) return list[0];
+            }
+            else {
+                using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                    if (e.MoveNext()) return e.Current;
+                }
+            }
+            throw Error.NoElements();
+        }
+
+        public static TSource First<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            foreach (TSource element in source) {
+                if (predicate(element)) return element;
+            }
+            throw Error.NoMatch();
+        }
+
+        public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            IList<TSource> list = source as IList<TSource>;
+            if (list != null) {
+                if (list.Count > 0) return list[0];
+            }
+            else {
+                using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                    if (e.MoveNext()) return e.Current;
+                }
+            }
+            return default(TSource);
+        }
+
+        public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            foreach (TSource element in source) {
+                if (predicate(element)) return element;
+            }
+            return default(TSource);
+        }
+
+        public static TSource Last<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            IList<TSource> list = source as IList<TSource>;
+            if (list != null) {
+                int count = list.Count;
+                if (count > 0) return list[count - 1];
+            }
+            else {
+                using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                    if (e.MoveNext()) {
+                        TSource result;
+                        do {
+                            result = e.Current;
+                        } while (e.MoveNext());
+                        return result;
+                    }
+                }
+            }
+            throw Error.NoElements();
+        }
+
+        public static TSource Last<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            TSource result = default(TSource);
+            bool found = false;
+            foreach (TSource element in source) {
+                if (predicate(element)) {
+                    result = element;
+                    found = true;
+                }
+            }
+            if (found) return result;
+            throw Error.NoMatch();
+        }
+
+        public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            IList<TSource> list = source as IList<TSource>;
+            if (list != null) {
+                int count = list.Count;
+                if (count > 0) return list[count - 1];
+            }
+            else {
+                using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                    if (e.MoveNext()) {
+                        TSource result;
+                        do {
+                            result = e.Current;
+                        } while (e.MoveNext());
+                        return result;
+                    }
+                }
+            }
+            return default(TSource);
+        }
+
+        public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            TSource result = default(TSource);
+            foreach (TSource element in source) {
+                if (predicate(element)) {
+                    result = element;
+                }
+            }
+            return result;
+        }
+
+        public static TSource Single<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            IList<TSource> list = source as IList<TSource>;
+            if (list != null) {
+                switch (list.Count) {
+                    case 0: throw Error.NoElements();
+                    case 1: return list[0];
+                }
+            }
+            else {
+                using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                    if (!e.MoveNext()) throw Error.NoElements();
+                    TSource result = e.Current;
+                    if (!e.MoveNext()) return result;
+                }
+            }
+            throw Error.MoreThanOneElement();
+        }
+
+        public static TSource Single<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            TSource result = default(TSource);
+            long count = 0;
+            foreach (TSource element in source) {
+                if (predicate(element)) {
+                    result = element;
+                    checked { count++; }
+                }
+            }
+            switch (count) {
+                case 0: throw Error.NoMatch();
+                case 1: return result;
+            }
+            throw Error.MoreThanOneMatch();
+        }
+
+        public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            IList<TSource> list = source as IList<TSource>;
+            if (list != null) {
+                switch (list.Count) {
+                    case 0: return default(TSource);
+                    case 1: return list[0];
+                }
+            }
+            else {
+                using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                    if (!e.MoveNext()) return default(TSource);
+                    TSource result = e.Current;
+                    if (!e.MoveNext()) return result;
+                }
+            }
+            throw Error.MoreThanOneElement();
+        }
+
+        public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            TSource result = default(TSource);
+            long count = 0;
+            foreach (TSource element in source) {
+                if (predicate(element)) {
+                    result = element;
+                    checked { count++; }
+                }
+            }
+            switch (count) {
+                case 0: return default(TSource);
+                case 1: return result;
+            }
+            throw Error.MoreThanOneMatch();
+        }
+
+        public static TSource ElementAt<TSource>(this IEnumerable<TSource> source, int index) {
+            if (source == null) throw Error.ArgumentNull("source");
+            IList<TSource> list = source as IList<TSource>;
+            if (list != null) return list[index];
+            if (index < 0) throw Error.ArgumentOutOfRange("index");
+            using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                while (true) {
+                    if (!e.MoveNext()) throw Error.ArgumentOutOfRange("index");
+                    if (index == 0) return e.Current;
+                    index--;
+                }
+            }
+        }
+
+        public static TSource ElementAtOrDefault<TSource>(this IEnumerable<TSource> source, int index) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (index >= 0) {
+                IList<TSource> list = source as IList<TSource>;
+                if (list != null) {
+                    if (index < list.Count) return list[index];
+                }
+                else {
+                    using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                        while (true) {
+                            if (!e.MoveNext()) break;
+                            if (index == 0) return e.Current;
+                            index--;
+                        }
+                    }
+                }
+            }
+            return default(TSource);
+        }
+
+        public static IEnumerable<int> Range(int start, int count) {
+            long max = ((long)start) + count - 1;
+            if (count < 0 || max > Int32.MaxValue) throw Error.ArgumentOutOfRange("count");
+            return RangeIterator(start, count);
+        }
+
+        static IEnumerable<int> RangeIterator(int start, int count) {
+            for (int i = 0; i < count; i++) yield return start + i;
+        }
+
+        public static IEnumerable<TResult> Repeat<TResult>(TResult element, int count) {
+            if (count < 0) throw Error.ArgumentOutOfRange("count");
+            return RepeatIterator<TResult>(element, count);
+        }
+
+        static IEnumerable<TResult> RepeatIterator<TResult>(TResult element, int count) {
+            for (int i = 0; i < count; i++) yield return element;
+        }
+
+        public static IEnumerable<TResult> Empty<TResult>() {
+            return EmptyEnumerable<TResult>.Instance;
+        }
+
+        public static bool Any<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                if (e.MoveNext()) return true;
+            }
+            return false;
+        }
+
+        public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            foreach (TSource element in source) {
+                if (predicate(element)) return true;
+            }
+            return false;
+        }
+
+        public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            foreach (TSource element in source) {
+                if (!predicate(element)) return false;
+            }
+            return true;
+        }
+
+        public static int Count<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            ICollection<TSource> collectionoft = source as ICollection<TSource>;
+            if (collectionoft != null) return collectionoft.Count;
+            ICollection collection = source as ICollection;
+            if (collection != null) return collection.Count;
+            int count = 0;
+            using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                checked {
+                    while (e.MoveNext()) count++;
+                }
+            }
+            return count;
+        }
+
+        public static int Count<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            int count = 0;
+            foreach (TSource element in source) {
+                checked {
+                    if (predicate(element)) count++;
+                }
+            }
+            return count;
+        }
+
+        public static long LongCount<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long count = 0;
+            using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                checked {
+                    while (e.MoveNext()) count++;
+                }
+            }
+            return count;
+        }
+
+        public static long LongCount<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (predicate == null) throw Error.ArgumentNull("predicate");
+            long count = 0;
+            foreach (TSource element in source) {
+                checked {
+                    if (predicate(element)) count++;
+                }
+            }
+            return count;
+        }
+
+        public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value) {
+            ICollection<TSource> collection = source as ICollection<TSource>;
+            if (collection != null) return collection.Contains(value);
+            return Contains<TSource>(source, value, null);
+        }
+
+        public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer)
+        {
+            if (comparer == null) comparer = EqualityComparer<TSource>.Default;
+            if (source == null) throw Error.ArgumentNull("source");
+            foreach (TSource element in source)
+                if (comparer.Equals(element, value)) return true;
+            return false;
+        }
+
+        public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func)
+        {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (func == null) throw Error.ArgumentNull("func");
+            using (IEnumerator<TSource> e = source.GetEnumerator()) {
+                if (!e.MoveNext()) throw Error.NoElements();
+                TSource result = e.Current;
+                while (e.MoveNext()) result = func(result, e.Current);
+                return result;
+            }
+        }
+
+        public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (func == null) throw Error.ArgumentNull("func");
+            TAccumulate result = seed;
+            foreach (TSource element in source) result = func(result, element);
+            return result;
+        }
+
+        public static TResult Aggregate<TSource, TAccumulate, TResult>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (func == null) throw Error.ArgumentNull("func");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            TAccumulate result = seed;
+            foreach (TSource element in source) result = func(result, element);
+            return resultSelector(result);
+        }
+
+        public static int Sum(this IEnumerable<int> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            int sum = 0;
+            checked {
+                foreach (int v in source) sum += v;
+            }
+            return sum;
+        }
+
+        public static int? Sum(this IEnumerable<int?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            int sum = 0;
+            checked {
+                foreach (int? v in source) {
+                    if (v != null) sum += v.GetValueOrDefault();
+                }
+            }
+            return sum;
+        }
+
+        public static long Sum(this IEnumerable<long> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long sum = 0;
+            checked {
+                foreach (long v in source) sum += v;
+            }
+            return sum;
+        }
+
+        public static long? Sum(this IEnumerable<long?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long sum = 0;
+            checked {
+                foreach (long? v in source) {
+                    if (v != null) sum += v.GetValueOrDefault();
+                }
+            }
+            return sum;
+        }
+
+        public static float Sum(this IEnumerable<float> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            foreach (float v in source) sum += v;
+            return (float)sum;
+        }
+
+        public static float? Sum(this IEnumerable<float?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            foreach (float? v in source) {
+                if (v != null) sum += v.GetValueOrDefault();
+            }
+            return (float)sum;
+        }
+
+        public static double Sum(this IEnumerable<double> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            foreach (double v in source) sum += v;
+            return sum;
+        }
+
+        public static double? Sum(this IEnumerable<double?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            foreach (double? v in source) {
+                if (v != null) sum += v.GetValueOrDefault();
+            }
+            return sum;
+        }
+
+        public static decimal Sum(this IEnumerable<decimal> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal sum = 0;
+            foreach (decimal v in source) sum += v;
+            return sum;
+        }
+
+        public static decimal? Sum(this IEnumerable<decimal?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal sum = 0;
+            foreach (decimal? v in source) {
+                if (v != null) sum += v.GetValueOrDefault();
+            }
+            return sum;
+        }
+
+        public static int Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static int? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static long Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static long? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static float Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static float? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static double Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static double? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static decimal Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static decimal? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector) {
+            return Enumerable.Sum(Enumerable.Select(source, selector));
+        }
+
+        public static int Min(this IEnumerable<int> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            int value = 0;
+            bool hasValue = false;
+            foreach (int x in source) {
+                if (hasValue) {
+                    if (x < value) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static int? Min(this IEnumerable<int?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            int? value = null;
+            foreach (int? x in source) {
+                if (value == null || x < value)
+                    value = x;
+            }
+            return value;
+        }
+
+        public static long Min(this IEnumerable<long> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long value = 0;
+            bool hasValue = false;
+            foreach (long x in source) {
+                if (hasValue) {
+                    if (x < value) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static long? Min(this IEnumerable<long?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long? value = null;
+            foreach (long? x in source) {
+                if (value == null || x < value) value = x;
+            }
+            return value;
+        }
+
+        public static float Min(this IEnumerable<float> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            float value = 0;
+            bool hasValue = false;
+            foreach (float x in source) {
+                if (hasValue) {
+                    // Normally NaN < anything is false, as is anything < NaN
+                    // However, this leads to some irksome outcomes in Min and Max.
+                    // If we use those semantics then Min(NaN, 5.0) is NaN, but
+                    // Min(5.0, NaN) is 5.0!  To fix this, we impose a total
+                    // ordering where NaN is smaller than every value, including
+                    // negative infinity.
+                    if (x < value || System.Single.IsNaN(x)) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static float? Min(this IEnumerable<float?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            float? value = null;
+            foreach (float? x in source) {
+                if (x == null) continue;
+                if (value == null || x < value || System.Single.IsNaN((float)x)) value = x;
+            }
+            return value;
+        }
+
+        public static double Min(this IEnumerable<double> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double value = 0;
+            bool hasValue = false;
+            foreach (double x in source) {
+                if (hasValue) {
+                    if (x < value || System.Double.IsNaN(x)) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static double? Min(this IEnumerable<double?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double? value = null;
+            foreach (double? x in source) {
+                if (x == null) continue;
+                if (value == null || x < value || System.Double.IsNaN((double)x)) value = x;
+            }
+            return value;
+        }
+
+        public static decimal Min(this IEnumerable<decimal> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal value = 0;
+            bool hasValue = false;
+            foreach (decimal x in source) {
+                if (hasValue) {
+                    if (x < value) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static decimal? Min(this IEnumerable<decimal?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal? value = null;
+            foreach (decimal? x in source) {
+                if (value == null || x < value) value = x;
+            }
+            return value;
+        }
+
+        public static TSource Min<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            Comparer<TSource> comparer = Comparer<TSource>.Default;
+            TSource value = default(TSource);
+            if (value == null) {
+                foreach (TSource x in source) {
+                    if (x != null && (value == null || comparer.Compare(x, value) < 0))
+                        value = x;
+                }
+                return value;
+            }
+            else {
+                bool hasValue = false;
+                foreach (TSource x in source) {
+                    if (hasValue) {
+                        if (comparer.Compare(x, value) < 0)
+                            value = x;
+                    }
+                    else {
+                        value = x;
+                        hasValue = true;
+                    }
+                }
+                if (hasValue) return value;
+                throw Error.NoElements();
+            }
+        }
+
+        public static int Min<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static int? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static long Min<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static long? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static float Min<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static float? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static double Min<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static double? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static decimal Min<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static decimal? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static TResult Min<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) {
+            return Enumerable.Min(Enumerable.Select(source, selector));
+        }
+
+        public static int Max(this IEnumerable<int> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            int value = 0;
+            bool hasValue = false;
+            foreach (int x in source) {
+                if (hasValue) {
+                    if (x > value) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static int? Max(this IEnumerable<int?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            int? value = null;
+            foreach (int? x in source) {
+                if (value == null || x > value) value = x;
+            }
+            return value;
+        }
+
+        public static long Max(this IEnumerable<long> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long value = 0;
+            bool hasValue = false;
+            foreach (long x in source) {
+                if (hasValue) {
+                    if (x > value) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static long? Max(this IEnumerable<long?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long? value = null;
+            foreach (long? x in source) {
+                if (value == null || x > value) value = x;
+            }
+            return value;
+        }
+
+        public static double Max(this IEnumerable<double> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double value = 0;
+            bool hasValue = false;
+            foreach (double x in source) {
+                if (hasValue) {
+                    if (x > value || System.Double.IsNaN(value)) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static double? Max(this IEnumerable<double?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double? value = null;
+            foreach (double? x in source) {
+                if (x == null) continue;
+                if (value == null || x > value || System.Double.IsNaN((double)value)) value = x;
+            }
+            return value;
+        }
+
+        public static float Max(this IEnumerable<float> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            float value = 0;
+            bool hasValue = false;
+            foreach (float x in source) {
+                if (hasValue) {
+                    if (x > value || System.Double.IsNaN(value)) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static float? Max(this IEnumerable<float?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            float? value = null;
+            foreach (float? x in source) {
+                if (x == null) continue;
+                if (value == null || x > value || System.Single.IsNaN((float)value)) value = x;
+            }
+            return value;
+        }
+
+        public static decimal Max(this IEnumerable<decimal> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal value = 0;
+            bool hasValue = false;
+            foreach (decimal x in source) {
+                if (hasValue) {
+                    if (x > value) value = x;
+                }
+                else {
+                    value = x;
+                    hasValue = true;
+                }
+            }
+            if (hasValue) return value;
+            throw Error.NoElements();
+        }
+
+        public static decimal? Max(this IEnumerable<decimal?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal? value = null;
+            foreach (decimal? x in source) {
+                if (value == null || x > value) value = x;
+            }
+            return value;
+        }
+
+        public static TSource Max<TSource>(this IEnumerable<TSource> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            Comparer<TSource> comparer = Comparer<TSource>.Default;
+            TSource value = default(TSource);
+            if (value == null) {
+                foreach (TSource x in source) {
+                    if (x != null && (value == null || comparer.Compare(x, value) > 0))
+                        value = x;
+                }
+                return value;
+            }
+            else {
+                bool hasValue = false;
+                foreach (TSource x in source) {
+                    if (hasValue) {
+                        if (comparer.Compare(x, value) > 0)
+                            value = x;
+                    }
+                    else {
+                        value = x;
+                        hasValue = true;
+                    }
+                }
+                if (hasValue) return value;
+                throw Error.NoElements();
+            }
+        }
+
+        public static int Max<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static int? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static long Max<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static long? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static float Max<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static float? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static double Max<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static double? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static decimal Max<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static decimal? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static TResult Max<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) {
+            return Enumerable.Max(Enumerable.Select(source, selector));
+        }
+
+        public static double Average(this IEnumerable<int> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long sum = 0;
+            long count = 0;
+            checked {
+                foreach (int v in source) {
+                    sum += v;
+                    count++;
+                }
+            }
+            if (count > 0) return (double)sum / count;
+            throw Error.NoElements();
+        }
+
+        public static double? Average(this IEnumerable<int?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long sum = 0;
+            long count = 0;
+            checked {
+                foreach (int? v in source) {
+                    if (v != null) {
+                        sum += v.GetValueOrDefault();
+                        count++;
+                    }
+                }
+            }
+            if (count > 0) return (double)sum / count;
+            return null;
+        }
+
+        public static double Average(this IEnumerable<long> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long sum = 0;
+            long count = 0;
+            checked {
+                foreach (long v in source) {
+                    sum += v;
+                    count++;
+                }
+            }
+            if (count > 0) return (double)sum / count;
+            throw Error.NoElements();
+        }
+
+        public static double? Average(this IEnumerable<long?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            long sum = 0;
+            long count = 0;
+            checked {
+                foreach (long? v in source) {
+                    if (v != null) {
+                        sum += v.GetValueOrDefault();
+                        count++;
+                    }
+                }
+            }
+            if (count > 0) return (double)sum / count;
+            return null;
+        }
+
+        public static float Average(this IEnumerable<float> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            long count = 0;
+            checked {
+                foreach (float v in source) {
+                    sum += v;
+                    count++;
+                }
+            }
+            if (count > 0) return (float)(sum / count);
+            throw Error.NoElements();
+        }
+
+        public static float? Average(this IEnumerable<float?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            long count = 0;
+            checked {
+                foreach (float? v in source) {
+                    if (v != null) {
+                        sum += v.GetValueOrDefault();
+                        count++;
+                    }
+                }
+            }
+            if (count > 0) return (float)(sum / count);
+            return null;
+        }
+
+        public static double Average(this IEnumerable<double> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            long count = 0;
+            checked {
+                foreach (double v in source) {
+                    sum += v;
+                    count++;
+                }
+            }
+            if (count > 0) return sum / count;
+            throw Error.NoElements();
+        }
+
+        public static double? Average(this IEnumerable<double?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            double sum = 0;
+            long count = 0;
+            checked {
+                foreach (double? v in source) {
+                    if (v != null) {
+                        sum += v.GetValueOrDefault();
+                        count++;
+                    }
+                }
+            }
+            if (count > 0) return sum / count;
+            return null;
+        }
+
+        public static decimal Average(this IEnumerable<decimal> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal sum = 0;
+            long count = 0;
+            checked {
+                foreach (decimal v in source) {
+                    sum += v;
+                    count++;
+                }
+            }
+            if (count > 0) return sum / count;
+            throw Error.NoElements();
+        }
+
+        public static decimal? Average(this IEnumerable<decimal?> source) {
+            if (source == null) throw Error.ArgumentNull("source");
+            decimal sum = 0;
+            long count = 0;
+            checked {
+                foreach (decimal? v in source) {
+                    if (v != null) {
+                        sum += v.GetValueOrDefault();
+                        count++;
+                    }
+                }
+            }
+            if (count > 0) return sum / count;
+            return null;
+        }
+
+        public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static float Average<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static float? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static decimal Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+
+        public static decimal? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector) {
+            return Enumerable.Average(Enumerable.Select(source, selector));
+        }
+    }
+
+    internal class EmptyEnumerable<TElement>
+    {
+        static volatile TElement[] instance;
+
+        public static IEnumerable<TElement> Instance {
+            get {
+                if (instance == null) instance = new TElement[0];
+                return instance;
+            }
+        }
+    }
+
+    internal class IdentityFunction<TElement>
+    {
+        public static Func<TElement, TElement> Instance {
+            get { return x => x; }
+        }
+    }
+
+    public interface IOrderedEnumerable<TElement> : IEnumerable<TElement>
+    {
+        IOrderedEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending);
+    }
+
+#if SILVERLIGHT
+    public interface IGrouping<TKey, TElement> : IEnumerable<TElement>
+#else
+    public interface IGrouping<out TKey, out TElement> : IEnumerable<TElement>
+#endif
+    {
+        TKey Key { get; }
+    }
+
+    public interface ILookup<TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>{
+        int Count { get; }
+        IEnumerable<TElement> this[TKey key] { get; }
+        bool Contains(TKey key);
+    }
+
+    public class Lookup<TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>, ILookup<TKey, TElement>{
+        IEqualityComparer<TKey> comparer;
+        Grouping[] groupings;
+        Grouping lastGrouping;
+        int count;
+
+        internal static Lookup<TKey, TElement> Create<TSource>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (keySelector == null) throw Error.ArgumentNull("keySelector");
+            if (elementSelector == null) throw Error.ArgumentNull("elementSelector");
+            Lookup<TKey, TElement> lookup = new Lookup<TKey, TElement>(comparer);
+            foreach (TSource item in source) {
+                lookup.GetGrouping(keySelector(item), true).Add(elementSelector(item));
+            }
+            return lookup;
+        }
+
+        internal static Lookup<TKey, TElement> CreateForJoin(IEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey> comparer) {
+            Lookup<TKey, TElement> lookup = new Lookup<TKey, TElement>(comparer);
+            foreach (TElement item in source) {
+                TKey key = keySelector(item);
+                if (key != null) lookup.GetGrouping(key, true).Add(item);
+            }
+            return lookup;
+        }
+
+        Lookup(IEqualityComparer<TKey> comparer) {
+            if (comparer == null) comparer = EqualityComparer<TKey>.Default;
+            this.comparer = comparer;
+            groupings = new Grouping[7];
+        }
+
+        public int Count {
+            get { return count; }
+        }
+
+        public IEnumerable<TElement> this[TKey key] {
+            get {
+                Grouping grouping = GetGrouping(key, false);
+                if (grouping != null) return grouping;
+                return EmptyEnumerable<TElement>.Instance;
+            }
+        }
+
+        public bool Contains(TKey key) {
+            return GetGrouping(key, false) != null;
+        }
+
+        public IEnumerator<IGrouping<TKey, TElement>> GetEnumerator() {
+            Grouping g = lastGrouping;
+            if (g != null) {
+                do {
+                    g = g.next;
+                    yield return g;
+                } while (g != lastGrouping);
+            }
+        }
+
+        public IEnumerable<TResult> ApplyResultSelector<TResult>(Func<TKey, IEnumerable<TElement>, TResult> resultSelector){
+            Grouping g = lastGrouping;
+            if (g != null) {
+                do {
+                    g = g.next;
+                    if (g.count != g.elements.Length) { Array.Resize<TElement>(ref g.elements, g.count); }
+                    yield return resultSelector(g.key, g.elements);
+                }while (g != lastGrouping);
+            }
+        }
+
+        IEnumerator IEnumerable.GetEnumerator() {
+            return GetEnumerator();
+        }
+
+        internal int InternalGetHashCode(TKey key)
+        {
+            //EDMAURER DevDivBugs 171937. work around comparer implementations that throw when passed null
+            return (key == null) ? 0 : comparer.GetHashCode(key) & 0x7FFFFFFF;
+        }
+
+        internal Grouping GetGrouping(TKey key, bool create) {
+            int hashCode = InternalGetHashCode(key);
+            for (Grouping g = groupings[hashCode % groupings.Length]; g != null; g = g.hashNext)
+                if (g.hashCode == hashCode && comparer.Equals(g.key, key)) return g;
+            if (create) {
+                if (count == groupings.Length) Resize();
+                int index = hashCode % groupings.Length;
+                Grouping g = new Grouping();
+                g.key = key;
+                g.hashCode = hashCode;
+                g.elements = new TElement[1];
+                g.hashNext = groupings[index];
+                groupings[index] = g;
+                if (lastGrouping == null) {
+                    g.next = g;
+                }
+                else {
+                    g.next = lastGrouping.next;
+                    lastGrouping.next = g;
+                }
+                lastGrouping = g;
+                count++;
+                return g;
+            }
+            return null;
+        }
+
+        void Resize() {
+            int newSize = checked(count * 2 + 1);
+            Grouping[] newGroupings = new Grouping[newSize];
+            Grouping g = lastGrouping;
+            do {
+                g = g.next;
+                int index = g.hashCode % newSize;
+                g.hashNext = newGroupings[index];
+                newGroupings[index] = g;
+            } while (g != lastGrouping);
+            groupings = newGroupings;
+        }
+
+        internal class Grouping : IGrouping<TKey, TElement>, IList<TElement>
+        {
+            internal TKey key;
+            internal int hashCode;
+            internal TElement[] elements;
+            internal int count;
+            internal Grouping hashNext;
+            internal Grouping next;
+
+            internal void Add(TElement element) {
+                if (elements.Length == count) Array.Resize(ref elements, checked(count * 2));
+                elements[count] = element;
+                count++;
+            }
+
+            public IEnumerator<TElement> GetEnumerator() {
+                for (int i = 0; i < count; i++) yield return elements[i];
+            }
+
+            IEnumerator IEnumerable.GetEnumerator() {
+                return GetEnumerator();
+            }
+
+            // DDB195907: implement IGrouping<>.Key implicitly
+            // so that WPF binding works on this property.
+            public TKey Key {
+                get { return key; }
+            }
+
+            int ICollection<TElement>.Count {
+                get { return count; }
+            }
+
+            bool ICollection<TElement>.IsReadOnly {
+                get { return true; }
+            }
+
+            void ICollection<TElement>.Add(TElement item) {
+                throw Error.NotSupported();
+            }
+
+            void ICollection<TElement>.Clear() {
+                throw Error.NotSupported();
+            }
+
+            bool ICollection<TElement>.Contains(TElement item) {
+                return Array.IndexOf(elements, item, 0, count) >= 0;
+            }
+
+            void ICollection<TElement>.CopyTo(TElement[] array, int arrayIndex) {
+                Array.Copy(elements, 0, array, arrayIndex, count);
+            }
+
+            bool ICollection<TElement>.Remove(TElement item) {
+                throw Error.NotSupported();
+            }
+
+            int IList<TElement>.IndexOf(TElement item) {
+                return Array.IndexOf(elements, item, 0, count);
+            }
+
+            void IList<TElement>.Insert(int index, TElement item) {
+                throw Error.NotSupported();
+            }
+
+            void IList<TElement>.RemoveAt(int index) {
+                throw Error.NotSupported();
+            }
+
+            TElement IList<TElement>.this[int index] {
+                get {
+                    if (index < 0 || index >= count) throw Error.ArgumentOutOfRange("index");
+                    return elements[index];
+                }
+                set {
+                    throw Error.NotSupported();
+                }
+            }
+        }
+    }
+
+    // @BUG: Dev10 858919 (zlatkom). PLINQ is now using this class (Dev11 MQ).
+    internal class Set<TElement>
+    {
+        int[] buckets;
+        Slot[] slots;
+        int count;
+        int freeList;
+        IEqualityComparer<TElement> comparer;
+
+        public Set() : this(null) { }
+
+        public Set(IEqualityComparer<TElement> comparer) {
+            if (comparer == null) comparer = EqualityComparer<TElement>.Default;
+            this.comparer = comparer;
+            buckets = new int[7];
+            slots = new Slot[7];
+            freeList = -1;
+        }
+
+        // If value is not in set, add it and return true; otherwise return false
+        public bool Add(TElement value) {
+            return !Find(value, true);
+        }
+
+        // Check whether value is in set
+        public bool Contains(TElement value) {
+            return Find(value, false);
+        }
+
+        // If value is in set, remove it and return true; otherwise return false
+        public bool Remove(TElement value) {
+            int hashCode = InternalGetHashCode(value);
+            int bucket = hashCode % buckets.Length;
+            int last = -1;
+            for (int i = buckets[bucket] - 1; i >= 0; last = i, i = slots[i].next) {
+                if (slots[i].hashCode == hashCode && comparer.Equals(slots[i].value, value)) {
+                    if (last < 0) {
+                        buckets[bucket] = slots[i].next + 1;
+                    }
+                    else {
+                        slots[last].next = slots[i].next;
+                    }
+                    slots[i].hashCode = -1;
+                    slots[i].value = default(TElement);
+                    slots[i].next = freeList;
+                    freeList = i;
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        bool Find(TElement value, bool add) {
+            int hashCode = InternalGetHashCode(value);
+            for (int i = buckets[hashCode % buckets.Length] - 1; i >= 0; i = slots[i].next) {
+                if (slots[i].hashCode == hashCode && comparer.Equals(slots[i].value, value)) return true;
+            }
+            if (add) {
+                int index;
+                if (freeList >= 0) {
+                    index = freeList;
+                    freeList = slots[index].next;
+                }
+                else {
+                    if (count == slots.Length) Resize();
+                    index = count;
+                    count++;
+                }
+                int bucket = hashCode % buckets.Length;
+                slots[index].hashCode = hashCode;
+                slots[index].value = value;
+                slots[index].next = buckets[bucket] - 1;
+                buckets[bucket] = index + 1;
+            }
+            return false;
+        }
+
+        void Resize() {
+            int newSize = checked(count * 2 + 1);
+            int[] newBuckets = new int[newSize];
+            Slot[] newSlots = new Slot[newSize];
+            Array.Copy(slots, 0, newSlots, 0, count);
+            for (int i = 0; i < count; i++) {
+                int bucket = newSlots[i].hashCode % newSize;
+                newSlots[i].next = newBuckets[bucket] - 1;
+                newBuckets[bucket] = i + 1;
+            }
+            buckets = newBuckets;
+            slots = newSlots;
+        }
+
+        internal int InternalGetHashCode(TElement value)
+        {
+            //EDMAURER DevDivBugs 171937. work around comparer implementations that throw when passed null
+            return (value == null) ? 0 : comparer.GetHashCode(value) & 0x7FFFFFFF;
+        }
+
+        internal struct Slot
+        {
+            internal int hashCode;
+            internal TElement value;
+            internal int next;
+        }
+    }
+
+    internal class GroupedEnumerable<TSource, TKey, TElement, TResult> : IEnumerable<TResult>{
+        IEnumerable<TSource> source;
+        Func<TSource, TKey> keySelector;
+        Func<TSource, TElement> elementSelector;
+        IEqualityComparer<TKey> comparer;
+        Func<TKey, IEnumerable<TElement>, TResult> resultSelector;
+
+        public GroupedEnumerable(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer){
+            if (source == null) throw Error.ArgumentNull("source");
+            if (keySelector == null) throw Error.ArgumentNull("keySelector");
+            if (elementSelector == null) throw Error.ArgumentNull("elementSelector");
+            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
+            this.source = source;
+            this.keySelector = keySelector;
+            this.elementSelector = elementSelector;
+            this.comparer = comparer;
+            this.resultSelector = resultSelector;
+        }
+
+        public IEnumerator<TResult> GetEnumerator(){
+            Lookup<TKey, TElement> lookup = Lookup<TKey, TElement>.Create<TSource>(source, keySelector, elementSelector, comparer);
+            return lookup.ApplyResultSelector(resultSelector).GetEnumerator();
+        }
+
+        IEnumerator IEnumerable.GetEnumerator(){
+            return GetEnumerator();
+        }
+    }
+
+    internal class GroupedEnumerable<TSource, TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>
+    {
+        IEnumerable<TSource> source;
+        Func<TSource, TKey> keySelector;
+        Func<TSource, TElement> elementSelector;
+        IEqualityComparer<TKey> comparer;
+
+        public GroupedEnumerable(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (keySelector == null) throw Error.ArgumentNull("keySelector");
+            if (elementSelector == null) throw Error.ArgumentNull("elementSelector");
+            this.source = source;
+            this.keySelector = keySelector;
+            this.elementSelector = elementSelector;
+            this.comparer = comparer;
+        }
+
+        public IEnumerator<IGrouping<TKey, TElement>> GetEnumerator() {
+            return Lookup<TKey, TElement>.Create<TSource>(source, keySelector, elementSelector, comparer).GetEnumerator();
+        }
+
+        IEnumerator IEnumerable.GetEnumerator() {
+            return GetEnumerator();
+        }
+    }
+
+    internal abstract class OrderedEnumerable<TElement> : IOrderedEnumerable<TElement>
+    {
+        internal IEnumerable<TElement> source;
+
+        public IEnumerator<TElement> GetEnumerator() {
+            Buffer<TElement> buffer = new Buffer<TElement>(source);
+            if (buffer.count > 0) {
+                EnumerableSorter<TElement> sorter = GetEnumerableSorter(null);
+                int[] map = sorter.Sort(buffer.items, buffer.count);
+                sorter = null;
+                for (int i = 0; i < buffer.count; i++) yield return buffer.items[map[i]];
+            }
+        }
+
+        internal abstract EnumerableSorter<TElement> GetEnumerableSorter(EnumerableSorter<TElement> next);
+
+        IEnumerator IEnumerable.GetEnumerator() {
+            return GetEnumerator();
+        }
+
+        IOrderedEnumerable<TElement> IOrderedEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending) {
+            OrderedEnumerable<TElement, TKey> result = new OrderedEnumerable<TElement, TKey>(source, keySelector, comparer, descending);
+            result.parent = this;
+            return result;
+        }
+    }
+
+    internal class OrderedEnumerable<TElement, TKey> : OrderedEnumerable<TElement>
+    {
+        internal OrderedEnumerable<TElement> parent;
+        internal Func<TElement, TKey> keySelector;
+        internal IComparer<TKey> comparer;
+        internal bool descending;
+
+        internal OrderedEnumerable(IEnumerable<TElement> source, Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending) {
+            if (source == null) throw Error.ArgumentNull("source");
+            if (keySelector == null) throw Error.ArgumentNull("keySelector");
+            this.source = source;
+            this.parent = null;
+            this.keySelector = keySelector;
+            this.comparer = comparer != null ? comparer : Comparer<TKey>.Default;
+            this.descending = descending;
+        }
+
+        internal override EnumerableSorter<TElement> GetEnumerableSorter(EnumerableSorter<TElement> next) {
+            EnumerableSorter<TElement> sorter = new EnumerableSorter<TElement, TKey>(keySelector, comparer, descending, next);
+            if (parent != null) sorter = parent.GetEnumerableSorter(sorter);
+            return sorter;
+        }
+    }
+
+    internal abstract class EnumerableSorter<TElement>
+    {
+        internal abstract void ComputeKeys(TElement[] elements, int count);
+
+        internal abstract int CompareKeys(int index1, int index2);
+
+        internal int[] Sort(TElement[] elements, int count) {
+            ComputeKeys(elements, count);
+            int[] map = new int[count];
+            for (int i = 0; i < count; i++) map[i] = i;
+            QuickSort(map, 0, count - 1);
+            return map;
+        }
+
+        void QuickSort(int[] map, int left, int right) {
+            do {
+                int i = left;
+                int j = right;
+                int x = map[i + ((j - i) >> 1)];
+                do {
+                    while (i < map.Length && CompareKeys(x, map[i]) > 0) i++;
+                    while (j >= 0 && CompareKeys(x, map[j]) < 0) j--;
+                    if (i > j) break;
+                    if (i < j) {
+                        int temp = map[i];
+                        map[i] = map[j];
+                        map[j] = temp;
+                    }
+                    i++;
+                    j--;
+                } while (i <= j);
+                if (j - left <= right - i) {
+                    if (left < j) QuickSort(map, left, j);
+                    left = i;
+                }
+                else {
+                    if (i < right) QuickSort(map, i, right);
+                    right = j;
+                }
+            } while (left < right);
+        }
+    }
+
+    internal class EnumerableSorter<TElement, TKey> : EnumerableSorter<TElement>
+    {
+        internal Func<TElement, TKey> keySelector;
+        internal IComparer<TKey> comparer;
+        internal bool descending;
+        internal EnumerableSorter<TElement> next;
+        internal TKey[] keys;
+
+        internal EnumerableSorter(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending, EnumerableSorter<TElement> next) {
+            this.keySelector = keySelector;
+            this.comparer = comparer;
+            this.descending = descending;
+            this.next = next;
+        }
+
+        internal override void ComputeKeys(TElement[] elements, int count) {
+            keys = new TKey[count];
+            for (int i = 0; i < count; i++) keys[i] = keySelector(elements[i]);
+            if (next != null) next.ComputeKeys(elements, count);
+        }
+
+        internal override int CompareKeys(int index1, int index2) {
+            int c = comparer.Compare(keys[index1], keys[index2]);
+            if (c == 0) {
+                if (next == null) return index1 - index2;
+                return next.CompareKeys(index1, index2);
+            }
+            return descending ? -c : c;
+        }
+    }
+
+    struct Buffer<TElement>
+    {
+        internal TElement[] items;
+        internal int count;
+
+        internal Buffer(IEnumerable<TElement> source) {
+            TElement[] items = null;
+            int count = 0;
+            ICollection<TElement> collection = source as ICollection<TElement>;
+            if (collection != null) {
+                count = collection.Count;
+                if (count > 0) {
+                    items = new TElement[count];
+                    collection.CopyTo(items, 0);
+                }
+            }
+            else {
+                foreach (TElement item in source) {
+                    if (items == null) {
+                        items = new TElement[4];
+                    }
+                    else if (items.Length == count) {
+                        TElement[] newItems = new TElement[checked(count * 2)];
+                        Array.Copy(items, 0, newItems, 0, count);
+                        items = newItems;
+                    }
+                    items[count] = item;
+                    count++;
+                }
+            }
+            this.items = items;
+            this.count = count;
+        }
+
+        internal TElement[] ToArray() {
+            if (count == 0) return new TElement[0];
+            if (items.Length == count) return items;
+            TElement[] result = new TElement[count];
+            Array.Copy(items, 0, result, 0, count);
+            return result;
+        }
+    }
+
+    /// <summary>
+    /// This class provides the items view for the Enumerable
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    internal sealed class SystemCore_EnumerableDebugView<T>
+    {
+        public SystemCore_EnumerableDebugView(IEnumerable<T> enumerable)
+        {
+            if (enumerable == null)
+            {
+                throw new ArgumentNullException("enumerable");
+            }
+
+            this.enumerable = enumerable;
+        }
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        public T[] Items
+        {
+            get
+            {
+                List<T> tempList = new List<T>();
+                IEnumerator<T> currentEnumerator = this.enumerable.GetEnumerator();
+
+                if (currentEnumerator != null)
+                {
+                    for(count = 0; currentEnumerator.MoveNext(); count++)
+                    {
+                        tempList.Add(currentEnumerator.Current);
+                    }
+                }
+                if (count == 0)
+                {
+                    throw new SystemCore_EnumerableDebugViewEmptyException();
+                }
+                cachedCollection = new T[this.count];
+                tempList.CopyTo(cachedCollection, 0);
+                return cachedCollection;
+            }
+        }
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        private IEnumerable<T> enumerable;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        private T[] cachedCollection;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        private int count;
+    }
+
+    internal sealed class SystemCore_EnumerableDebugViewEmptyException : Exception
+    {
+        public string Empty
+        {
+            get
+            {
+                return Strings.EmptyEnumerable;
+            }
+        }
+    }
+
+    internal sealed class SystemCore_EnumerableDebugView
+    {
+        public SystemCore_EnumerableDebugView(IEnumerable enumerable)
+        {
+            if (enumerable == null)
+            {
+                throw new ArgumentNullException("enumerable");
+            }
+
+            this.enumerable = enumerable;
+            count = 0;
+            cachedCollection = null;
+        }
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        public object[] Items
+        {
+            get
+            {
+                List<object> tempList = new List<object>();
+                IEnumerator currentEnumerator = this.enumerable.GetEnumerator();
+
+                if (currentEnumerator != null)
+                {
+                    for (count = 0; currentEnumerator.MoveNext(); count++)
+                    {
+                        tempList.Add(currentEnumerator.Current);
+                    }
+                }
+                if (count == 0)
+                {
+                    throw new SystemCore_EnumerableDebugViewEmptyException();
+                }
+                cachedCollection = new object[this.count];
+                tempList.CopyTo(cachedCollection, 0);
+                return cachedCollection;
+            }
+        }
+        
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        private IEnumerable enumerable;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        private object[] cachedCollection;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        private int count;
+    }
+}

+ 0 - 0
Ix/Import.targets → Ix/NET/Import.targets


+ 0 - 0
Ix/Interactive Extensions.sln → Ix/NET/Interactive Extensions.sln


+ 0 - 0
Ix/Interactive Extensions.vsmdi → Ix/NET/Interactive Extensions.vsmdi


+ 0 - 0
Ix/Interactive Extensions.vssscc → Ix/NET/Interactive Extensions.vssscc


+ 0 - 0
Ix/Local.testsettings → Ix/NET/Local.testsettings


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerable.Aggregates.cs → Ix/NET/System.Interactive.Async/AsyncEnumerable.Aggregates.cs


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerable.Conversions.cs → Ix/NET/System.Interactive.Async/AsyncEnumerable.Conversions.cs


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerable.Creation.cs → Ix/NET/System.Interactive.Async/AsyncEnumerable.Creation.cs


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerable.Exceptions.cs → Ix/NET/System.Interactive.Async/AsyncEnumerable.Exceptions.cs


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerable.Generated.cs → Ix/NET/System.Interactive.Async/AsyncEnumerable.Generated.cs


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerable.Multiple.cs → Ix/NET/System.Interactive.Async/AsyncEnumerable.Multiple.cs


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerable.Single.cs → Ix/NET/System.Interactive.Async/AsyncEnumerable.Single.cs


+ 0 - 0
Ix/System.Interactive.Async/AsyncEnumerator.cs → Ix/NET/System.Interactive.Async/AsyncEnumerator.cs


+ 0 - 0
Ix/System.Interactive.Async/Disposables.cs → Ix/NET/System.Interactive.Async/Disposables.cs


+ 0 - 0
Ix/System.Interactive.Async/EnumerableGrouping.cs → Ix/NET/System.Interactive.Async/EnumerableGrouping.cs


+ 0 - 0
Ix/System.Interactive.Async/IAsyncEnumerable.cs → Ix/NET/System.Interactive.Async/IAsyncEnumerable.cs


+ 0 - 0
Ix/System.Interactive.Async/IAsyncEnumerator.cs → Ix/NET/System.Interactive.Async/IAsyncEnumerator.cs


+ 0 - 0
Ix/System.Interactive.Async/IAsyncGrouping.cs → Ix/NET/System.Interactive.Async/IAsyncGrouping.cs


+ 0 - 0
Ix/System.Interactive.Async/IOrderedAsyncEnumerable.cs → Ix/NET/System.Interactive.Async/IOrderedAsyncEnumerable.cs


+ 0 - 0
Ix/System.Interactive.Async/Properties/AssemblyInfo.cs → Ix/NET/System.Interactive.Async/Properties/AssemblyInfo.cs


+ 0 - 0
Ix/System.Interactive.Async/System.Interactive.Async.csproj → Ix/NET/System.Interactive.Async/System.Interactive.Async.csproj


+ 0 - 0
Ix/System.Interactive.Async/TaskExt.cs → Ix/NET/System.Interactive.Async/TaskExt.cs


+ 0 - 0
Ix/System.Interactive.Providers/Properties/AssemblyInfo.cs → Ix/NET/System.Interactive.Providers/Properties/AssemblyInfo.cs


+ 0 - 0
Ix/System.Interactive.Providers/QueryableEx.cs → Ix/NET/System.Interactive.Providers/QueryableEx.cs


+ 0 - 0
Ix/System.Interactive.Providers/System.Interactive.Providers.csproj → Ix/NET/System.Interactive.Providers/System.Interactive.Providers.csproj


+ 0 - 0
Ix/System.Interactive/EnumerableEx.Aggregates.cs → Ix/NET/System.Interactive/EnumerableEx.Aggregates.cs


+ 0 - 0
Ix/System.Interactive/EnumerableEx.Buffering.cs → Ix/NET/System.Interactive/EnumerableEx.Buffering.cs


+ 0 - 0
Ix/System.Interactive/EnumerableEx.Creation.cs → Ix/NET/System.Interactive/EnumerableEx.Creation.cs


+ 0 - 0
Ix/System.Interactive/EnumerableEx.Exceptions.cs → Ix/NET/System.Interactive/EnumerableEx.Exceptions.cs


+ 0 - 0
Ix/System.Interactive/EnumerableEx.Imperative.cs → Ix/NET/System.Interactive/EnumerableEx.Imperative.cs


+ 0 - 0
Ix/System.Interactive/EnumerableEx.Multiple.cs → Ix/NET/System.Interactive/EnumerableEx.Multiple.cs


+ 0 - 0
Ix/System.Interactive/EnumerableEx.Single.cs → Ix/NET/System.Interactive/EnumerableEx.Single.cs


+ 0 - 0
Ix/System.Interactive/Properties/AssemblyInfo.cs → Ix/NET/System.Interactive/Properties/AssemblyInfo.cs


+ 0 - 0
Ix/System.Interactive/System.Interactive.csproj → Ix/NET/System.Interactive/System.Interactive.csproj


+ 0 - 0
Ix/Tests/App.cs → Ix/NET/Tests/App.cs


+ 0 - 0
Ix/Tests/AsyncTests.Aggregates.cs → Ix/NET/Tests/AsyncTests.Aggregates.cs


+ 0 - 0
Ix/Tests/AsyncTests.Bugs.cs → Ix/NET/Tests/AsyncTests.Bugs.cs


+ 0 - 0
Ix/Tests/AsyncTests.Conversions.cs → Ix/NET/Tests/AsyncTests.Conversions.cs


+ 0 - 0
Ix/Tests/AsyncTests.Creation.cs → Ix/NET/Tests/AsyncTests.Creation.cs


+ 0 - 0
Ix/Tests/AsyncTests.Exceptions.cs → Ix/NET/Tests/AsyncTests.Exceptions.cs


+ 0 - 0
Ix/Tests/AsyncTests.Multiple.cs → Ix/NET/Tests/AsyncTests.Multiple.cs


+ 0 - 0
Ix/Tests/AsyncTests.Single.cs → Ix/NET/Tests/AsyncTests.Single.cs


+ 0 - 0
Ix/Tests/AsyncTests.cs → Ix/NET/Tests/AsyncTests.cs


+ 0 - 0
Ix/Tests/Properties/AppManifest.xml → Ix/NET/Tests/Properties/AppManifest.xml


+ 0 - 0
Ix/Tests/Properties/AssemblyInfo.cs → Ix/NET/Tests/Properties/AssemblyInfo.cs


+ 0 - 0
Ix/Tests/Tests.Aggregates.cs → Ix/NET/Tests/Tests.Aggregates.cs


+ 0 - 0
Ix/Tests/Tests.Buffering.cs → Ix/NET/Tests/Tests.Buffering.cs


+ 0 - 0
Ix/Tests/Tests.Creation.cs → Ix/NET/Tests/Tests.Creation.cs


+ 0 - 0
Ix/Tests/Tests.Exceptions.cs → Ix/NET/Tests/Tests.Exceptions.cs


+ 0 - 0
Ix/Tests/Tests.Imperative.cs → Ix/NET/Tests/Tests.Imperative.cs


+ 0 - 0
Ix/Tests/Tests.Multiple.cs → Ix/NET/Tests/Tests.Multiple.cs


+ 0 - 0
Ix/Tests/Tests.Qbservable.cs → Ix/NET/Tests/Tests.Qbservable.cs


+ 0 - 0
Ix/Tests/Tests.Single.cs → Ix/NET/Tests/Tests.Single.cs


+ 0 - 0
Ix/Tests/Tests.cs → Ix/NET/Tests/Tests.cs


+ 0 - 0
Ix/Tests/Tests.csproj → Ix/NET/Tests/Tests.csproj


+ 0 - 0
Ix/TraceAndTestImpact.testsettings → Ix/NET/TraceAndTestImpact.testsettings


+ 0 - 0
Ix/license.txt → Ix/NET/license.txt


BIN
Rx.NET/RX.snk


+ 0 - 6
Rx.NET/Rx.vsmdi

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
-  <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
-    <RunConfiguration id="a2f63e98-7f97-4ca7-9d25-6313d3452023" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-  </TestList>
-</TestLists>

+ 0 - 10
Rx.NET/Rx.vssscc

@@ -1,10 +0,0 @@
-""
-{
-"FILE_VERSION" = "9237"
-"ENLISTMENT_CHOICE" = "NEVER"
-"PROJECT_FILE_RELATIVE_PATH" = ""
-"NUMBER_OF_EXCLUDED_FILES" = "0"
-"ORIGINAL_PROJECT_FILE_PATH" = ""
-"NUMBER_OF_NESTED_PROJECTS" = "0"
-"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
-}

+ 0 - 28
Rx.NET/System.Reactive.Linq/Reactive/Internal/HashSet.cs

@@ -1,28 +0,0 @@
-// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
-
-#if NO_HASHSET
-using System;
-using System.Collections.Generic;
-
-namespace System.Reactive
-{
-    class HashSet<T>
-    {
-        private Dictionary<T, object> _set;
-
-        public HashSet(IEqualityComparer<T> comparer)
-        {
-            _set = new Dictionary<T, object>(comparer);
-        }
-
-        public bool Add(T value)
-        {
-            if (_set.ContainsKey(value))
-                return false;
-
-            _set[value] = null;
-            return true;
-        }
-    }
-}
-#endif

+ 0 - 66
Rx.NET/System.Reactive.Linq/Reactive/Internal/Sink.cs

@@ -1,66 +0,0 @@
-#if !NO_PERF
-using System.Threading;
-
-namespace System.Reactive
-{
-    /// <summary>
-    /// Base class for implementation of query operators, providing a lightweight sink that can be disposed to mute the outgoing observer.
-    /// </summary>
-    /// <typeparam name="TSource">Type of the resulting sequence's elements.</typeparam>
-    /// <remarks>Implementations of sinks are responsible to enforce the message grammar on the associated observer. Upon sending a terminal message, a pairing Dispose call should be made to trigger cancellation of related resources and to mute the outgoing observer.</remarks>
-    abstract class Sink<TSource> : IDisposable
-    {
-        protected volatile IObserver<TSource> _observer;
-        private IDisposable _cancel;
-
-        public Sink(IObserver<TSource> observer, IDisposable cancel)
-        {
-            _observer = observer;
-            _cancel = cancel;
-        }
-
-        public virtual void Dispose()
-        {
-            _observer = NopObserver<TSource>.Instance;
-
-            var cancel = Interlocked.Exchange(ref _cancel, null);
-            if (cancel != null)
-            {
-                cancel.Dispose();
-            }
-        }
-
-        public IObserver<TSource> GetForwarder()
-        {
-            return new _(this);
-        }
-
-        class _ : IObserver<TSource>
-        {
-            private readonly Sink<TSource> _forward;
-
-            public _(Sink<TSource> forward)
-            {
-                _forward = forward;
-            }
-
-            public void OnNext(TSource value)
-            {
-                _forward._observer.OnNext(value);
-            }
-
-            public void OnError(Exception error)
-            {
-                _forward._observer.OnError(error);
-                _forward.Dispose();
-            }
-
-            public void OnCompleted()
-            {
-                _forward._observer.OnCompleted();
-                _forward.Dispose();
-            }
-        }
-    }
-}
-#endif

+ 0 - 64
Rx.NET/System.Reactive.Linq/Reactive/Linq/QueryLanguage.Awaiter.cs

@@ -1,64 +0,0 @@
-// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
-
-#if HAS_AWAIT
-using System.Threading;
-using System.Reactive.Disposables;
-using System.Reactive.Subjects;
-
-namespace System.Reactive.Linq
-{
-    internal partial class QueryLanguage
-    {
-        public virtual AsyncSubject<TSource> GetAwaiter<TSource>(IObservable<TSource> source)
-        {
-            var s = new AsyncSubject<TSource>();
-            source.SubscribeSafe(s);
-            return s;
-        }
-
-        public virtual AsyncSubject<TSource> GetAwaiter<TSource>(IConnectableObservable<TSource> source)
-        {
-            var s = new AsyncSubject<TSource>();
-            source.SubscribeSafe(s);
-            source.Connect();
-            return s;
-        }
-
-        public virtual AsyncSubject<TSource> RunAsync<TSource>(IObservable<TSource> source, CancellationToken cancellationToken)
-        {
-            var s = new AsyncSubject<TSource>();
-
-            var cancel = new Action(() => s.OnError(new OperationCanceledException()));
-            if (cancellationToken.IsCancellationRequested)
-            {
-                cancel();
-                return s;
-            }
-
-            var d = source.SubscribeSafe(s);
-            cancellationToken.Register(d.Dispose);
-            cancellationToken.Register(cancel);
-
-            return s;
-        }
-
-        public virtual AsyncSubject<TSource> RunAsync<TSource>(IConnectableObservable<TSource> source, CancellationToken cancellationToken)
-        {
-            var s = new AsyncSubject<TSource>();
-
-            var cancel = new Action(() => s.OnError(new OperationCanceledException()));
-            if (cancellationToken.IsCancellationRequested)
-            {
-                cancel();
-                return s;
-            }
-
-            var d = new CompositeDisposable(source.SubscribeSafe(s), source.Connect());
-            cancellationToken.Register(d.Dispose);
-            cancellationToken.Register(cancel);
-
-            return s;
-        }
-    }
-}
-#endif

+ 0 - 116
Rx.NET/Tests.System.Reactive/Tests/ObservableExtensionsTest.cs

@@ -1,116 +0,0 @@
-// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
-
-using System;
-using System.Reactive.Concurrency;
-using System.Reactive.Linq;
-using Microsoft.Reactive.Testing;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace ReactiveTests.Tests
-{
-    [TestClass]
-    public partial class ObservableExtensionsTest : ReactiveTest
-    {
-        #region Subscribe
-
-        [TestMethod]
-        public void Subscribe_ArgumentChecking()
-        {
-            var someObservable = Observable.Empty<int>();
-
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(default(IObservable<int>)));
-
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(default(IObservable<int>), _ => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, default(Action<int>)));
-
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(default(IObservable<int>), _ => { }, () => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, default(Action<int>), () => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, _ => { }, default(Action)));
-
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(default(IObservable<int>), _ => { }, (Exception _) => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, default(Action<int>), (Exception _) => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, _ => { }, default(Action<Exception>)));
-
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(default(IObservable<int>), _ => { }, (Exception _) => { }, () => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, default(Action<int>), (Exception _) => { }, () => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, _ => { }, default(Action<Exception>), () => { }));
-            ReactiveAssert.Throws<ArgumentNullException>(() => ObservableExtensions.Subscribe<int>(someObservable, _ => { }, (Exception _) => { }, default(Action)));
-        }
-
-        [TestMethod]
-        public void Subscribe_None_Return()
-        {
-            Observable.Return(1, Scheduler.Immediate).Subscribe();
-        }
-
-        [TestMethod]
-        public void Subscribe_None_Throw()
-        {
-            var ex = new Exception();
-
-            var xs = Observable.Throw<int>(ex, Scheduler.Immediate);
-
-            ReactiveAssert.Throws(ex, () => xs.Subscribe());
-        }
-
-        [TestMethod]
-        public void Subscribe_None_Empty()
-        {
-            Observable.Empty<int>(Scheduler.Immediate).Subscribe((int _) => { Assert.Fail(); });
-        }
-
-        [TestMethod]
-        public void Subscribe_OnNext_Return()
-        {
-            int _x = -1;
-            Observable.Return(42, Scheduler.Immediate).Subscribe((int x) => { _x = x; });
-            Assert.AreEqual(42, _x);
-        }
-
-        [TestMethod]
-        public void Subscribe_OnNext_Throw()
-        {
-            var ex = new Exception();
-
-            var xs = Observable.Throw<int>(ex, Scheduler.Immediate);
-
-            ReactiveAssert.Throws(ex, () => xs.Subscribe(_ => { Assert.Fail(); }));
-        }
-
-        [TestMethod]
-        public void Subscribe_OnNext_Empty()
-        {
-            Observable.Empty<int>(Scheduler.Immediate).Subscribe((int _) => { Assert.Fail(); });
-        }
-
-        [TestMethod]
-        public void Subscribe_OnNextOnCompleted_Return()
-        {
-            bool finished = false;
-            int _x = -1;
-            Observable.Return(42, Scheduler.Immediate).Subscribe((int x) => { _x = x; }, () => { finished = true; });
-            Assert.AreEqual(42, _x);
-            Assert.IsTrue(finished);
-        }
-
-        [TestMethod]
-        public void Subscribe_OnNextOnCompleted_Throw()
-        {
-            var ex = new Exception();
-
-            var xs = Observable.Throw<int>(ex, Scheduler.Immediate);
-
-            ReactiveAssert.Throws(ex, () => xs.Subscribe(_ => { Assert.Fail(); }, () => { Assert.Fail(); }));
-        }
-
-        [TestMethod]
-        public void Subscribe_OnNextOnCompleted_Empty()
-        {
-            bool finished = false;
-            Observable.Empty<int>(Scheduler.Immediate).Subscribe((int _) => { Assert.Fail(); }, () => { finished = true; });
-            Assert.IsTrue(finished);
-        }
-
-        #endregion
-    }
-}

BIN
Rx/NET/Resources/Artwork/Logo.ico


BIN
Rx/NET/Resources/Artwork/Logo.png


BIN
Rx/NET/Resources/Artwork/Logo_Color.png


BIN
Rx/NET/Resources/Artwork/Logo_Zip.ico


+ 29 - 0
Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample.sln

@@ -0,0 +1,29 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventCorrelationSample", "EventCorrelationSample\EventCorrelationSample.csproj", "{268FE559-08B0-4258-A4FD-48DDD7B167B8}"
+EndProject
+Global
+	GlobalSection(TeamFoundationVersionControl) = preSolution
+		SccNumberOfProjects = 2
+		SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
+		SccTeamFoundationServer = http://sqlbuvsts01:8080/main
+		SccLocalPath0 = .
+		SccProjectUniqueName1 = EventCorrelationSample\\EventCorrelationSample.csproj
+		SccProjectName1 = EventCorrelationSample
+		SccLocalPath1 = EventCorrelationSample
+	EndGlobalSection
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{268FE559-08B0-4258-A4FD-48DDD7B167B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{268FE559-08B0-4258-A4FD-48DDD7B167B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{268FE559-08B0-4258-A4FD-48DDD7B167B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{268FE559-08B0-4258-A4FD-48DDD7B167B8}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 6 - 0
Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+    </startup>
+</configuration>

+ 77 - 0
Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/EventCorrelationSample.csproj

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{268FE559-08B0-4258-A4FD-48DDD7B167B8}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>EventCorrelationSample</RootNamespace>
+    <AssemblyName>EventCorrelationSample</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <SccProjectName>SAK</SccProjectName>
+    <SccLocalPath>SAK</SccLocalPath>
+    <SccAuxPath>SAK</SccAuxPath>
+    <SccProvider>SAK</SccProvider>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Reactive.Core, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\Reactive Extensions\v2.0\Binaries\.NETFramework\v4.5\System.Reactive.Core.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Reactive.Interfaces, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\Reactive Extensions\v2.0\Binaries\.NETFramework\v4.5\System.Reactive.Interfaces.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Reactive.Linq, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\Reactive Extensions\v2.0\Binaries\.NETFramework\v4.5\System.Reactive.Linq.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Reactive.PlatformServices, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\Reactive Extensions\v2.0\Binaries\.NETFramework\v4.5\System.Reactive.PlatformServices.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.CSharp" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <WCFMetadata Include="Service References\" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 234 - 0
Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/Program.cs

@@ -0,0 +1,234 @@
+/*
+ * Example showing the use of Rx for monitoring correlated activity event tracing streams.
+ * 
+ * bartde - 10/10/2012
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Reactive;
+using System.Reactive.Linq;
+using System.Reactive.Subjects;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace EventCorrelationSample
+{
+    class Program
+    {
+        //
+        // Those fields represent the ETW infrastructure.
+        //
+        private static Subject<BeginActivity> _beginActivities = new Subject<BeginActivity>();
+        private static Subject<EndActivity> _endActivities = new Subject<EndActivity>();
+        private static Subject<BeginTaskA> _beginAs = new Subject<BeginTaskA>();
+        private static Subject<EndTaskA> _endAs = new Subject<EndTaskA>();
+        private static Subject<BeginTaskB> _beginBs = new Subject<BeginTaskB>();
+        private static Subject<EndTaskB> _endBs = new Subject<EndTaskB>();
+
+        static void Main(string[] args)
+        {
+            //
+            // Timestamps would really be inserted by ETW, but we'll add them ourselves using Rx's Timestamp operator.
+            //
+            var beginActivities = _beginActivities.Timestamp();
+            var endActivities = _endActivities.Timestamp();
+            var beginAs = _beginAs.Timestamp();
+            var endAs = _endAs.Timestamp();
+            var beginBs = _beginBs.Timestamp();
+            var endBs = _endBs.Timestamp();
+
+            //
+            // Analyze length of requests.
+            //
+            var requests = from b in beginActivities
+                           from e in endActivities.Where(e => e.Value.Id == b.Value.Id)
+                           select new { Id = b.Value.Id, Length = e.Timestamp - b.Timestamp };
+
+            requests.Subscribe(Print(ConsoleColor.Yellow));
+
+            //
+            // Correlate task information.
+            //
+            var info = from beginAct in beginActivities
+                       let activityId = beginAct.Value.Id /* improve readability */
+                       //
+                       // Obtain correlated streams. Subscription doesn't happen here yet.
+                       //
+                       let endAct = endActivities.FirstAsync(e => e.Value.Id == activityId) /* correlated end event */
+                       let taskAs = /* correlated task A events; will contain payload and start/end times */
+                            from beginA in beginAs.TakeUntil(endAct).Where(a => a.Value.ActivityId == activityId)
+                            from endA in endAs.FirstAsync(e => e.Value.Id == beginA.Value.Id) /* correlation between the task's begin/end events */
+                            select new { Value = (int?)beginA.Value.Value, Start = beginA.Timestamp, End = endA.Timestamp }
+                       let taskBs = /* correlated task B events; will contain payload and start/end times */
+                            from beginB in beginBs.TakeUntil(endAct).Where(b => b.Value.ActivityId == activityId)
+                            from endB in endBs.FirstAsync(e => e.Value.Id == beginB.Value.Id) /* correlation between the task's begin/end events */
+                            select new { Value = beginB.Value.Value, Start = beginB.Timestamp, End = endB.Timestamp }
+                       //
+                       // Parallel observation of all of the above, using CombineLatest with seed values for events that can be absent.
+                       // The SelectMany operator, bound to by from...from... syntax causes the flattening of beginActivities and the result of parallel observation.
+                       //
+                       from res in Observable.CombineLatest(
+                            endAct,
+                            taskAs.StartWith(new { Value = default(int?), Start = DateTimeOffset.MinValue, End = DateTimeOffset.MinValue }),
+                            taskBs.StartWith(new { Value = default(string), Start = DateTimeOffset.MinValue, End = DateTimeOffset.MinValue }),
+                            (e, a, b) => new { e, a, b }).LastAsync() /* the stream will end because all substreams end (due to FirstAsync and TakeUntil use); only forward the last combined result */
+                       select new { 
+                           Activity = activityId, StartTime = beginAct.Timestamp, EndTime = res.e.Timestamp,
+                           PayloadA = res.a.Value != null ? res.a.Value.ToString() : "(none)", DurationA = res.a.End - res.a.Start,
+                           PayloadB = res.b.Value ?? "(none)", DurationB = res.b.End - res.b.Start
+                       };
+
+            info.Subscribe(Print(ConsoleColor.Cyan));
+
+            StartService();
+        }
+
+        static void StartService()
+        {
+            //
+            // Mimics talking to ETW.
+            //
+            var beginActivitiesObserver = Observer.Synchronize(_beginActivities);
+            var endActivitiesObserver = Observer.Synchronize(_endActivities);
+            var beginAsObserver = Observer.Synchronize(_beginAs);
+            var endAsObserver = Observer.Synchronize(_endAs);
+            var beginBsObserver = Observer.Synchronize(_beginBs);
+            var endBsObserver = Observer.Synchronize(_endBs);
+
+            //
+            // Master random number generator + throttle to max 10 requests at the same time.
+            //
+            var rnd = new Random();
+            var semaphore = new Semaphore(10, 10);
+
+            while (true)
+            {
+                semaphore.WaitOne();
+
+                var seed = rnd.Next();
+                Task.Run(async () =>
+                {
+                    var rand = new Random(seed);
+
+                    var requestId = Guid.NewGuid();
+
+                    Print(ConsoleColor.Green)("Starting request " + requestId);
+
+                    var measure = Stopwatch.StartNew();
+                    beginActivitiesObserver.OnNext(new BeginActivity { Id = requestId });
+
+                    Thread.Sleep(rand.Next(50, 300));
+
+                    var tossA = rand.Next(2);
+                    var tossB = rand.Next(2);
+
+                    var tasks = new List<Task>(tossA + tossB);
+                    var diag = new List<string>();
+
+                    if (tossA == 1)
+                    {
+                        var aDelay = rand.Next(20, 70);
+                        var aLength = rand.Next(100, 2000);
+                        var aValue = rand.Next(0, 43);
+
+                        diag.Add(string.Format("A(d = {0}, t = {1}, x = {2})", aDelay, aLength, aValue));
+
+                        tasks.Add(Task.Run(() =>
+                        {
+                            var taskId = Guid.NewGuid();
+
+                            Thread.Sleep(aDelay);
+                            beginAsObserver.OnNext(new BeginTaskA { Id = taskId, ActivityId = requestId, Value = aValue });
+                            Thread.Sleep(aLength);
+                            endAsObserver.OnNext(new EndTaskA { Id = taskId });
+                        }));
+                    }
+
+                    if (tossB == 1)
+                    {
+                        var bDelay = rand.Next(10, 40);
+                        var bLength = rand.Next(100, 2000);
+                        var alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
+                        var bValue = new string(Enumerable.Range(0, rand.Next(0, 10)).Select(x => alphabet[rand.Next(alphabet.Length)]).ToArray());
+
+                        diag.Add(string.Format("B(d = {0}, t = {1}, x = {2})", bDelay, bLength, bValue));
+
+                        tasks.Add(Task.Run(() =>
+                        {
+                            var taskId = Guid.NewGuid();
+
+                            Thread.Sleep(bDelay);
+                            beginBsObserver.OnNext(new BeginTaskB { Id = taskId, ActivityId = requestId, Value = bValue });
+                            Thread.Sleep(bLength);
+                            endBsObserver.OnNext(new EndTaskB { Id = taskId });
+                        }));
+                    }
+
+                    await Task.WhenAll(tasks);
+
+                    Thread.Sleep(rand.Next(50, 100));
+
+                    measure.Stop();
+                    Print(ConsoleColor.Red)(string.Format("Ending request {0} (d = {1}) {2}", requestId, measure.Elapsed, string.Join(" ", diag)));
+                    endActivitiesObserver.OnNext(new EndActivity { Id = requestId });
+
+                    semaphore.Release();
+                });
+            }
+        }
+
+        static object s_gate = new object();
+
+        static void WriteLine(ConsoleColor color, object message)
+        {
+            lock (s_gate)
+            {
+                Console.ForegroundColor = color;
+                Console.WriteLine(message);
+                Console.ResetColor();
+            }
+        }
+
+        static Action<object> Print(ConsoleColor color)
+        {
+            return s => WriteLine(color, s);
+        }
+    }
+
+    class Event
+    {
+        public Guid Id { get; set; }
+    }
+
+    class BeginActivity : Event
+    {
+    }
+
+    class EndActivity : Event
+    {
+    }
+
+    class BeginTaskA : Event
+    {
+        public Guid ActivityId { get; set; }
+        public int Value { get; set; }
+    }
+
+    class EndTaskA : Event
+    {
+    }
+
+    class BeginTaskB : Event
+    {
+        public Guid ActivityId { get; set; }
+        public string Value { get; set; }
+    }
+
+    class EndTaskB : Event
+    {
+        public string Value { get; set; }
+    }
+}

+ 36 - 0
Rx/NET/Samples/EventCorrelationSample/EventCorrelationSample/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("EventCorrelationSample")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("EventCorrelationSample")]
+[assembly: AssemblyCopyright("Copyright ©  2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("d6d7c0d7-c065-4f58-b078-a1ab8dd23449")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 58 - 0
Rx/NET/Samples/HOL/CS/Excercise1/Start/Excercise1.csproj

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{64025149-E5AD-4566-9E82-7408B2176FD3}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Excercise1</RootNamespace>
+    <AssemblyName>Excercise1</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Reactive, Version=1.0.10425.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 20 - 0
Rx/NET/Samples/HOL/CS/Excercise1/Start/Excercise1.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excercise1", "Excercise1.csproj", "{64025149-E5AD-4566-9E82-7408B2176FD3}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{64025149-E5AD-4566-9E82-7408B2176FD3}.Debug|x86.ActiveCfg = Debug|x86
+		{64025149-E5AD-4566-9E82-7408B2176FD3}.Debug|x86.Build.0 = Debug|x86
+		{64025149-E5AD-4566-9E82-7408B2176FD3}.Release|x86.ActiveCfg = Release|x86
+		{64025149-E5AD-4566-9E82-7408B2176FD3}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 15 - 0
Rx/NET/Samples/HOL/CS/Excercise1/Start/Program.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Reactive.Linq;
+
+namespace Excercise1
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            IObservable<int> source;
+            IObserver<int> handler;
+
+        }
+    }
+}

+ 36 - 0
Rx/NET/Samples/HOL/CS/Excercise1/Start/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Excercise1")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Excercise1")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("c2c174e8-ff52-447f-a66c-2951492718cf")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 58 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Start/Excercise2.csproj

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{AF344E14-373F-4DD8-A784-A33040B39FD5}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Excercise2</RootNamespace>
+    <AssemblyName>Excercise2</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Reactive, Version=1.0.10425.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 20 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Start/Excercise2.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excercise2", "Excercise2.csproj", "{AF344E14-373F-4DD8-A784-A33040B39FD5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.ActiveCfg = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.Build.0 = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.ActiveCfg = Release|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 25 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Start/Program.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Linq;
+using System.Reactive.Linq;
+
+namespace Excercise2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            IObservable<int> source = null /* We’ll explore a set of factory methods here */;
+
+            IDisposable subscription = source.Subscribe(
+                x  => Console.WriteLine("OnNext:  {0}", x),
+                ex => Console.WriteLine("OnError: {0}", ex.Message),
+                () => Console.WriteLine("OnCompleted")
+            );
+
+            Console.WriteLine("Press ENTER to unsubscribe...");
+            Console.ReadLine();
+            
+            subscription.Dispose();
+        }
+    }
+}

+ 36 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Start/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Excercise2")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Excercise2")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a639ddeb-d032-48b0-9b70-6108606b2bbb")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 58 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step03/Excercise2.csproj

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{6F62C380-C2B1-4702-8A73-9101FCAB2E38}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Excercise2</RootNamespace>
+    <AssemblyName>Excercise2</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Reactive, Version=1.0.10425.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 20 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step03/Excercise2.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excercise2", "Excercise2.csproj", "{AF344E14-373F-4DD8-A784-A33040B39FD5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.ActiveCfg = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.Build.0 = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.ActiveCfg = Release|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 25 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step03/Program.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Linq;
+using System.Reactive.Linq;
+
+namespace Excercise2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            IObservable<int> source = Observable.Empty<int>();
+
+            IDisposable subscription = source.Subscribe(
+                x  => Console.WriteLine("OnNext:  {0}", x),
+                ex => Console.WriteLine("OnError: {0}", ex.Message),
+                () => Console.WriteLine("OnCompleted")
+            );
+
+            Console.WriteLine("Press ENTER to unsubscribe...");
+            Console.ReadLine();
+            
+            subscription.Dispose();
+        }
+    }
+}

+ 36 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step03/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Excercise2")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Excercise2")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a639ddeb-d032-48b0-9b70-6108606b2bbb")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 58 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step04/Excercise2.csproj

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{289C6220-CB61-413F-8C14-21AEDEB94B4C}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Excercise2</RootNamespace>
+    <AssemblyName>Excercise2</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Reactive, Version=1.0.10425.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 20 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step04/Excercise2.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excercise2", "Excercise2.csproj", "{AF344E14-373F-4DD8-A784-A33040B39FD5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.ActiveCfg = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.Build.0 = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.ActiveCfg = Release|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 25 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step04/Program.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Linq;
+using System.Reactive.Linq;
+
+namespace Excercise2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            IObservable<int> source = Observable.Throw<int>(new Exception("Oops"));
+
+            IDisposable subscription = source.Subscribe(
+                x  => Console.WriteLine("OnNext:  {0}", x),
+                ex => Console.WriteLine("OnError: {0}", ex.Message),
+                () => Console.WriteLine("OnCompleted")
+            );
+
+            Console.WriteLine("Press ENTER to unsubscribe...");
+            Console.ReadLine();
+            
+            subscription.Dispose();
+        }
+    }
+}

+ 36 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step04/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Excercise2")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Excercise2")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a639ddeb-d032-48b0-9b70-6108606b2bbb")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 58 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step05/Excercise2.csproj

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{BC16C11F-D510-4CE9-ABA4-3E703ED48FBD}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Excercise2</RootNamespace>
+    <AssemblyName>Excercise2</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Reactive, Version=1.0.10425.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 20 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step05/Excercise2.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excercise2", "Excercise2.csproj", "{AF344E14-373F-4DD8-A784-A33040B39FD5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.ActiveCfg = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.Build.0 = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.ActiveCfg = Release|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 25 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step05/Program.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Linq;
+using System.Reactive.Linq;
+
+namespace Excercise2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            IObservable<int> source = Observable.Return(42);
+
+            IDisposable subscription = source.Subscribe(
+                x  => Console.WriteLine("OnNext:  {0}", x),
+                ex => Console.WriteLine("OnError: {0}", ex.Message),
+                () => Console.WriteLine("OnCompleted")
+            );
+
+            Console.WriteLine("Press ENTER to unsubscribe...");
+            Console.ReadLine();
+            
+            subscription.Dispose();
+        }
+    }
+}

+ 36 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step05/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Excercise2")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Excercise2")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a639ddeb-d032-48b0-9b70-6108606b2bbb")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 58 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step06/Excercise2.csproj

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{E4136784-3DC4-438F-9E90-E261CCE9DA6C}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Excercise2</RootNamespace>
+    <AssemblyName>Excercise2</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Reactive, Version=1.0.10425.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 20 - 0
Rx/NET/Samples/HOL/CS/Excercise2/Step06/Excercise2.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excercise2", "Excercise2.csproj", "{AF344E14-373F-4DD8-A784-A33040B39FD5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.ActiveCfg = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Debug|x86.Build.0 = Debug|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.ActiveCfg = Release|x86
+		{AF344E14-373F-4DD8-A784-A33040B39FD5}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно