comparison Implab/Safe.cs @ 228:6fa235c5a760 v2

Rewritten JsonScanner, JsonParser, fixed naming style
author cin
date Tue, 12 Sep 2017 01:19:12 +0300
parents 8808383fcb94
children bdfdba6b645b
comparison
equal deleted inserted replaced
227:8d5de4eb9c2c 228:6fa235c5a760
3 using System.Linq; 3 using System.Linq;
4 using System.Text; 4 using System.Text;
5 using System.Text.RegularExpressions; 5 using System.Text.RegularExpressions;
6 using System.Diagnostics; 6 using System.Diagnostics;
7 using System.Collections; 7 using System.Collections;
8 using System.Runtime.CompilerServices;
8 9
9 #if NET_4_5 10 #if NET_4_5
10 using System.Threading.Tasks; 11 using System.Threading.Tasks;
11 #endif 12 #endif
12 13
13 namespace Implab 14 namespace Implab
14 { 15 {
15 public static class Safe 16 public static class Safe
16 { 17 {
18 [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 public static void ArgumentAssert(bool condition, string paramName) { 19 public static void ArgumentAssert(bool condition, string paramName) {
18 if (!condition) 20 if (!condition)
19 throw new ArgumentException("The parameter is invalid", paramName); 21 throw new ArgumentException("The parameter is invalid", paramName);
20 } 22 }
21 23
24 [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 public static void ArgumentMatch(string value, string paramName, Regex rx) { 25 public static void ArgumentMatch(string value, string paramName, Regex rx) {
23 if (rx == null) 26 if (rx == null)
24 throw new ArgumentNullException("rx"); 27 throw new ArgumentNullException("rx");
25 if (!rx.IsMatch(value)) 28 if (!rx.IsMatch(value))
26 throw new ArgumentException(String.Format("The prameter value must match {0}", rx), paramName); 29 throw new ArgumentException(String.Format("The prameter value must match {0}", rx), paramName);
27 } 30 }
28 31
32 [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 public static void ArgumentNotEmpty(string value, string paramName) { 33 public static void ArgumentNotEmpty(string value, string paramName) {
30 if (String.IsNullOrEmpty(value)) 34 if (String.IsNullOrEmpty(value))
31 throw new ArgumentException("The parameter can't be empty", paramName); 35 throw new ArgumentException("The parameter can't be empty", paramName);
32 } 36 }
33 37
38 [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 public static void ArgumentNotEmpty<T>(T[] value, string paramName) { 39 public static void ArgumentNotEmpty<T>(T[] value, string paramName) {
35 if (value == null || value.Length == 0) 40 if (value == null || value.Length == 0)
36 throw new ArgumentException("The array must be not emty", paramName); 41 throw new ArgumentException("The array must be not emty", paramName);
37 } 42 }
38 43
44 [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 public static void ArgumentNotNull(object value, string paramName) { 45 public static void ArgumentNotNull(object value, string paramName) {
40 if (value == null) 46 if (value == null)
41 throw new ArgumentNullException(paramName); 47 throw new ArgumentNullException(paramName);
42 } 48 }
43 49
50 [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 internal static void ArgumentGreaterThan(int value, int min, string paramName) {
52 if (value < min)
53 throw new ArgumentOutOfRangeException(paramName);
54 }
55
56 [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 public static void ArgumentInRange(int value, int min, int max, string paramName) { 57 public static void ArgumentInRange(int value, int min, int max, string paramName) {
45 if (value < min || value > max) 58 if (value < min || value > max)
46 throw new ArgumentOutOfRangeException(paramName); 59 throw new ArgumentOutOfRangeException(paramName);
47 } 60 }
48 61
62 [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 public static void ArgumentOfType(object value, Type type, string paramName) { 63 public static void ArgumentOfType(object value, Type type, string paramName) {
50 if (!type.IsInstanceOfType(value)) 64 if (!type.IsInstanceOfType(value))
51 throw new ArgumentException(String.Format("The parameter must be of type {0}", type), paramName); 65 throw new ArgumentException(String.Format("The parameter must be of type {0}", type), paramName);
52 } 66 }
53 67