##// END OF EJS Templates
refactoring, code cleanup
refactoring, code cleanup

File last commit:

r145:706fccb85524 v2
r158:130781364799 v2
Show More
Safe.cs
118 lines | 3.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
working version of AsyncQueue and batch operations...
r121 public static void ArgumentMatch(string value, string paramName, Regex rx) {
cin
Added methods for parameter checks
r51 if (rx == null)
throw new ArgumentNullException("rx");
cin
working version of AsyncQueue and batch operations...
r121 if (!rx.IsMatch(value))
throw new ArgumentException(String.Format("The prameter value must match {0}", rx), paramName);
cin
Added methods for parameter checks
r51 }
cin
working version of AsyncQueue and batch operations...
r121 public static void ArgumentNotEmpty(string value, string paramName) {
if (String.IsNullOrEmpty(value))
throw new ArgumentException("The parameter can't be empty", paramName);
cin
code cleanup
r90 }
cin
working version of AsyncQueue and batch operations...
r121 public static void ArgumentNotEmpty<T>(T[] value, string paramName) {
if (value == null || value.Length == 0)
throw new ArgumentException("The array must be not emty", paramName);
cin
Added methods for parameter checks
r51 }
cin
working version of AsyncQueue and batch operations...
r121 public static void ArgumentNotNull(object value, string paramName) {
if (value == null)
throw new ArgumentNullException(paramName);
cin
Added methods for parameter checks
r51 }
cin
working version of AsyncQueue and batch operations...
r121 public static void ArgumentInRange(int value, int min, int max, string paramName) {
if (value < min || value > max)
throw new ArgumentOutOfRangeException(paramName);
cin
Added initial JSON support...
r55 }
cin
Added Signal class a lightweight alternative to ManualResetEvent
r128 public static void Dispose(params IDisposable[] objects) {
foreach (var d in objects)
cin
minor changes
r126 if (d != null)
d.Dispose();
cin
Added utility class for safe disposing methods....
r1 }
cin
Refactoring
r66
cin
Added Signal class a lightweight alternative to ManualResetEvent
r128 public static void Dispose(params object[] objects) {
foreach (var obj in objects) {
var d = obj as IDisposable;
if (d != null)
d.Dispose();
}
}
public static void Dispose(object obj) {
var d = obj as IDisposable;
if (d != null)
d.Dispose();
}
cin
Refactoring
r66 [DebuggerStepThrough]
cin
minor fixes
r132 public static IPromise<T> WrapPromise<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
minor fixes
r132 public static IPromise WrapPromise(Action action) {
cin
minor changes
r95 ArgumentNotNull(action, "action");
cin
Promises rewritten, added improved version of AsyncQueue
r119 var p = new Promise();
cin
minor changes
r95 try {
action();
p.Resolve();
} catch (Exception err) {
p.Reject(err);
}
return p;
}
[DebuggerStepThrough]
cin
minor changes
r131 public static IPromise InvokePromise(Func<IPromise> action) {
ArgumentNotNull(action, "action");
try {
cin
sync
r133 var p = action();
if (p == null) {
var d = new Promise();
d.Reject(new Exception("The action returned null"));
p = d;
}
return p;
cin
minor changes
r131 } catch (Exception err) {
cin
sync
r133 var p = new Promise();
cin
minor changes
r131 p.Reject(err);
cin
sync
r133 return p;
cin
minor changes
r131 }
}
[DebuggerStepThrough]
cin
minor fixes
r94 public static IPromise<T> InvokePromise<T>(Func<IPromise<T>> action) {
cin
Refactoring
r66 ArgumentNotNull(action, "action");
try {
cin
RC: cancellation support for promises + tests
r145 return action() ?? Promise<T>.FromException(new Exception("The action returned null"));
cin
Refactoring
r66 } catch (Exception err) {
cin
RC: cancellation support for promises + tests
r145 return Promise<T>.FromException(err);
cin
Refactoring
r66 }
}
cin
Added utility class for safe disposing methods....
r1 }
}