How to determine from MethodInfo - if a method is a dynamic method?

Answered How to determine from MethodInfo - if a method is a dynamic method?

  • Friday, May 18, 2012 3:37 PM
     
     

    Is there way with reflection to ascertain if a method is dynamic (generated dynamically) ?

    I can see no obvious properties in MethodInfo or MethodBase so wondered if anyone had any idea?

    Thx

    Cap'n

All Replies

  • Friday, May 18, 2012 3:42 PM
    Moderator
     
     Answered

    Hmm, check the type ?

    if (methodInfo is System.Reflection.Emit.DynamicMethod) { // methodInfo is a dynamic method... }

  • Friday, May 18, 2012 6:11 PM
     
     Answered Has Code

    Hi, 

    You can also rely on ReflectedType. For dynamic methods ReflectedType is always null.

    if(methodInfo.ReflectedType == null)
    {
     //methodInfo is dynamicmethod
    }


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

  • Saturday, June 02, 2012 4:33 PM
     
     

    Hmm, check the type ?

    if (methodInfo is System.Reflection.Emit.DynamicMethod) { // methodInfo is a dynamic method... }

    Very good Mike - much appreciated.