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
  1. Home
  2. General Programming
  3. C#
  4. dynamically invoking a method in an assemly

dynamically invoking a method in an assemly

Scheduled Pinned Locked Moved C#
helpdata-structurescareer
3 Posts 2 Posters 0 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
    Sonu T
    wrote on last edited by
    #1

    hi everybody, i was given a job of developing a function which accepts 3 parameters i.e., an assembly path, a class with namespace, and a method in that assembly. the function should return the value that is being returned by the method that iam invoking(the one which we passed as a parameter) iam using system.reflection namespace. the problem is, i also need to pass arguements to the method that iam invoking but it is just not working the i way i want. this is how iam calling my function .. public int myreflect("..the path of the assembly..", "...calss name with namespace..say N.C1..","..method name..say M1..", 2,4) // 2,4 are the arguments iam passing to my method M1// this is how iam defining my function public int myreflect(string a, string b, string c, params int[] list) everything is working except that i need to somehow extract the arguements which are in the param array i.e., list. i need to capture those arguments and store them in another array..say int[] args..and use this args in Invokemember function, as parameters to invoke my M1 method. i hope i have done a fair job in explaining my problem. a little help would be greatly appreciated. Thanks in advance....

    Sonu

    S 1 Reply Last reply
    0
    • S Sonu T

      hi everybody, i was given a job of developing a function which accepts 3 parameters i.e., an assembly path, a class with namespace, and a method in that assembly. the function should return the value that is being returned by the method that iam invoking(the one which we passed as a parameter) iam using system.reflection namespace. the problem is, i also need to pass arguements to the method that iam invoking but it is just not working the i way i want. this is how iam calling my function .. public int myreflect("..the path of the assembly..", "...calss name with namespace..say N.C1..","..method name..say M1..", 2,4) // 2,4 are the arguments iam passing to my method M1// this is how iam defining my function public int myreflect(string a, string b, string c, params int[] list) everything is working except that i need to somehow extract the arguements which are in the param array i.e., list. i need to capture those arguments and store them in another array..say int[] args..and use this args in Invokemember function, as parameters to invoke my M1 method. i hope i have done a fair job in explaining my problem. a little help would be greatly appreciated. Thanks in advance....

      Sonu

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      As InvokeMember takes an object array, copy the content of the integer array into such an array and then pass it to InvokeMember.

      object[] args = new object[list.Length];
      list.CopyTo(args, 0);


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      S 1 Reply Last reply
      0
      • S Stefan Troschuetz

        As InvokeMember takes an object array, copy the content of the integer array into such an array and then pass it to InvokeMember.

        object[] args = new object[list.Length];
        list.CopyTo(args, 0);


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        S Offline
        S Offline
        Sonu T
        wrote on last edited by
        #3

        Thanx Stefan!! this is exactly what i wanted. iam gratefulto you....thanx once again..:-O

        Sonu

        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