Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Reflection ... Call Method. Parameter question

Reflection ... Call Method. Parameter question

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Seraphin
    wrote on last edited by
    #1

    I have the OnButtonClick Event inside a Form btnGetInfo_Click(object sender, System.EventArgs e) Here is the implementation System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click", **???**); mi.Invoke(oSender, System.Reflection.BindingFlags.InvokeMethod, null, **null???**, null); But how I can implement the parameters - object sender and System.EventArgs e ?

    O 1 Reply Last reply
    0
    • S Seraphin

      I have the OnButtonClick Event inside a Form btnGetInfo_Click(object sender, System.EventArgs e) Here is the implementation System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click", **???**); mi.Invoke(oSender, System.Reflection.BindingFlags.InvokeMethod, null, **null???**, null); But how I can implement the parameters - object sender and System.EventArgs e ?

      O Offline
      O Offline
      occcy
      wrote on last edited by
      #2

      System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click", ???); the overload list for GetMethod provides several possible parameterlists. if there is only one method btnGetInfo_Click inside your form, you can call GetMethod only with your methodname. otherwise you have to pass the types of your parameters: System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click"); or System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click", **new Type[]{typeof(object),typeof(EventArgs)}**); mi.Invoke(oSender, System.Reflection.BindingFlags.InvokeMethod, null, null???, null); the forth parameter needs an array of parameters for "sender" and "e". mi.Invoke(oSender, System.Reflection.BindingFlags.InvokeMethod, null, **new object[]{null,null}**, null);

      S 1 Reply Last reply
      0
      • O occcy

        System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click", ???); the overload list for GetMethod provides several possible parameterlists. if there is only one method btnGetInfo_Click inside your form, you can call GetMethod only with your methodname. otherwise you have to pass the types of your parameters: System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click"); or System.Reflection.MethodInfo mi = this.oSender.GetType().GetMethod("btnGetInfo_Click", **new Type[]{typeof(object),typeof(EventArgs)}**); mi.Invoke(oSender, System.Reflection.BindingFlags.InvokeMethod, null, null???, null); the forth parameter needs an array of parameters for "sender" and "e". mi.Invoke(oSender, System.Reflection.BindingFlags.InvokeMethod, null, **new object[]{null,null}**, null);

        S Offline
        S Offline
        Seraphin
        wrote on last edited by
        #3

        thx

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups