9

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 :)

Soroush Mirzaei
  • 936
  • 2
  • 19
  • 34
  • Do you need to know which classes you can use because this is well documented. – Security Hound Nov 13 '12 at 18:38
  • @Ramhound I'm not quite sure what you're asking, in my scenario I have over 100 rules and each rule has a unique name and implements IRule interface. I want to get all classes that implement IRule interface. – Soroush Mirzaei Nov 13 '12 at 19:20
  • Did you look this [a thread](http://stackoverflow.com/questions/13373000/in-metro-get-all-inherited-classes-of-an-abstract-class)? Maybe it help you NG – Nelson Godinho Nov 14 '12 at 14:11
  • @NelsonGodinho The answer below works perfectly, I'd mark it as answer but I can't until tomorrow. Thanks anyway :) – Soroush Mirzaei Nov 14 '12 at 15:04

1 Answers1

11

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();
Soroush Mirzaei
  • 936
  • 2
  • 19
  • 34