How do I detect that a specific Type is a delegate?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    How do I detect that a specific Type is a delegate?

    Hi everyone, I guess this question applies to C# too. I am using the Assembly.GetTyp es() reflection method to build an object explorer for my project, and for the life of me I can't seem to figure out how to tell a regular class apart from a delegate in my query loop. Any ideas on how I could tell the difference?

    It's probably not the hardest thing in the world, but it shows up my lack of current knowledge in reflection, so will be glad to hear from those more experienced in the area :)

    ---

    Ok after a while of playing round I discovered that it's possible to query weather the type has the BaseClass type MulticastDelega te, so made this extension method:

    Code:
    <Extension()>
    Public Function IsDelegate(ByVal aType As Type) As Boolean
        Return aType.BaseType Is GetType(MulticastDelegate)
    End Function
    And it seems to work, however as this is a new subject to me, I am fully aware that this maybe the wrong way to do it, anyone have any thoughts?

    Aimee.
    Last edited by Aimee Bailey; Aug 6 '11, 04:23 AM. Reason: Found a possible solution.
Working...