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
|
55
|
28 public static void ArgumentInRange(int arg, int min, int max, string name) {
|
|
29 if (arg < min || arg > max)
|
|
30 throw new ArgumentOutOfRangeException(name);
|
|
31 }
|
|
32
|
31
|
33 public static void Dispose<T>(T obj) where T : class
|
1
|
34 {
|
2
|
35 var disp = obj as IDisposable;
|
|
36 if (disp != null)
|
|
37 disp.Dispose();
|
1
|
38 }
|
|
39 }
|
|
40 }
|