/// <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