<#@ template debug="false" hostspecific="false" language="C#" #> <#@ assembly name="System.Core" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.Collections.Generic" #> <#@ output extension=".cs" #> // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #if !NO_PERF using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Reactive.Disposables; namespace System.Reactive.Linq.ObservableImpl { #region [3,16]-ary /* The following code is generated by a T4 template. */ #region CombineLatest auto-generated code (<#=DateTime.Now.ToString()#>) <# for (var i = 3; i <= 16; i++) { var ts = string.Join(", ", Enumerable.Range(1, i).Select(j => "T" + j)); var os = string.Join(", ", Enumerable.Range(1, i).Select(j => "IObservable source" + j)); var vs = string.Join(", ", Enumerable.Range(1, i).Select(j => "_observer" + j + ".Value")); if (i == 5) { #> #if !NO_LARGEARITY <# } #> class CombineLatest<<#=ts#>, TResult> : Producer { <# for (var j = 1; j <= i; j++) { #> private readonly IObservable> _source<#=j#>; <# } #> private readonly Func<<#=ts#>, TResult> _resultSelector; public CombineLatest(<#=os#>, Func<<#=ts#>, TResult> resultSelector) { <# for (var j = 1; j <= i; j++) { #> _source<#=j#> = source<#=j#>; <# } #> _resultSelector = resultSelector; } protected override IDisposable Run(IObserver observer, IDisposable cancel, Action setSink) { var sink = new _(this, observer, cancel); setSink(sink); return sink.Run(); } class _ : CombineLatestSink { private readonly CombineLatest<<#=ts#>, TResult> _parent; public _(CombineLatest<<#=ts#>, TResult> parent, IObserver observer, IDisposable cancel) : base(<#=i#>, observer, cancel) { _parent = parent; } <# for (var j = 1; j <= i; j++) { #> private CombineLatestObserver> _observer<#=j#>; <# } #> public IDisposable Run() { var subscriptions = new SingleAssignmentDisposable[<#=i#>]; for (int i = 0; i < <#=i#>; i++) subscriptions[i] = new SingleAssignmentDisposable(); <# for (var j = 1; j <= i; j++) { #> _observer<#=j#> = new CombineLatestObserver>(_gate, this, <#=j - 1#>, subscriptions[<#=j - 1#>]); <# } #> <# for (var j = 1; j <= i; j++) { #> subscriptions[<#=j - 1#>].Disposable = _parent._source<#=j#>.SubscribeSafe(_observer<#=j#>); <# } #> return StableCompositeDisposable.Create(subscriptions); } protected override TResult GetResult() { return _parent._resultSelector(<#=vs#>); } } } <# } #> #endif #endregion #endregion } #endif