Click to See Complete Forum and Search --> : Determining implements[Resolved]
Mike Hildner
Aug 12th, 2004, 01:58 PM
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
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:
if (t.BaseType == typeof(Form) && typeof(MyInterface).IsAssignableFrom(t))
Cander
Aug 12th, 2004, 03:34 PM
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
Mike Hildner
Aug 12th, 2004, 03:39 PM
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 :)
Cander
Aug 12th, 2004, 03:46 PM
:p
Loopy. Ill have to remember that term.
Mike Hildner
Aug 12th, 2004, 03:56 PM
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.
Cander
Aug 13th, 2004, 08:42 AM
Oh yeah. I know all about that.
http://www.vbforums.com/showthread.php?s=&threadid=194447&highlight=plugin+cander
:p
Mike Hildner
Aug 13th, 2004, 09:07 AM
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.
Cander
Aug 13th, 2004, 09:30 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.