0

I'm currently developing an APP using UWP in C#. I wanted to use reflection in order to discover available classes and dynamically let users select which one to use. It seems that UWP Reflection doesn't work exactly the same way as for other C# applications. So I can't find code that work. I need to discover which classes are available that extend a particular class.

Can someone point me on the right direction?

Ricardo Alves
  • 1,071
  • 18
  • 36
  • duplicated: http://stackoverflow.com/questions/8928464/for-an-object-can-i-get-all-its-subclasses-using-reflection-or-other-ways – aaalex88 Oct 02 '16 at 12:58
  • @aaalex88 it's not a duplicate, because uwp uses .NET Core and there are some API changes in reflection: https://blogs.msdn.microsoft.com/dotnet/2012/08/28/evolving-the-reflection-api/ – Stefano Balzarotti Oct 02 '16 at 16:10

1 Answers1

1
using System.Reflection;

List<Type> derivedClassList = typeof(MyClass).GetTypeInfo().Assembly.GetTypes().Where(type => type.IsInstanceOfType(typeof(MyClass))).ToList();

Reflection API changes in .NET Core : https://blogs.msdn.microsoft.com/dotnet/2012/08/28/evolving-the-reflection-api/

Stefano Balzarotti
  • 1,760
  • 1
  • 18
  • 35
  • Thanks! that is indeed something that works. But that does not solved my problem, as the base class is not on the same assembly as the classes that extend it. Do you knwo how I can get all assemblies? – Ricardo Alves Oct 02 '16 at 17:57
  • I think there is no a clean way in UWP, but you can search in all .dll from install directory: http://stackoverflow.com/a/38120023/5081328 – Stefano Balzarotti Oct 02 '16 at 18:21