plz help on delegates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rox59
    New Member
    • Jan 2007
    • 4

    plz help on delegates

    I need anyone's help!!! i have to build a list of methods that will be available for decoupled components to add and call functions from another components, so far i am using delegates to add methods to the list, but delegates ask me to state the type of parameters that each method has, and i want the list to accept any kind of method regarding the signaturei want to be able to do this:

    class1{
    List methods;
    methods.add(int index, Method method) //Method can be other than Delegate, i don't mind
    { .... }
    }
    class2{
    class1.methods. add(1,M1);
    class2.methods. add(2,M2);
    class3.methods. add(3,M3);

    void M1(string g){...}
    void M2(int f, int w){ .. }
    void M3() { ... }
    }

    class3{
    class1.call(1);
    class1.call(3);
    }

    please please please!!! somebody?? anybody??
  • enreil
    New Member
    • Jan 2007
    • 86

    #2
    I don't know a whole lot about using delegates, but can't you just have them accept parameters of type Object or Object(), depending on whether you want to pass single or multiple parameters?

    Originally posted by rox59
    I need anyone's help!!! i have to build a list of methods that will be available for decoupled components to add and call functions from another components, so far i am using delegates to add methods to the list, but delegates ask me to state the type of parameters that each method has, and i want the list to accept any kind of method regarding the signaturei want to be able to do this:

    class1{
    List methods;
    methods.add(int index, Method method) //Method can be other than Delegate, i don't mind
    { .... }
    }
    class2{
    class1.methods. add(1,M1);
    class2.methods. add(2,M2);
    class3.methods. add(3,M3);

    void M1(string g){...}
    void M2(int f, int w){ .. }
    void M3() { ... }
    }

    class3{
    class1.call(1);
    class1.call(3);
    }

    please please please!!! somebody?? anybody??

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Originally posted by rox59
      I need anyone's help!!! i have to build a list of methods that will be available for decoupled components to add and call functions from another components, so far i am using delegates to add methods to the list, but delegates ask me to state the type of parameters that each method has, and i want the list to accept any kind of method regarding the signaturei want to be able to do this:

      class1{
      List methods;
      methods.add(int index, Method method) //Method can be other than Delegate, i don't mind
      { .... }
      }
      class2{
      class1.methods. add(1,M1);
      class2.methods. add(2,M2);
      class3.methods. add(3,M3);

      void M1(string g){...}
      void M2(int f, int w){ .. }
      void M3() { ... }
      }

      class3{
      class1.call(1);
      class1.call(3);
      }

      please please please!!! somebody?? anybody??
      Why do you need to use only one delegate?
      Couldn't you declare three delegates, and for each different set of arguments?
      If you could overload delegates, then you would only ever need one.

      Comment

      • rox59
        New Member
        • Jan 2007
        • 4

        #4
        Originally posted by Motoma
        Why do you need to use only one delegate?
        Couldn't you declare three delegates, and for each different set of arguments?
        If you could overload delegates, then you would only ever need one.
        Thanks for your posts, I kind of solved it by storing an object of type Method in the methods list with the constructor

        Code:
        Method(string [I]name[/I] , Type[] [I]argsTypes[/I], [I]Type instanceType[/I])
        the argsTypes is not really necessary if you are not overloading methods within the same component which is not my case :(

        the list only holds those attributes and when i want to call the method from another component I use another function in my Method class that basically does this:

        Code:
        instanceType.InvokeMember([I]name[/I], BindingFlags.InvokeMethod, null, [I]instance[/I], userParameters);
        i get the instance object from an inner list that has all executing component instances

        Comment

        Working...