Sum.Generated.tt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. <#@ template debug="false" hostspecific="false" language="C#" #>
  5. <#@ assembly name="System.Core" #>
  6. <#@ import namespace="System.Linq" #>
  7. <#@ import namespace="System.Text" #>
  8. <#@ import namespace="System.Collections.Generic" #>
  9. <#@ output extension=".cs" #>
  10. <#
  11. var types = new[] { typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) };
  12. var name = "Sum";
  13. #>
  14. using System.Threading.Tasks;
  15. namespace System.Reactive.Linq
  16. {
  17. partial class AsyncObservable
  18. {
  19. <#
  20. foreach (var t in types)
  21. {
  22. foreach (var n in new[] { false, true })
  23. {
  24. var typeName = n ? t.Name + "?" : t.Name;
  25. var methodName = n ? "Nullable" + t.Name : t.Name;
  26. #>
  27. public static IAsyncObservable<<#=typeName#>> <#=name#>(this IAsyncObservable<<#=typeName#>> source)
  28. {
  29. if (source == null)
  30. throw new ArgumentNullException(nameof(source));
  31. return Create<<#=typeName#>>(observer => source.SubscribeSafeAsync(AsyncObserver.<#=name#><#=methodName#>(observer)));
  32. }
  33. public static IAsyncObservable<<#=typeName#>> <#=name#><TSource>(this IAsyncObservable<TSource> source, Func<TSource, <#=typeName#>> selector)
  34. {
  35. if (source == null)
  36. throw new ArgumentNullException(nameof(source));
  37. if (selector == null)
  38. throw new ArgumentNullException(nameof(selector));
  39. return Create<<#=typeName#>>(observer => source.SubscribeSafeAsync(AsyncObserver.<#=name#><#=methodName#>(observer, selector)));
  40. }
  41. public static IAsyncObservable<<#=typeName#>> <#=name#><TSource>(this IAsyncObservable<TSource> source, Func<TSource, Task<<#=typeName#>>> selector)
  42. {
  43. if (source == null)
  44. throw new ArgumentNullException(nameof(source));
  45. if (selector == null)
  46. throw new ArgumentNullException(nameof(selector));
  47. return Create<<#=typeName#>>(observer => source.SubscribeSafeAsync(AsyncObserver.<#=name#><#=methodName#>(observer, selector)));
  48. }
  49. <#
  50. }
  51. }
  52. #>
  53. }
  54. partial class AsyncObserver
  55. {
  56. <#
  57. foreach (var t in types)
  58. {
  59. foreach (var n in new[] { false, true })
  60. {
  61. var typeName = n ? t.Name + "?" : t.Name;
  62. var methodName = n ? "Nullable" + t.Name : t.Name;
  63. #>
  64. public static IAsyncObserver<TSource> <#=name#><#=methodName#><TSource>(IAsyncObserver<<#=typeName#>> observer, Func<TSource, <#=typeName#>> selector)
  65. {
  66. if (observer == null)
  67. throw new ArgumentNullException(nameof(observer));
  68. if (selector == null)
  69. throw new ArgumentNullException(nameof(selector));
  70. return Select(<#=name#><#=methodName#>(observer), selector);
  71. }
  72. public static IAsyncObserver<TSource> <#=name#><#=methodName#><TSource>(IAsyncObserver<<#=typeName#>> observer, Func<TSource, Task<<#=typeName#>>> selector)
  73. {
  74. if (observer == null)
  75. throw new ArgumentNullException(nameof(observer));
  76. if (selector == null)
  77. throw new ArgumentNullException(nameof(selector));
  78. return Select(<#=name#><#=methodName#>(observer), selector);
  79. }
  80. <#
  81. }
  82. }
  83. #>
  84. }
  85. }