11using System.Reflection;
15 internal class DynamicMethodHandle
17 public string MethodName {
get;
private set; }
19 public bool HasFinalArrayParam {
get;
private set; }
20 public int MethodParamsLength {
get;
private set; }
21 public Type FinalArrayElementType {
get;
private set; }
22 public bool IsAsyncTask {
get;
private set; }
23 public bool IsAsyncTaskObject {
get;
private set; }
25 public DynamicMethodHandle(System.Reflection.MethodInfo info, params
object[] parameters)
29 this.DynamicMethod =
null;
33 this.MethodName = info.Name;
34 var infoParams = info.GetParameters();
35 object[] inParams =
null;
36 if (parameters ==
null)
38 inParams =
new object[] {
null };
43 inParams = parameters;
45 var pCount = infoParams.Length;
47 var isgeneric = info.ReturnType.IsGenericType();
49 ((pCount == 1 && infoParams[0].ParameterType.IsArray) ||
50 (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute),
true).Count() > 0)))
52 var isgeneric = info.ReturnType.IsGenericType;
54 ((pCount == 1 && infoParams[0].ParameterType.IsArray) ||
55 (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute),
true).Length > 0)))
58 this.HasFinalArrayParam =
true;
59 this.MethodParamsLength = pCount;
60 this.FinalArrayElementType = infoParams[pCount - 1].ParameterType;
62 IsAsyncTask = (info.ReturnType == typeof(System.Threading.Tasks.Task));
63 IsAsyncTaskObject = (isgeneric && (info.ReturnType.GetGenericTypeDefinition() == typeof(System.Threading.Tasks.Task<>)));
64 this.DynamicMethod = DynamicMethodHandlerFactory.CreateMethod(info);
delegate object DynamicMethodDelegate(object target, object[] args)
Delegate for a dynamic method.