// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. // See the LICENSE file in the project root for more information. <#@ 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=".Generated.cs" #> using System.Linq.Expressions; using System.Reactive.Linq; namespace System.Reactive.Joins { /* The following code is generated by a T4 template. */ #region Joins auto-generated code (<#=DateTime.Now#>) <# Func toUpper = s => char.ToUpper(s[0]) + s.Substring(1); string[] counts = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen" }; string[] ordinals = new[] { "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth" }; for (int i = 2; i <= 16; i++) { var parameters = string.Join(", ", Enumerable.Range(1, i).Select(j => "IObservable " + ordinals[j - 1])); var genArgs = string.Join(", ", Enumerable.Range(1, i).Select(j => "TSource" + j)); var sources = string.Join(", ", Enumerable.Range(1, i).Select(j => toUpper(ordinals[j - 1]))); #> /// /// Represents a join pattern over <#=counts[i - 1]#> observable sequence<#=i != 1 ? "s" : ""#>. /// <# for (int j = 0; j < i; j++) { #> /// The type of the elements in the <#=ordinals[j]#> source sequence. <# } #> public class QueryablePattern<<#=genArgs#>> : QueryablePattern { internal QueryablePattern(Expression expression) : base(expression) { } <# if (i > 1 && i != 16) { #> /// /// Creates a pattern that matches when all <#=counts[i]#> observable sequences have an available element. /// /// The type of the elements in the <#=ordinals[i]#> observable sequence. /// Observable sequence to match with the <#=counts[i - 1]#> previous sequences. /// Pattern object that matches when all observable sequences have an available element. /// is null. public QueryablePattern<<#=genArgs#>, TSource<#=i+1#>> And>(IObservable> other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } var t = typeof(QueryablePattern<<#=genArgs#>>); var m = t.GetMethod(nameof(And)).MakeGenericMethod(typeof(TSource<#=i + 1#>)); return new QueryablePattern<<#=genArgs#>, TSource<#=i + 1#>>( Expression.Call( Expression, m, Qbservable.GetSourceExpression(other) ) ); } <# } #> /// /// Matches when all observable sequences have an available element and projects the elements by invoking the selector function. /// /// The type of the elements in the result sequence, returned by the selector function. /// Selector that will be invoked for elements in the source sequences. /// Plan that produces the projected results, to be fed (with other plans) to the When operator. /// is null. public QueryablePlan Then(Expression, TResult>> selector) { if (selector == null) { throw new ArgumentNullException(nameof(selector)); } var t = typeof(QueryablePattern<<#=genArgs#>>); var m = t.GetMethod(nameof(Then)).MakeGenericMethod(typeof(TResult)); return new QueryablePlan( Expression.Call( Expression, m, selector ) ); } } <# } #> #endregion }