@@ -1,17 +1,35 | |||
|
1 | 1 | using System; |
|
2 | 2 | using System.Collections.Generic; |
|
3 | 3 | using System.Linq; |
|
4 | 4 | using System.Text; |
|
5 | using System.Text.RegularExpressions; | |
|
5 | 6 | |
|
6 | 7 | namespace Implab |
|
7 | 8 | { |
|
8 | 9 | public static class Safe |
|
9 | 10 | { |
|
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 | ||
|
10 | 28 | public static void Dispose<T>(T obj) where T : class |
|
11 | 29 | { |
|
12 | 30 | var disp = obj as IDisposable; |
|
13 | 31 | if (disp != null) |
|
14 | 32 | disp.Dispose(); |
|
15 | 33 | } |
|
16 | 34 | } |
|
17 | 35 | } |
General Comments 0
You need to be logged in to leave comments.
Login now