Solved

looking up objects inheriting a specified interface in .net

Posted on 2004-08-08
1
194 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
1 Comment
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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