comparison Implab/Safe.cs @ 51:2c332a9c64c0

Added methods for parameter checks
author cin
date Sat, 26 Apr 2014 23:36:00 +0400
parents dafaadca5b9f
children c0bf853aa04f
comparison
equal deleted inserted replaced
50:f8cbe84cfdb1 51:2c332a9c64c0
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Linq; 3 using System.Linq;
4 using System.Text; 4 using System.Text;
5 using System.Text.RegularExpressions;
5 6
6 namespace Implab 7 namespace Implab
7 { 8 {
8 public static class Safe 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 public static void Dispose<T>(T obj) where T : class 28 public static void Dispose<T>(T obj) where T : class
11 { 29 {
12 var disp = obj as IDisposable; 30 var disp = obj as IDisposable;
13 if (disp != null) 31 if (disp != null)
14 disp.Dispose(); 32 disp.Dispose();