Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all classes that implement a given interface in WinRT

I'm trying to get a list of classes that implement a certain interface in windows 8 store apps but it seems that reflection is very different in WinRT and so far I couldn't find a good example of doing so.

Does anyone know, how to load the current assembly and loop through it?

Any help is much appreciated :)

like image 536
Soroush Mirzaei Avatar asked Nov 13 '12 17:11

Soroush Mirzaei


1 Answers

Got an answer from the MSDN forums. Just posting it here in case someone else is looking for the same thing.

This code will get all classes that implement IDisposable interface:

// We get the current assembly through the current class
var currentAssembly = this.GetType().GetTypeInfo().Assembly;

// we filter the defined classes according to the interfaces they implement
var iDisposableAssemblies = currentAssembly.DefinedTypes.Where(type => type.ImplementedInterfaces.Any(inter => inter == typeof(IDisposable))).ToList();
like image 185
Soroush Mirzaei Avatar answered Oct 09 '22 07:10

Soroush Mirzaei