comparison Implab/Safe.cs @ 66:790e8a997d30

Refactoring
author cin
date Thu, 14 Aug 2014 18:08:09 +0400
parents c0bf853aa04f
children efcb076407a7
comparison
equal deleted inserted replaced
65:653c4e04968b 66:790e8a997d30
1 using System; 1 using System;
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 7
7 namespace Implab 8 namespace Implab
8 { 9 {
9 public static class Safe 10 public static class Safe
10 { 11 {
34 { 35 {
35 var disp = obj as IDisposable; 36 var disp = obj as IDisposable;
36 if (disp != null) 37 if (disp != null)
37 disp.Dispose(); 38 disp.Dispose();
38 } 39 }
40
41 [DebuggerStepThrough]
42 public static IPromise<T> GuargPromise<T>(Func<T> action) {
43 ArgumentNotNull(action, "action");
44
45 var p = new Promise<T>();
46 try {
47 p.Resolve(action());
48 } catch (Exception err) {
49 p.Reject(err);
50 }
51
52 return p;
53 }
54
55 [DebuggerStepThrough]
56 public static IPromise<T> GuardPromise<T>(Func<IPromise<T>> action) {
57 ArgumentNotNull(action, "action");
58
59 try {
60 return action();
61 } catch (Exception err) {
62 return Promise<T>.ExceptionToPromise(err);
63 }
64 }
39 } 65 }
40 } 66 }