Results 1 to 8 of 8

Thread: Determining implements[Resolved]

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Determining implements[Resolved]

    I want to look at types in assemblies and determine one, if it's a Form, but also if it implements an interface - say MyInterface.

    Here's what I have so far
    PHP Code:
                            Assembly a Assembly.LoadFrom(fileName);
                            
    Type[] types a.GetTypes();
                            foreach (
    Type t in types)
                            {
                                if (
    t.BaseType == typeof(Form)) // and it implements MyInterface ???
                                
    {
                                    
    Application.Run((Form)Activator.CreateInstance(t));
                                }
                            } 
    How can I figure that out?

    Thanks,
    Mike

    Edit: like this:
    Code:
    if (t.BaseType == typeof(Form) && typeof(MyInterface).IsAssignableFrom(t))
    Last edited by Mike Hildner; Aug 12th, 2004 at 02:31 PM.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    The type object also provides a GetInterface() function that accepts a string that you can use to check if a specific Interface name is implemented. If returns null, the interface isnt implemented
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Thanks. I guess I should have mentioned that this is on the Compact Framework, which does not have GetInterface. It does have GetInterfaces, though. But then you have to iterate through that. My code is getting loopy enough

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913


    Loopy. Ill have to remember that term.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I mean it in both contexts:
    1) Consisting of or covered with loops.
    2) Offbeat; crazy: “the loopy energy of Harpo Marx” (Michael Wood).

    I'm trying to make a plug in app for the compact framework, so there's a foreach for all files in my "Plugins" directory, then an if statement to see if it's a dll, then a foreach for the types in each assembly, then another if statement to see if the type is a form and implements my interface.

  6. #6
    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

  7. #7

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Cander, what do you do with your plugins? I mean, what's the architecture? Not even sure if I'm asking that correctly. With mine, I'm envisioning selling modules. Right now my interface only defines one method, GetDisplayName(). That gets called and added to the plugin menu. Then when you click the menu item, it shows the dll's form.

    I'm thinking of also getting an image from the plugin, and add that to a list view - a little better looking.

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I never really used it for anything important. It was just something I wrote some time ago because people were asking how to do it. I did use it to test adding new tabs with controls on it to a tab control on a form by having a seperate plugin for each tab. Worked very well.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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