##// END OF EJS Templates
fixed Promise.Error handler
fixed Promise.Error handler

File last commit:

r96:daffa72a1cec v2
r112:38d6a4db35d7 v2
Show More
Safe.cs
86 lines | 2.7 KiB | text/x-csharp | CSharpLexer
cin
Added utility class for safe disposing methods....
r1 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
cin
Added methods for parameter checks
r51 using System.Text.RegularExpressions;
cin
Refactoring
r66 using System.Diagnostics;
cin
Added utility class for safe disposing methods....
r1
namespace Implab
{
public static class Safe
{
cin
Added methods for parameter checks
r51 public static void ArgumentMatch(string param, string name, Regex rx) {
if (rx == null)
throw new ArgumentNullException("rx");
if (!rx.IsMatch(param))
cin
code cleanup
r90 throw new ArgumentException(String.Format("The prameter value must match {0}", rx), name);
cin
Added methods for parameter checks
r51 }
public static void ArgumentNotEmpty(string param, string name) {
if (String.IsNullOrEmpty(param))
cin
code cleanup
r90 throw new ArgumentException("The parameter can't be empty", name);
}
public static void ArgumentNotEmpty<T>(T[] param, string name) {
if (param == null || param.Length == 0)
throw new ArgumentException("The array must be not emty");
cin
Added methods for parameter checks
r51 }
public static void ArgumentNotNull(object param, string name) {
if (param == null)
throw new ArgumentNullException(name);
}
cin
Added initial JSON support...
r55 public static void ArgumentInRange(int arg, int min, int max, string name) {
if (arg < min || arg > max)
throw new ArgumentOutOfRangeException(name);
}
cin
minor cleanup
r31 public static void Dispose<T>(T obj) where T : class
cin
Added utility class for safe disposing methods....
r1 {
cin
small fixes
r2 var disp = obj as IDisposable;
if (disp != null)
disp.Dispose();
cin
Added utility class for safe disposing methods....
r1 }
cin
Refactoring
r66
[DebuggerStepThrough]
cin
minor fixes
r94 public static IPromise<T> InvokePromise<T>(Func<T> action) {
cin
Refactoring
r66 ArgumentNotNull(action, "action");
var p = new Promise<T>();
try {
p.Resolve(action());
} catch (Exception err) {
p.Reject(err);
}
return p;
}
[DebuggerStepThrough]
cin
Added the chaining method to the non-generic IPromise
r96 public static IPromise InvokePromise(Action action) {
cin
minor changes
r95 ArgumentNotNull(action, "action");
var p = new Promise<object>();
try {
action();
p.Resolve();
} catch (Exception err) {
p.Reject(err);
}
return p;
}
[DebuggerStepThrough]
cin
minor fixes
r94 public static IPromise<T> InvokePromise<T>(Func<IPromise<T>> action) {
cin
Refactoring
r66 ArgumentNotNull(action, "action");
try {
cin
minor fixes
r94 return action() ?? Promise<T>.ExceptionToPromise(new Exception("The action returned null"));
cin
Refactoring
r66 } catch (Exception err) {
return Promise<T>.ExceptionToPromise(err);
}
}
cin
Added utility class for safe disposing methods....
r1 }
}