Results 1 to 4 of 4

Thread: Know through reflection if a class is derived from another class

  1. #1

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

    Know through reflection if a class is derived from another class

    how do i do this?
    \m/\m/

  2. #2

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i did it: just in case it was:
    Code:
    		private void GUI_Load(object sender, System.EventArgs e) {
    			Assembly asm = Assembly.LoadFrom("devListener.dll");
    			Type[] types = asm.GetTypes();
    
    			Metamorfosis Interface;
    			Metamorfosis ex = new Metamorfosis(this);
    			Type ex2 = ex.GetType();
    			object[] p = { this };
    
    			foreach (Type derived in types) {
    				if (derived.IsSubclassOf(ex2)) {
    					Interface = (Metamorfosis)Activator.CreateInstance(derived, p);
    					derived.InvokeMember("Test", BindingFlags.Default | BindingFlags.InvokeMethod,
    						null, Interface, new object[0]);
    				}
    			}
    		}
    \m/\m/

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    you can also use the 'is' and 'as' operators for this.

  4. #4

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yea i've noticed that tks anyways
    \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