473,382 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Question about interfaces

Is there an easy way to find out what classes implement a given interface?
For example, it might be useful to know what classes implement ICollectible.

Much obliged,
Geoff.
Jul 21 '05 #1
5 1401
If TypeOf myCollection Is ICollectible Then
' myCollection implements ICollectible
End If

If GetType(ICollectible).IsAssignableFrom(myCollectio n.GetType) Then
'again, myCollection implements ICollectible
End If

In C#, I believe you can use the typeof keyword to get the type of an
object.

Also, You can use the Type.GetInterfaces method to get a collection of type
objects for all the interfaces implemented by an object. You can also use
the Type.GetInterface method to get an interface by name.

hope that helps..
Imran.
"Geoff Pennington" <Ge*******@verizon.netNoSpam> wrote in message
news:ev**************@TK2MSFTNGP14.phx.gbl...
Is there an easy way to find out what classes implement a given interface?
For example, it might be useful to know what classes implement ICollectible.
Much obliged,
Geoff.

Jul 21 '05 #2
Geoff Pennington <Ge*******@verizon.netNoSpam> wrote:
Is there an easy way to find out what classes implement a given interface?
For example, it might be useful to know what classes implement ICollectible.


Again, MSDN is your friend. Go to the overview page for the interface,
and it lists the classes which implement it directly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
If I understand correctly, you are answering the opposite question from the
one I asked. Your reply seems to address the question "What interfaces does
this class implement?", but what I want to know is "What classes implement
this interface?".

Sometimes, when choosing a class for a specific purpose, I want to be sure I
have considered all the options.

Geoff.

"Imran Koradia" <no****@microsoft.com> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
If TypeOf myCollection Is ICollectible Then
' myCollection implements ICollectible
End If

If GetType(ICollectible).IsAssignableFrom(myCollectio n.GetType) Then
'again, myCollection implements ICollectible
End If

In C#, I believe you can use the typeof keyword to get the type of an
object.

Also, You can use the Type.GetInterfaces method to get a collection of type objects for all the interfaces implemented by an object. You can also use
the Type.GetInterface method to get an interface by name.

hope that helps..
Imran.
"Geoff Pennington" <Ge*******@verizon.netNoSpam> wrote in message
news:ev**************@TK2MSFTNGP14.phx.gbl...
Is there an easy way to find out what classes implement a given interface? For example, it might be useful to know what classes implement

ICollectible.

Much obliged,
Geoff.


Jul 21 '05 #4
OK, good. Thanks.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Geoff Pennington <Ge*******@verizon.netNoSpam> wrote:
Is there an easy way to find out what classes implement a given interface? For example, it might be useful to know what classes implement
ICollectible.
Again, MSDN is your friend. Go to the overview page for the interface,
and it lists the classes which implement it directly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5

"Geoff Pennington" <Ge*******@verizon.netNoSpam> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
If I understand correctly, you are answering the opposite question from the one I asked. Your reply seems to address the question "What interfaces does this class implement?", but what I want to know is "What classes implement
this interface?".


My apologies. I misread your question. However, there's no way through code
to figure out what classes implement a given interface. If you are talking
about classes and interfaces in the .NET class library, you can look up the
MSDN documentation for the given interface - it'll have a list of classes
that directly implement the interface.

hope that helps..
Imran.
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
7
by: tshad | last post by:
I am trying to understand why I would use interfaces. In the following example for IPrinciple, I have the following code: ************************************************************ using...
1
by: Larry | last post by:
I checked definition of class CollectionBase public abstract class CollectionBase : IList, ICollection, IEnumerable, it implements 3 interface IList, ICollection and IEnumerable. I found...
1
by: brianlanning | last post by:
I have a class that represents a business object. Currently, this class exists as a vb6 "class" which will be ported to .net. The plan is to separate this out into a .net object residing in a web...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.