##// END OF EJS Templates
Added Signal class a lightweight alternative to ManualResetEvent
Added Signal class a lightweight alternative to ManualResetEvent

File last commit:

r128:6241bff0cd64 v2
r128:6241bff0cd64 v2
Show More
Safe.cs
99 lines | 3.1 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
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");
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 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 }
}