[Reflection] Is it possible to Invoke a static method?

Discussion in 'ASP .Net' started by [Gauthier], Dec 2, 2003.

  1. [Gauthier]

    [Gauthier] Guest

    Hi,

    Is it possible to invoke a System.Reflection.MethodInfo that reference a
    static method?

    If no, is there any other way (via reflection) to invoke a static method?

    Thanks

    Gauthier
     
    [Gauthier], Dec 2, 2003
    #1
    1. Advertising

  2. [Gauthier]

    Eric Cadwell Guest

    Sure...

    Type t = typeof(CustomType);
    if (t!= null)
    {
    foreach (MethodInfo mi in t.GetMethods(BindingFlags.Static |
    BindingFlags.Public))
    {
    Console.WriteLine("method {0}", mi.Name);
    mi.Invoke(null, null);
    }
    }

    HTH;
    Eric Cadwell
    http://www.origincontrols.com
     
    Eric Cadwell, Dec 2, 2003
    #2
    1. Advertising

  3. [Gauthier]

    [Gauthier] Guest

    Hi, it works nicefully, thanks!

    Gauthier

    "Eric Cadwell" <> wrote in message
    news:...
    | Sure...
    |
    | Type t = typeof(CustomType);
    | if (t!= null)
    | {
    | foreach (MethodInfo mi in t.GetMethods(BindingFlags.Static |
    | BindingFlags.Public))
    | {
    | Console.WriteLine("method {0}", mi.Name);
    | mi.Invoke(null, null);
    | }
    | }
    |
    | HTH;
    | Eric Cadwell
    | http://www.origincontrols.com
    |
    |
     
    [Gauthier], Dec 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jerry051
    Replies:
    2
    Views:
    805
    Oliver Sturm
    Aug 2, 2005
  2. Daniel
    Replies:
    0
    Views:
    449
    Daniel
    Mar 12, 2005
  3. imran
    Replies:
    1
    Views:
    18,061
    Thomas Fritsch
    Feb 1, 2005
  4. Alex Luya
    Replies:
    7
    Views:
    400
    Mike Schilling
    Aug 12, 2009
  5. Sébastien de Mapias
    Replies:
    11
    Views:
    918
    Roedy Green
    Nov 9, 2009
Loading...

Share This Page