PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/System.Reactive/System.Reactive.Linq/gen/gen-code.cs

https://github.com/gshackles/mono-reactive
C# | 88 lines | 83 code | 5 blank | 0 comment | 2 complexity | 1623507f38711a4fea218b09c23cf7d7 MD5 | raw file
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. public class CodeGen
  5. {
  6. public static void Main ()
  7. {
  8. Console.WriteLine (@"
  9. using System;
  10. using System.Linq;
  11. using System.Reactive;
  12. using System.Reactive.Concurrency;
  13. using System.Reactive.Subjects;
  14. namespace System.Reactive.Linq
  15. {
  16. public static partial class Observable
  17. {
  18. ");
  19. for (int i = 1; i <= 14; i++) {
  20. string s = String.Join (", ", (from t in Enumerable.Range (1, i) select "T" + t).ToArray ());
  21. string s2 = String.Join (", ", (from t in Enumerable.Range (1, i) select "t" + t).ToArray ());
  22. Console.WriteLine (@"
  23. public static Func<{0}, IObservable<Unit>> FromAsyncPattern<{0}> (Func<{0}, AsyncCallback, object, IAsyncResult> begin, Action<IAsyncResult> end)
  24. {{
  25. var sub = new Subject<Unit> ();
  26. return ({1}) => {{ begin ({1}, (res) => {{
  27. try {{
  28. end (res);
  29. sub.OnNext (Unit.Default);
  30. sub.OnCompleted ();
  31. }} catch (Exception ex) {{
  32. sub.OnError (ex);
  33. }}
  34. }}, sub); return sub; }};
  35. }}
  36. public static Func<{0}, IObservable<TResult>> FromAsyncPattern<{0}, TResult> (Func<{0}, AsyncCallback, Object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)
  37. {{
  38. var sub = new Subject<TResult> ();
  39. return ({1}) => {{ begin ({1}, (res) => {{
  40. try {{
  41. var result = end (res);
  42. sub.OnNext (result);
  43. sub.OnCompleted ();
  44. }} catch (Exception ex) {{
  45. sub.OnError (ex);
  46. }}
  47. }}, sub); return sub; }};
  48. }}
  49. ", s, s2);
  50. }
  51. for (int i = 2; i <= 16; i++) {
  52. string s = String.Join (", ", (from t in Enumerable.Range (1, i) select "T" + t).ToArray ());
  53. string s2 = String.Join (", ", (from t in Enumerable.Range (1, i) select "t" + t).ToArray ());
  54. Console.WriteLine (@"
  55. public static Func<{0}, IObservable<Unit>> ToAsync<{0}> (this Action<{0}> function)
  56. {{
  57. return ({1}) => Start (() => function ({1}));
  58. }}
  59. public static Func<{0}, IObservable<Unit>> ToAsync<{0}> (this Action<{0}> function, IScheduler scheduler)
  60. {{
  61. return ({1}) => Start (() => function ({1}), scheduler);
  62. }}
  63. public static Func<{0}, IObservable<TResult>> ToAsync<{0}, TResult> (this Func<{0}, TResult> function)
  64. {{
  65. return ({1}) => Start (() => function ({1}));
  66. }}
  67. public static Func<{0}, IObservable<TResult>> ToAsync<{0}, TResult> (this Func<{0}, TResult> function, IScheduler scheduler)
  68. {{
  69. return ({1}) => Start (() => function ({1}), scheduler);
  70. }}
  71. ", s, s2);
  72. }
  73. Console.WriteLine (@"
  74. }
  75. }
  76. ");
  77. }
  78. }