// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 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#>(this IAsyncObservable source, Func> 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#>(this IAsyncObservable source, Func>> 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 <#=name#><#=methodName#>(IAsyncObserver<<#=typeName#>> observer, Func> 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 <#=name#><#=methodName#>(IAsyncObserver<<#=typeName#>> observer, Func>> selector) { if (observer == null) throw new ArgumentNullException(nameof(observer)); if (selector == null) throw new ArgumentNullException(nameof(selector)); return Select(<#=name#><#=methodName#>(observer), selector); } <# } } #> } }