Sfoglia il codice sorgente

Add T4 for patterns.

Bart De Smet 5 anni fa
parent
commit
6171954b40

+ 2 - 18
Rx.NET/Source/src/System.Reactive/Joins/Pattern.Generated.cs

@@ -4,9 +4,9 @@
 
 namespace System.Reactive.Joins
 {
-    /* The following code is generated by a tool checked in to $/.../Source/Tools/CodeGenerators. */
+    /* The following code is generated by a T4 template. */
 
-    #region Joins auto-generated code (8/4/2012 1:00:26 AM)
+    #region Joins auto-generated code (09/25/2020 12:58:51)
 
     /// <summary>
     /// Represents a join pattern over one observable sequence.
@@ -37,7 +37,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -89,7 +88,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -144,7 +142,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -202,7 +199,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -263,7 +259,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -327,7 +322,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -394,7 +388,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -464,7 +457,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -537,7 +529,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -613,7 +604,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TSource10, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -692,7 +682,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TSource10, TSource11, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -774,7 +763,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TSource10, TSource11, TSource12, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -859,7 +847,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TSource10, TSource11, TSource12, TSource13, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -947,7 +934,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TSource10, TSource11, TSource12, TSource13, TSource14, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -1038,7 +1024,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TSource10, TSource11, TSource12, TSource13, TSource14, TSource15, TResult>(this, selector);
         }
-
     }
 
     /// <summary>
@@ -1115,7 +1100,6 @@ namespace System.Reactive.Joins
 
             return new Plan<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7, TSource8, TSource9, TSource10, TSource11, TSource12, TSource13, TSource14, TSource15, TSource16, TResult>(this, selector);
         }
-
     }
 
     #endregion

+ 110 - 0
Rx.NET/Source/src/System.Reactive/Joins/Pattern.tt

@@ -0,0 +1,110 @@
+// 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" #>
+namespace System.Reactive.Joins
+{
+    /* The following code is generated by a T4 template. */
+
+    #region Joins auto-generated code (<#=DateTime.Now#>)
+
+<#
+Func<string, string> 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 = 1; i <= 16; i++)
+{
+    var parameters = string.Join(", ", Enumerable.Range(1, i).Select(j => "IObservable<TSource" + j + "> " + 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])));
+
+#>
+    /// <summary>
+    /// Represents a join pattern over <#=counts[i - 1]#> observable sequence<#=i != 1 ? "s" : ""#>.
+    /// </summary>
+<#
+for (int j = 0; j < i; j++)
+{
+#>
+    /// <typeparam name="TSource<#=j + 1#>">The type of the elements in the <#=ordinals[j]#> source sequence.</typeparam>
+<#
+}
+#>
+    public class Pattern<<#=genArgs#>> : Pattern
+    {
+        internal Pattern(<#=parameters#>)
+        {
+<#
+for (int j = 0; j < i; j++)
+{
+#>
+            <#=toUpper(ordinals[j])#> = <#=ordinals[j]#>;
+<#
+}
+#>
+        }
+
+<#
+for (int j = 0; j < i; j++)
+{
+#>
+        internal IObservable<TSource<#=j + 1#>> <#=toUpper(ordinals[j])#> { get; }
+<#
+}
+#>
+
+<#
+if (i > 1 && i != 16)
+{
+#>
+        /// <summary>
+        /// Creates a pattern that matches when all <#=counts[i]#> observable sequences have an available element.
+        /// </summary>
+        /// <typeparam name="TSource<#=i+1#>">The type of the elements in the <#=ordinals[i]#> observable sequence.</typeparam>
+        /// <param name="other">Observable sequence to match with the <#=counts[i - 1]#> previous sequences.</param>
+        /// <returns>Pattern object that matches when all observable sequences have an available element.</returns>
+        /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
+        public Pattern<<#=genArgs#>, TSource<#=i+1#>> And<TSource<#=i+1#>>(IObservable<TSource<#=i+1#>> other)
+        {
+            if (other == null)
+            {
+                throw new ArgumentNullException(nameof(other));
+            }
+
+            return new Pattern<<#=genArgs#>, TSource<#=i+1#>>(<#=sources#>, other);
+        }
+
+<#
+}
+#>
+        /// <summary>
+        /// Matches when all observable sequences have an available element and projects the elements by invoking the selector function.
+        /// </summary>
+        /// <typeparam name="TResult">The type of the elements in the result sequence, returned by the selector function.</typeparam>
+        /// <param name="selector">Selector that will be invoked for elements in the source sequences.</param>
+        /// <returns>Plan that produces the projected results, to be fed (with other plans) to the When operator.</returns>
+        /// <exception cref="ArgumentNullException"><paramref name="selector"/> is null.</exception>
+        public Plan<TResult> Then<TResult>(Func<<#=genArgs#>, TResult> selector)
+        {
+            if (selector == null)
+            {
+                throw new ArgumentNullException(nameof(selector));
+            }
+
+            return new Plan<<#=genArgs#>, TResult>(this, selector);
+        }
+    }
+
+<#
+}
+#>
+    #endregion
+}

+ 2 - 46
Rx.NET/Source/src/System.Reactive/Joins/QueryablePattern.Generated.cs

