1
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Linq;
|
|
4 using System.Text;
|
51
|
5 using System.Text.RegularExpressions;
|
1
|
6
|
|
7 namespace Implab
|
|
8 {
|
|
9 public static class Safe
|
|
10 {
|
51
|
11 public static void ArgumentMatch(string param, string name, Regex rx) {
|
|
12 if (rx == null)
|
|
13 throw new ArgumentNullException("rx");
|
|
14 if (!rx.IsMatch(param))
|
|
15 throw new ArgumentException(String.Format("A prameter value must match {0}", rx), name);
|
|
16 }
|
|
17
|
|
18 public static void ArgumentNotEmpty(string param, string name) {
|
|
19 if (String.IsNullOrEmpty(param))
|
|
20 throw new ArgumentException("A parameter can't be empty", name);
|
|
21 }
|
|
22
|
|
23 public static void ArgumentNotNull(object param, string name) {
|
|
24 if (param == null)
|
|
25 throw new ArgumentNullException(name);
|
|
26 }
|
|
27
|
31
|
28 public static void Dispose<T>(T obj) where T : class
|
1
|
29 {
|
2
|
30 var disp = obj as IDisposable;
|
|
31 if (disp != null)
|
|
32 disp.Dispose();
|
1
|
33 }
|
|
34 }
|
|
35 }
|