2013-12-11 10 views
7

Obecnie próbuję przekonwertować bibliotekę aplikacji Xamarin.iOS na PCL (profil 78). Mam ten kod, który nie zostanie skompilowany:Przenośna biblioteka klasy Refleksja

public static void RegisterAllCommandHandlers(IEnumerable<Assembly> assemblies) { 
      // Get all types that are concrete classes which implement ICommandHandler 
      var commandHandlerOpenGenericType = typeof(ICommandHandler<>); 
      var types = new List<Type>(); 
      foreach (var assembly in assemblies) { 
       types.AddRange(assembly.GetTypes() 
         .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == commandHandlerOpenGenericType))); 
      } 
    } 

Oto obraz błędów kompilatora: enter image description here

Jak mogę zrobić to samo z nowym refleksji API?

+0

Które platformy pan kierować w swojej PCL? – Markus

+0

@Markus Profile 78 (Xamarin.IOS, Xamarin.Android, .net 4.5, Windows Store, Windows Phone 8 –

+0

Jakie są błędy kompilatora, które otrzymujesz? (Obrazek nie pokazuje błędów kompilatora) – elgonzo

Odpowiedz

16

Jest to spowodowane podziałem typu/typu info. Zobacz Evolving the Reflection API.

Spróbuj kod:

assembly.DefinedTypes 
    .Where(x => x.IsClass && !x.IsAbstract && x.ImplementedInterfaces 
     .Any(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == commandHandlerOpenGenericType)) 
    .Select(x => x.AsType()) 
+0

Pracowałem bardzo dziękuję! –

Powiązane problemy