Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

looking up objects inheriting a specified interface in .net

Posted on 2004-08-08
1
Medium Priority
?
198 Views
Last Modified: 2010-04-15
is there a way of looking up all objects inheriting a specified interface in the .net class library?
0
Comment
Question by:sethUSer420
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 1000 total points
ID: 11748517
sure is !

you would need to run through a set of classes ...

when you get the type for the class on of the methods is GetInterfaces http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtypeclassgetinterfacestopic.asp

using System;
using System.Web;
using System.Web.UI;

namespace Samples
{
    public class MyTemplate : Control, INamingContainer
    {
        private String _message = null;
        public String Message
        {
            get
            {
                return _message;
            }
            set
            {
                _message = value;
            }
        }    
    }
    public class MyInterfacesSample
    {
        public static void Main()
        {
            try
            {
                Type[] myObjectArray= typeof(MyTemplate).GetInterfaces();
                Console.WriteLine("The interfaces inherited by the MyTemplate class are:\n");
                for (int index = 0; index < myObjectArray.Length; index++)
                {    
                    Console.WriteLine(myObjectArray[index]);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred.");
                Console.WriteLine("Message: " + e.Message);
            }
        }
    }
}

is an example of how to use it, you would simply compare your interface to the interfaces of the class to see if it contains it.

so you would need to run through the assemblies and test each type to see if it contained the interface.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question