|
-
Jan 25th, 2006, 07:12 PM
#1
Thread Starter
Hyperactive Member
find all classes that implement an interface
I searched, but only saw some code for java.
How can this be done in C#?
Thanks!!
-
Jan 26th, 2006, 02:28 AM
#2
Re: find all classes that implement an interface
Are you talking about writing code to that at run time? If so I don't see how it's practically possible. If you don't have a reference to an assembly in your project then your app can't query that assembly to know anything about what it contains. Therefore you'd have to reference every assembly in the Framework in order to do it. I'd assume that you would then have to use reflection to test every class to see if it implemented the interface using Type.GetInterface.
-
Jan 26th, 2006, 04:47 AM
#3
Re: find all classes that implement an interface
You'll need to loop through the classes in the assembly. To check if it implements an interface, say
if(typeof(classname) is interfacename)
{
//
}
Check this thread for assembly information through reflection
http://www.vbforums.com/showthread.p...ght=reflection
It's in VBCode, but I'm sure you can conver it.
-
Jan 26th, 2006, 05:06 AM
#4
Re: find all classes that implement an interface
 Originally Posted by mendhak
You'll need to loop through the classes in the assembly. To check if it implements an interface, say
if(typeof(classname) is interfacename)
{
//
}
Check this thread for assembly information through reflection
http://www.vbforums.com/showthread.p...ght=reflection
It's in VBCode, but I'm sure you can conver it.
That makes perfect sense. No wonder I didn't think of it.
-
Jan 27th, 2006, 07:46 PM
#5
Thread Starter
Hyperactive Member
Re: find all classes that implement an interface
How do you start it out and set the type to "System". I tried several things, but none were right. It does sound weird because system is a namespace, not a type - but, you know what I mean? I'd want to loop through everything in system.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|