Check if a type implements an interface

If you need to check if a type implements an interface you can use the IsAssignableFrom method attached to the Type object:

class Program
{
	public static void Main(string[] args)
	{
		Console.WriteLine("Does Person implement the IPerson interface?");
		if(typeof(IPerson).IsAssignableFrom(typeof(Person)))
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");
 
		Console.WriteLine("Does Foo implement the IPerson interface?");
		if(typeof(IPerson).IsAssignableFrom(typeof(Foo)))
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");
 
		Console.Read();
	}
 
}
 
interface IPerson
{
}
 
class Person : IPerson 
{
}
 
class Foo
{		
}

This will output:
Does Person implement the IPerson interface?
Yes
Does Foo implement the IPerson interface?
No