Results 1 to 9 of 9

Thread: Invoke methods thru reflection

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Invoke methods thru reflection

    how do i invoke methods of a class of mine thru reflection? how do i invoke static and non-static methods? tks
    \m/\m/

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Remember this
    http://www.vbforums.com/showthread.p...=plugin+cander

    look at the InvokeMember part.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm yea i suck sorry
    \m/\m/

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm that example sucks a bit because i dont have the interface and that thing doesnt even instantiate the class..or does it? an code that i can put in vs.net and see it work or something like that would be a lot better :\

    edit: hmm actually it creates an instance..let me check it again..grr
    \m/\m/

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    just take out the interface stuff and use the object's name isntead of IPlugin for casting.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    btw how does it know if the interface PLUGIN that the caller has is the same as the plugin has?
    \m/\m/

  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm i am not achieving what i want..i keep getting an "instance Additional information: Specified cast is not valid.
    " or whatever:

    Code:
    		private void button1_Click(object sender, System.EventArgs e) {
    			Assembly asm = Assembly.LoadFrom("teste.dll");
    			object classTest = asm.CreateInstance("BRANCO_Class");
    			object[] _params = {};
    			IPlugin plugin;
    
    			System.Type[] types = asm.GetTypes();
    
    			foreach (System.Type type in types) {
    				plugin = (IPlugin)Activator.CreateInstance(type);
    			}
    		}
    plugin interface
    Code:
    	public interface IPlugin {
    		void attack();
    	}
    edit: i think i finally did it...
    edit2: FINALLY DID IT
    Last edited by PT Exorcist; Feb 7th, 2003 at 02:33 PM.
    \m/\m/

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm...now i have a different case...i have a plugin which has a form...that form has a control(a Panel)...i already created an instance of the form...now how do i retrieve the panel off it? which kind of thing is the panel? a field? i tried listing all fields using GetFields() but none field appear...

    any suggestions?
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width