Results 1 to 4 of 4

Thread: (Another) Reflection question?

  1. #1

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

    (Another) Reflection question?

    i have 2 projects and a dll...
    the dll is the plugin abstract class im going to inherit from when doing plugins...
    one project is the main app and the other project is the plugin.

    the plugin project will inherit from the abstract class..and the main app thru reflection will invoke some methods of that class.
    the problem is the following: my abstract class, and it's derived classes have its default constructor private and instead they have a one parameter constructor.
    As many of the future plugin's will have many classes inside the assembly , when i do the :

    Code:
    					foreach (Type type in types) {
    i want to put a "if" to check whenever to use that class(the types that are derived from the plugin dll abstract class are used, the others are ignored) but i am finding the following problem:
    to use the .IsSubClassOf() function i must create an instance of the class i want to analise...and the main app only has a reference to the abstract class but i cant create instances of abstract classes. So how would i know if a class from the plugins derivates from the abstract plugin class?
    \m/\m/

  2. #2
    Member
    Join Date
    Mar 2003
    Posts
    34
    This works?

    Code:
    using System;
    using System.Reflection;
    
    public abstract class Vehicle {
    
        public string Make;
        public string Model;
    
        static void Main() {
            Type t = typeof(Car);
            Console.WriteLine(t.IsSubclassOf(typeof(Vehicle)));
        }
    }
    
    public class Car: Vehicle {}
    The IsSubClassOf() method wants a type reference.
    AKA 'Lethal'

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    no doesnt work because he wants an instantiated class, if i dont instantiate the class he just says that it is a unassigned var
    \m/\m/

  4. #4

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    AHH! i think i misread (or how it is said) your post! now it is not appointing any kind of error..ill check it out
    \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