jQuery and ASP.NET

November 21, 2009

Determine all Types that Implement an Interface




I recently saw an interesting discussion on a forum. The discussion was about finding all the types that implement a particular interface. Here’s a code that lists all the types implementing a particular interface:

C#

using System.Linq;
public static void Main(string[] args)
{
var t = typeof(IYourInterfaceName);
var assemblyTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(typ => typ.GetTypes())
.Where(x => t.IsAssignableFrom(x));
foreach (var v in assemblyTypes)
{
Console.WriteLine(v.FullName);
}
Console.ReadLine();
}

VB.NET

Public Shared Sub Main(ByVal args() As String)
Dim t = GetType(IYourInterfaceName)
Dim assemblyTypes = AppDomain.CurrentDomain.GetAssemblies() _
.SelectMany(Function(typ) typ.GetTypes()) _
.Where(Function(x) t.IsAssignableFrom(x))
For Each v In assemblyTypes
Console.WriteLine(v.FullName)
Next v
Console.ReadLine()
End Sub


'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Determine all Types that Implement an Interface"
 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions