Peter:
Try using the method "IsAssignableFr om", like this:
interface Interface1
{
}
interface Interface2 : Interface1
{
}
class A : Interface2
{
}
static void Main(string[] args)
{
Console.WriteLi ne(typeof(A).Is AssignableFrom( typeof(Interfac e1)).ToStrin
g());
Console.WriteLi ne(typeof(A).Is AssignableFrom( typeof(Interfac e2)).ToStrin
g());
Console.ReadLin e();
}
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.c om]
Expuesto a las: Lunes, 20 de Octubre de 2008 12:06 p.m.
Expuesto en: microsoft.publi c.dotnet.langua ges.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.WriteLi ne(typeof(A).Is SubclassOf(type of(Interface1)) .ToString())
;
Console.WriteLi ne(typeof(A).Is SubclassOf(type of(Interface2)) .ToString())
;
Console.ReadLin e();
}
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