Mercurial > pub > ImplabNet
comparison Implab/Safe.cs @ 207:558f34b2fb50 v2
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
added Safe.Dispose(IEnumerable)
added PromiseExtensions.CancellationPoint to add a cancellation point to the chain of promises
added IPromise<T> PromiseExtensions.Then<T>(this IPromise<T> that, Action<T> success) overloads
added PromiseExtensions.Error() overloads to handle a error or(and) a cancellation
author | cin |
---|---|
date | Wed, 09 Nov 2016 12:03:22 +0300 |
parents | 8200ab154c8a |
children | a867536c68fc |
comparison
equal
deleted
inserted
replaced
206:86b61d53b7db | 207:558f34b2fb50 |
---|---|
2 using System.Collections.Generic; | 2 using System.Collections.Generic; |
3 using System.Linq; | 3 using System.Linq; |
4 using System.Text; | 4 using System.Text; |
5 using System.Text.RegularExpressions; | 5 using System.Text.RegularExpressions; |
6 using System.Diagnostics; | 6 using System.Diagnostics; |
7 using System.Collections; | |
7 | 8 |
8 namespace Implab | 9 namespace Implab |
9 { | 10 { |
10 public static class Safe | 11 public static class Safe |
11 { | 12 { |
58 if (d != null) | 59 if (d != null) |
59 d.Dispose(); | 60 d.Dispose(); |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
64 public static void Dispose(IEnumerable<IDisposable> objects) { | |
65 foreach (var d in objects) | |
66 if (d != null) | |
67 d.Dispose(); | |
68 } | |
69 | |
63 public static void Dispose(object obj) { | 70 public static void Dispose(object obj) { |
64 var d = obj as IDisposable; | 71 var d = obj as IDisposable; |
65 if (d != null) | 72 if (d != null) |
66 d.Dispose(); | 73 d.Dispose(); |
74 } | |
75 | |
76 public static void DispatchEvent<T>(this EventHandler<T> handler, object sender, T args) { | |
77 if (handler != null) | |
78 handler(sender, args); | |
79 } | |
80 | |
81 public static void DispatchEvent(this EventHandler handler, object sender, EventArgs args) { | |
82 if (handler != null) | |
83 handler(sender, args); | |
67 } | 84 } |
68 | 85 |
69 [DebuggerStepThrough] | 86 [DebuggerStepThrough] |
70 public static IPromise<T> Run<T>(Func<T> action) { | 87 public static IPromise<T> Run<T>(Func<T> action) { |
71 ArgumentNotNull(action, "action"); | 88 ArgumentNotNull(action, "action"); |