什么是得到一个MethodBase对象最快的方法是什么?对象、最快、方法、MethodBase

由网友(眼淚笑了)分享简介:我有一个类型的对象和方法名:I have a Type object, and a method name: Type type; string methodName; 和我需要的方法方法名一MethodBase对象,在堆栈​​中的某个地方。这工作:And i need a MethodBase obj...

我有一个类型的对象和方法名:

I have a Type object, and a method name:

Type type;  
string methodName;  

和我需要的方法方法名一MethodBase对象,在堆栈​​中的某个地方。 这工作:

And i need a MethodBase object for the method "methodName", somewhere in the stack. This works:

MethodBase nemo;
StackTrace st = new StackTrace(); // Behaves poorly...
for(int i =0; i< st.FrameCount; i++ )
{
   StackFrame sf = st.GetFrame(i);
   if (sf.GetMethod().Name == methodName)
   {
       nemo = sf.GetMethod();      
   }
}

但我需要一个更快的方法...

But i need a faster approach...

推荐答案

您可以写 type.GetMethod(方法名)

阅读全文

相关推荐

最新文章