using reflection to invoke static methods of the class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    #1

    using reflection to invoke static methods of the class

    Say, I have classname string, static method string, parameters list
    (which is char[]). Can I use reflection to invoke the method?
  • Peter Duniho

    #2
    Re: using reflection to invoke static methods of the class

    On Thu, 16 Oct 2008 13:33:56 -0700, puzzlecracker <ironsel2000@gm ail.com>
    wrote:
    Say, I have classname string, static method string, parameters list
    (which is char[]). Can I use reflection to invoke the method?
    Yes.

    Comment

    • sternr

      #3
      Re: using reflection to invoke static methods of the class

      On Oct 16, 10:33 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
      Say, I have classname string, static  method string, parameters list
      (which is char[]). Can I use reflection to invoke the method?
      Yes.
      Using Type.GetType("Y OUR-TYPE").InvokeMe mber
      The second parameter is BindingFlag, specify BindingFlags.St atic for
      invocation of static methods.

      --sternr

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: using reflection to invoke static methods of the class

        puzzlecracker wrote:
        Say, I have classname string, static method string, parameters list
        (which is char[]). Can I use reflection to invoke the method?
        Yes.

        Example:

        using System;
        using System.Reflecti on;

        namespace E
        {
        public class Program
        {
        public static void Test(char[] ca)
        {
        foreach(char c in ca)
        {
        Console.Write(c );
        }
        Console.WriteLi ne();
        }
        public static void Main(string[] args)
        {
        typeof(Program) .InvokeMember(" Test",
        BindingFlags.De claredOnly | BindingFlags.Pu blic | BindingFlags.St atic |
        BindingFlags.In vokeMethod, null, null, new object[] { new char[] { 'H',
        'e', 'l', 'l', 'o' }});
        Console.ReadKey ();
        }
        }
        }

        Arne

        Comment

        • Ben Voigt [C++ MVP]

          #5
          Re: using reflection to invoke static methods of the class

          puzzlecracker wrote:
          Say, I have classname string, static method string, parameters list
          (which is char[]). Can I use reflection to invoke the method?
          Are you referring to a constructor (method name == class name)? Yes you can
          use reflection, no most of the code suggested to you isn't going to work
          exactly the same for constructor calls.


          Comment

          Working...