Peter:
Try using the method "IsAssignableFrom", like this:
interface Interface1
{
}
interface Interface2 : Interface1
{
}
class A : Interface2
{
}
static void Main(string[] args)
{
Console.WriteLine(typeof(A).IsAssignableFrom(typeo f(Interface1)).ToStrin
g());
Console.WriteLine(typeof(A).IsAssignableFrom(typeo f(Interface2)).ToStrin
g());
Console.ReadLine();
}
Good luck!
Gustavo A. Cantero
CEO - Scientia® Soluciones Informáticas
MCP - MCSD - MCTS
http://www.scientia.com.ar http://www.programandoamedianoche.com http://foro.scientia.com.ar
-----Mensaje original-----
De: Peter Morris [mailto:mr*********@SPAMgmail.com]
Expuesto a las: Lunes, 20 de Octubre de 2008 12:06 p.m.
Expuesto en: microsoft.public.dotnet.languages.csharp
Conversación: Does a class implement an interface?
Asunto: Does a class implement an interface?
interface Interface1
{
}
interface Interface2 : Interface1
{
}
class A : Interface2
{
}
static void Main(string[] args)
{
Console.WriteLine(typeof(A).IsSubclassOf(typeof(In terface1)).ToString())
;
Console.WriteLine(typeof(A).IsSubclassOf(typeof(In terface2)).ToString())
;
Console.ReadLine();
}
Both return False. Given a type what is the simplest way of checking if
it
implements Interface1 either directly, or by implementing Interface2?
--
Pete
====
http://mrpmorris.blogspot.com http://www.capableobjects.com