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

  • Question

  • 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

    Friday, May 18, 2012 3:37 PM

Answers

  • Hmm, check the type ?

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

    • Proposed as answer by Kris444 Friday, May 18, 2012 6:09 PM
    • Marked as answer by Mike FengModerator Thursday, May 31, 2012 11:33 AM
    Friday, May 18, 2012 3:42 PM
    Moderator
  • 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".

    Friday, May 18, 2012 6:11 PM

All replies

  • Hmm, check the type ?

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

    • Proposed as answer by Kris444 Friday, May 18, 2012 6:09 PM
    • Marked as answer by Mike FengModerator Thursday, May 31, 2012 11:33 AM
    Friday, May 18, 2012 3:42 PM
    Moderator
  • 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".

    Friday, May 18, 2012 6:11 PM
  • Hmm, check the type ?

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

    Very good Mike - much appreciated.

    Saturday, June 2, 2012 4:33 PM