-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
60 lines (54 loc) · 1.85 KB
/
Utils.cs
File metadata and controls
60 lines (54 loc) · 1.85 KB
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
using System;
using System.Collections.Generic;
using System.Reflection;
namespace CShargs
{
internal static class ThrowIf
{
public static void ArgumentNull(string paramName, object param, string message = null)
{
if (param == null) {
if (message != null) {
throw new ArgumentNullException(paramName, message);
} else {
throw new ArgumentNullException(paramName);
}
}
}
internal static void InState(bool condition, string message = null)
{
if (condition) {
throw new InvalidOperationException(message);
}
}
internal static void ArgumentValue(bool condition, string message = null)
{
if (condition) {
throw new ArgumentException(message);
}
}
}
internal static class OperatorsEx
{
public static bool In<T, TElem>(this T obj, ICollection<TElem> collection) where T : TElem
{
return collection.Contains(obj);
}
}
internal static class ReflectionEx
{
public static Type GetOwnType(this MemberInfo member)
{
switch (member.MemberType) {
case MemberTypes.Constructor: return member.DeclaringType;
case MemberTypes.Field: return ((FieldInfo)member).FieldType;
case MemberTypes.Method: return ((MethodInfo)member).ReturnType;
case MemberTypes.Property: return ((PropertyInfo)member).PropertyType;
case MemberTypes.Event: return ((EventInfo)member).EventHandlerType;
case MemberTypes.TypeInfo: return ((TypeInfo)member).AsType();
default:
throw new NotImplementedException();
}
}
}
}