开发者

What is the fastest way to get a MethodBase object?

开发者 https://www.devze.com 2023-03-06 02:23 出处:网络
I have a Type object, and a method name: Type type; string methodName; And i need a MethodBase object for the method \"methodName\", somewhere in the stack.

I have a Type object, and a method name:

Type type;  
string methodName;  

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++ )
{
   St开发者_运维百科ackFrame sf = st.GetFrame(i);
   if (sf.GetMethod().Name == methodName)
   {
       nemo = sf.GetMethod();      
   }
}

But i need a faster approach...


You can write type.GetMethod(methodName).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号