@@ -7,9 +7,9 @@ using System.Reactive.Linq;
 
 namespace System.Reactive.Joins
 {
-    /* The following code is generated by a tool checked in to $/.../Source/Tools/CodeGenerators. */
+    /* The following code is generated by a T4 template. */
 
-    #region Joins auto-generated code (8/4/2012 1:00:32 AM)
+    #region Joins auto-generated code (09/25/2020 13:10:21)
 
     /// <summary>
     /// Represents a join pattern over two observable sequences.
@@ -46,7 +46,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -72,9 +71,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -113,7 +110,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -139,9 +135,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -181,7 +175,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -207,9 +200,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -250,7 +241,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -276,9 +266,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -320,7 +308,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -346,9 +333,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -391,7 +376,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -417,9 +401,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -463,7 +445,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -489,9 +470,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -536,7 +515,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -562,9 +540,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -610,7 +586,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -636,9 +611,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -685,7 +658,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -711,9 +683,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -761,7 +731,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -787,9 +756,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -838,7 +805,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -864,9 +830,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -916,7 +880,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -942,9 +905,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -995,7 +956,6 @@ namespace System.Reactive.Joins
                     Qbservable.GetSourceExpression(other)
                 )
             );
-
         }
 
         /// <summary>
@@ -1021,9 +981,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     /// <summary>
@@ -1075,9 +1033,7 @@ namespace System.Reactive.Joins
                     selector
                 )
             );
-
         }
-
     }
 
     #endregion

+ 113 - 0
Rx.NET/Source/src/System.Reactive/Joins/QueryablePattern.tt

@@ -0,0 +1,113 @@
+// 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<string, string> 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<TSource" + j + "> " + 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])));
+
+#>
+    /// <summary>
+    /// Represents a join pattern over <#=counts[i - 1]#> observable sequence<#=i != 1 ? "s" : ""#>.
+    /// </summary>
+<#
+for (int j = 0; j < i; j++)
+{
+#>
+    /// <typeparam name="TSource<#=j + 1#>">The type of the elements in the <#=ordinals[j]#> source sequence.</typeparam>
+<#
+}
+#>
+    public class QueryablePattern<<#=genArgs#>> : QueryablePattern
+    {
+        internal QueryablePattern(Expression expression)
+            : base(expression)
+        {
+        }
+
+<#
+if (i > 1 && i != 16)
+{
+#>
+        /// <summary>
+        /// Creates a pattern that matches when all <#=counts[i]#> observable sequences have an available element.
+        /// </summary>
+        /// <typeparam name="TSource<#=i+1#>">The type of the elements in the <#=ordinals[i]#> observable sequence.</typeparam>
+        /// <param name="other">Observable sequence to match with the <#=counts[i - 1]#> previous sequences.</param>
+        /// <returns>Pattern object that matches when all observable sequences have an available element.</returns>
+        /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
+        public QueryablePattern<<#=genArgs#>, TSource<#=i+1#>> And<TSource<#=i+1#>>(IObservable<TSource<#=i+1#>> 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)
+                )
+            );
+        }
+
+<#
+}
+#>
+        /// <summary>
+        /// Matches when all observable sequences have an available element and projects the elements by invoking the selector function.
+        /// </summary>
+        /// <typeparam name="TResult">The type of the elements in the result sequence, returned by the selector function.</typeparam>
+        /// <param name="selector">Selector that will be invoked for elements in the source sequences.</param>
+        /// <returns>Plan that produces the projected results, to be fed (with other plans) to the When operator.</returns>
+        /// <exception cref="ArgumentNullException"><paramref name="selector"/> is null.</exception>
+        public QueryablePlan<TResult> Then<TResult>(Expression<Func<<#=genArgs#>, 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<TResult>(
+                Expression.Call(
+                    Expression,
+                    m,
+                    selector
+                )
+            );
+        }
+    }
+
+<#
+}
+#>
+    #endregion
+}

+ 18 - 0
Rx.NET/Source/src/System.Reactive/System.Reactive.csproj

@@ -63,6 +63,16 @@
 
   <!-- Designer support -->
   <ItemGroup>
+    <Compile Update="Joins\Pattern.Generated.cs">
+      <DesignTime>True</DesignTime>
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Pattern.tt</DependentUpon>
+    </Compile>
+    <Compile Update="Joins\QueryablePattern.Generated.cs">
+      <DesignTime>True</DesignTime>
+      <AutoGen>True</AutoGen>
+      <DependentUpon>QueryablePattern.tt</DependentUpon>
+    </Compile>
     <Compile Update="Linq\Observable\CombineLatest.Generated.cs">
       <DesignTime>True</DesignTime>
       <AutoGen>True</AutoGen>
@@ -94,6 +104,14 @@
       <DependentUpon>QueryLanguage.Multiple.Zip.tt</DependentUpon>
     </Compile>
 
+    <None Update="Joins\Pattern.tt">
+      <Generator>TextTemplatingFileGenerator</Generator>
+      <LastGenOutput>Pattern.Generated.cs</LastGenOutput>
+    </None>
+    <None Update="Joins\QueryablePattern.tt">
+      <Generator>TextTemplatingFileGenerator</Generator>
+      <LastGenOutput>QueryablePattern.Generated.cs</LastGenOutput>
+    </None>
     <None Update="Linq\Observable\CombineLatest.Generated.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
       <LastGenOutput>CombineLatest.Generated.cs</LastGenOutput>