any possibility of calling a method by it's String name?

Discussion in 'C#' started by most_afar, Aug 1, 2006.

  1. most_afar

    most_afar New Member

    Joined:
    Aug 1, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi
    Is it possible to call a method by it's String name?
    something like this:

    System.callByName("MyMethod1","MyParameters");

    where the mothod "MyMethod1" is defined somewhere accessible with
    parameters "MyParameters".

    Thank you.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,335
    Likes Received:
    377
    Trophy Points:
    83
    You need to use System.Reflection class to extract detail of a class. The MemberInfo class available in System.Reflection namespace is an abstract class. It discovers the attributes of a member and provides access to the member metadata. You need to assign the details you need to query about a type viz. Constructors/Methods/Interfaces/Fields/Property etc. to the MemberInfo class local variable and use methods like GetFields/GetMethods/GetInterfaces etc ...
     
  3. most_afar

    most_afar New Member

    Joined:
    Aug 1, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Thank you shabbir.
    your comment was usefull for me.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,335
    Likes Received:
    377
    Trophy Points:
    83
    My pleasure.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice