Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] Passing a type as a parameter

Threaded View

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Resolved [RESOLVED] [2.0] Passing a type as a parameter

    I want to make a function like this:

    Code:
            private List<Type> GetSubClasses(Type type)
            {
                Type[] TypeList = System.Reflection.Emit.AssemblyBuilder.GetExecutingAssembly().GetTypes();
                List<Type> Result = new List<Type>();
                foreach(Type typ in TypeList)
                {
                    if (typ.BaseType == type)
                        Result.Add(typ);
                }
                return Result;
            }
    This will (hopefully) list all subclasses of a given class. The trouble is i get a compiler error when i write code to call it:

    'CEffect' is a 'type', which is not valid in the given context

    (CEffect is a class)

    I'm guessing i can do this since the function accepting a type did accept it, i'm just not sure how i pass in a type.
    I know i could do it like this Type.GetType("Magic.CEffect",true), but i want to avoid that really as it looks pretty ugly and isn't as universal as i would like.

    Any help would be great!

    EDIT: doh, didn't see the 'typeof' keyword!!!
    Last edited by SLH; May 28th, 2006 at 11:16 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


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