예제 #1
0
 private CustomMethodInfo GetMethodFromPath()
 {
     var info = new CustomMethodInfo();
     try
     {
         info.Assembly = Assembly.Load(_pathInfo.Assembly);
         var type = info.Assembly.GetType(_pathInfo.TypeName, true, true);
         info.Instance = Activator.CreateInstance(type);
         info.Method = type.GetMethod(_pathInfo.MethodName, Flags);
         info.Count = 1;
         info.AttrList = ReflectionHelper.GetAttributes<AttrBase>(info.Method);
         info.ReturnType = info.Method.ReturnType;
         info.ParamterInfos = info.Method.GetParameters();
         info.LastUpdateTime = DateTime.Now;
     }
     catch
     {
         info = null;
     }
     return info;
 }
예제 #2
0
 /// <summary>
 /// 执行方法
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public object ExecutinonMethod(CustomMethodInfo info)
 {
     try
     {
         object obj = null;
         if (info.ParamterInfos.Length == 0)
         {
             obj = info.Method.Invoke(info.Instance, null);
         }
         else
         {
             var args = new object[info.ParamterInfos.Length];
             for (int i = 0; i < info.ParamterInfos.Length; i++)
             {
                 var para = info.ParamterInfos[i];
                 var val = _request.WebParameters[para.Name];
                 args[i] = ReflectionHelper.ChangeType(val, para.ParameterType);
             }
             obj = info.Method.Invoke(info.Instance, args);
         }
         return obj;
     }
     catch(Exception ex)
     {
         return new AjaxResult {state = 0, msg = ex.Message};
     }
 }