1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Reflection;
|
21
|
|
using System.Text;
|
22
|
|
using Seasar.Framework.Exceptions;
|
23
|
|
|
24
|
|
namespace Seasar.Framework.Util
|
25
|
|
{
|
26
|
|
public sealed class MethodUtil
|
27
|
|
{
|
28
|
0
|
private MethodUtil()
|
29
|
|
{
|
30
|
|
}
|
31
|
|
|
32
|
50
|
public static object Invoke(MethodInfo method,object target,object[] args)
|
33
|
|
{
|
34
|
50
|
try
|
35
|
|
{
|
36
|
50
|
return method.Invoke(target,args);
|
37
|
|
}
|
38
|
|
catch(TargetInvocationException ex)
|
39
|
|
{
|
40
|
0
|
throw new InvocationTargetRuntimeException(method.DeclaringType,ex);
|
41
|
|
}
|
42
|
|
catch(TargetException ex)
|
43
|
|
{
|
44
|
0
|
throw new IllegalAccessRuntimeException(method.DeclaringType,ex);
|
45
|
|
}
|
46
|
|
catch(ArgumentException ex)
|
47
|
|
{
|
48
|
0
|
throw new IllegalAccessRuntimeException(method.DeclaringType,ex);
|
49
|
|
}
|
50
|
|
catch(TargetParameterCountException ex)
|
51
|
|
{
|
52
|
0
|
throw new IllegalAccessRuntimeException(method.DeclaringType,ex);
|
53
|
|
}
|
54
|
|
catch(MethodAccessException ex)
|
55
|
|
{
|
56
|
0
|
throw new IllegalAccessRuntimeException(method.DeclaringType,ex);
|
57
|
|
}
|
58
|
|
}
|
59
|
|
|
60
|
2
|
public static string GetSignature(string methodName,Type[] argTypes)
|
61
|
|
{
|
62
|
2
|
StringBuilder buf = new StringBuilder(100);
|
63
|
2
|
buf.Append(methodName);
|
64
|
2
|
buf.Append("(");
|
65
|
2
|
if(argTypes != null)
|
66
|
|
{
|
67
|
1
|
for(int i = 0; i < argTypes.Length; ++i)
|
68
|
|
{
|
69
|
0
|
if(i > 0) buf.Append(", ");
|
70
|
0
|
buf.Append(argTypes[i].FullName);
|
71
|
|
}
|
72
|
|
}
|
73
|
2
|
buf.Append(")");
|
74
|
2
|
return buf.ToString();
|
75
|
|
}
|
76
|
|
|
77
|
|
|
78
|
3
|
public static string GetSignature(string methodName,object[] methodArgs)
|
79
|
|
{
|
80
|
3
|
StringBuilder buf = new StringBuilder(100);
|
81
|
3
|
buf.Append(methodName);
|
82
|
3
|
buf.Append("(");
|
83
|
3
|
if(methodArgs != null)
|
84
|
|
{
|
85
|
4
|
for(int i = 0; i < methodArgs.Length; ++i)
|
86
|
|
{
|
87
|
0
|
if(i > 0) buf.Append(", ");
|
88
|
1
|
if(methodArgs[i] != null)
|
89
|
|
{
|
90
|
1
|
buf.Append(methodArgs[i].GetType().FullName);
|
91
|
|
}
|
92
|
|
else
|
93
|
|
{
|
94
|
0
|
buf.Append("null");
|
95
|
|
}
|
96
|
|
}
|
97
|
|
}
|
98
|
3
|
buf.Append(")");
|
99
|
3
|
return buf.ToString();
|
100
|
|
}
|
101
|
|
|
102
|
0
|
public static string[] GetParameterNames(MethodInfo mi)
|
103
|
|
{
|
104
|
|
ParameterInfo[] parameters = mi.GetParameters();
|
105
|
|
string[] argNames = new string[parameters.Length];
|
106
|
|
for(int i = 0; i < parameters.Length; ++i)
|
107
|
|
{
|
108
|
|
argNames[i] = parameters[i].Name;
|
109
|
|
}
|
110
|
|
return argNames;
|
111
|
|
}
|
112
|
|
|
113
|
0
|
public static Type[] GetParameterTypes(MethodInfo mi)
|
114
|
|
{
|
115
|
|
ParameterInfo[] parameters = mi.GetParameters();
|
116
|
|
Type[] argTypes = new Type[parameters.Length];
|
117
|
|
for(int i = 0; i < parameters.Length; ++i)
|
118
|
|
{
|
119
|
|
argTypes[i] = parameters[i].ParameterType;
|
120
|
|
}
|
121
|
|
return argTypes;
|
122
|
|
}
|
123
|
|
}
|
124
|
|
}
|
125
|
|
|