/
ReflectorExtensions.cs
100 lines (84 loc) · 3.13 KB
/
ReflectorExtensions.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
using System;
using System.Reflection;
namespace AspectCore.Extensions.Reflection
{
public static class ReflectorExtensions
{
#region Reflection
public static TypeReflector GetReflector(this Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
return TypeReflector.Create(type.GetTypeInfo());
}
public static TypeReflector GetReflector(this TypeInfo typeInfo)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
return TypeReflector.Create(typeInfo);
}
public static ConstructorReflector GetReflector(this ConstructorInfo constructor)
{
if (constructor == null)
{
throw new ArgumentNullException(nameof(constructor));
}
return ConstructorReflector.Create(constructor);
}
public static FieldReflector GetReflector(this FieldInfo field)
{
if (field == null)
{
throw new ArgumentNullException(nameof(field));
}
return FieldReflector.Create(field);
}
public static MethodReflector GetReflector(this MethodInfo method)
{
return GetReflector(method, CallOptions.Callvirt);
}
public static MethodReflector GetReflector(this MethodInfo method, CallOptions callOption)
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}
return MethodReflector.Create(method, callOption);
}
public static PropertyReflector GetReflector(this PropertyInfo property)
{
if (property == null)
{
throw new ArgumentNullException(nameof(property));
}
return GetReflector(property, CallOptions.Callvirt);
}
public static PropertyReflector GetReflector(this PropertyInfo property, CallOptions callOption)
{
if (property == null)
{
throw new ArgumentNullException(nameof(property));
}
return PropertyReflector.Create(property, callOption);
}
public static ParameterReflector GetReflector(this ParameterInfo parameterInfo)
{
if (parameterInfo == null)
{
throw new ArgumentNullException(nameof(parameterInfo));
}
return ParameterReflector.Create(parameterInfo);
}
#endregion
#region Reflectr
public static FieldInfo GetFieldInfo(this FieldReflector reflector) => reflector?.GetMemberInfo();
public static MethodInfo GetMethodInfo(this MethodReflector reflector) => reflector?.GetMemberInfo();
public static ConstructorInfo GetConstructorInfo(this ConstructorReflector reflector) => reflector?.GetMemberInfo();
public static PropertyInfo GetPropertyInfo(this PropertyReflector reflector) => reflector?.GetMemberInfo();
#endregion
}
}