/// <summary>
/// 獲得方法的執行時間
/// </summary>
/// <param name="ClassType">類</param>
/// <param name="ClassParameters">構造函數用的參數</param>
/// <param name="MethodName">方法名稱</param>
/// <param name="MethodParameters">方法參數</param>
/// <returns>毫秒</returns>
public static long GetMethodRunTime(Type ClassType, object[] ClassParameters, string MethodName, object[] MethodParameters,Type[] MethodParametersType)
{
object obj = Activator.CreateInstance(ClassType, ClassParameters);
MethodInfo method = ClassType.GetMethod(MethodName, MethodParametersType);
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
method.Invoke(obj, MethodParameters);
stopWatch.Stop();
return stopWatch.ElapsedTicks;///Stopwatch.Frequency/1000;
}
int x = -1;
long time = Helper.GetMethodRunTime(typeof(T_RoleService),null,"QueryByPage",new object[]{1,x},new Type[]{ typeof(Int32),typeof(int).MakeByRefType() });
MessageBox.Show(time.ToString());
注意typeof(int).MakeByRefType(),這裏關聯out