-
Notifications
You must be signed in to change notification settings - Fork 133
/
WpfObject.cs
103 lines (92 loc) · 3.27 KB
/
WpfObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows;
namespace SharpVectors.Renderers
{
public abstract class WpfObject : DependencyObject
{
protected WpfObject()
{
}
#region Exception Utilities
public static void NotNull(object argObject, string argName)
{
if (argObject == null)
{
throw new ArgumentNullException(argName, String.Format(
"The parameter '{0}' is required, and cannot be null (or Nothing).", argName));
}
}
public static void NotNull(string argObject, string argName)
{
if (argObject == null)
{
throw new ArgumentNullException(argName, String.Format(
"The parameter '{0}' is required, and cannot be null (or Nothing).", argName));
}
}
public static void NotEmpty(string argObject, string argName)
{
if (String.IsNullOrEmpty(argObject))
{
throw new ArgumentException(String.Format(
"The parameter '{0}' is required, and cannot be empty.", argName), argName);
}
}
public static void NotNullNotEmpty(string argObject, string argName)
{
if (argObject == null)
{
throw new ArgumentNullException(argName, String.Format(
"The parameter '{0}' is required, and cannot be null (or Nothing).", argName));
}
if (argObject.Length == 0)
{
throw new ArgumentException(String.Format(
"The parameter '{0}' is required, and cannot be empty.", argName), argName);
}
}
public static void NotNullNotEmpty<E>(IList<E> argObject, string argName)
{
if (argObject == null)
{
throw new ArgumentNullException(argName, String.Format(
"The parameter '{0}' is required, and cannot be null (or Nothing).", argName));
}
if (argObject.Count == 0)
{
throw new ArgumentException(String.Format(
"The parameter '{0}' is required, and cannot be empty.", argName), argName);
}
}
public static void PathMustExist(string argObject, string argName)
{
if (argObject == null)
{
throw new ArgumentNullException(argName,
String.Format("The path '{0}' cannot be null (or Nothing).",
argName));
}
if (argObject.Length == 0)
{
throw new ArgumentException("The path is not valid.", argName);
}
if (Path.HasExtension(argObject))
{
if (File.Exists(argObject) == false)
{
throw new ArgumentException("The file path must exists.", argName);
}
}
else
{
if (Directory.Exists(argObject) == false)
{
throw new ArgumentException("The directory path must exists.", argName);
}
}
}
#endregion
}
}