123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- // 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=".cs" #>
- <#
- var types = new[] { typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) };
- var name = "Sum";
- #>
- using System.Threading.Tasks;
- namespace System.Reactive.Linq
- {
- partial class AsyncObservable
- {
- <#
- foreach (var t in types)
- {
- foreach (var n in new[] { false, true })
- {
- var typeName = n ? t.Name + "?" : t.Name;
- var methodName = n ? "Nullable" + t.Name : t.Name;
- #>
- public static IAsyncObservable<<#=typeName#>> <#=name#>(this IAsyncObservable<<#=typeName#>> source)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- return Create<<#=typeName#>>(observer => source.SubscribeSafeAsync(AsyncObserver.<#=name#><#=methodName#>(observer)));
- }
- public static IAsyncObservable<<#=typeName#>> <#=name#><TSource>(this IAsyncObservable<TSource> source, Func<TSource, <#=typeName#>> selector)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- if (selector == null)
- throw new ArgumentNullException(nameof(selector));
- return Create<<#=typeName#>>(observer => source.SubscribeSafeAsync(AsyncObserver.<#=name#><#=methodName#>(observer, selector)));
- }
- public static IAsyncObservable<<#=typeName#>> <#=name#><TSource>(this IAsyncObservable<TSource> source, Func<TSource, Task<<#=typeName#>>> selector)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- if (selector == null)
- throw new ArgumentNullException(nameof(selector));
- return Create<<#=typeName#>>(observer => source.SubscribeSafeAsync(AsyncObserver.<#=name#><#=methodName#>(observer, selector)));
- }
- <#
- }
- }
- #>
- }
- partial class AsyncObserver
- {
- <#
- foreach (var t in types)
- {
- foreach (var n in new[] { false, true })
- {
- var typeName = n ? t.Name + "?" : t.Name;
- var methodName = n ? "Nullable" + t.Name : t.Name;
- #>
- public static IAsyncObserver<TSource> <#=name#><#=methodName#><TSource>(IAsyncObserver<<#=typeName#>> observer, Func<TSource, <#=typeName#>> selector)
- {
- if (observer == null)
- throw new ArgumentNullException(nameof(observer));
- if (selector == null)
- throw new ArgumentNullException(nameof(selector));
- return Select(<#=name#><#=methodName#>(observer), selector);
- }
- public static IAsyncObserver<TSource> <#=name#><#=methodName#><TSource>(IAsyncObserver<<#=typeName#>> observer, Func<TSource, Task<<#=typeName#>>> selector)
- {
- if (observer == null)
- throw new ArgumentNullException(nameof(observer));
- if (selector == null)
- throw new ArgumentNullException(nameof(selector));
- return Select(<#=name#><#=methodName#>(observer), selector);
- }
- <#
- }
- }
- #>
- }
- }
|