Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 可移植类库反射_C#_Reflection_Portable Class Library - Fatal编程技术网

C# 可移植类库反射

C# 可移植类库反射,c#,reflection,portable-class-library,C#,Reflection,Portable Class Library,我目前正在尝试将Xamarin.iOS应用程序库转换为PCL(配置文件78)。我有一段不会编译的代码: public static void RegisterAllCommandHandlers(IEnumerable<Assembly> assemblies) { // Get all types that are concrete classes which implement ICommandHandler var comman

我目前正在尝试将Xamarin.iOS应用程序库转换为PCL(配置文件78)。我有一段不会编译的代码:

 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)));
            }
    }
publicstaticvoid寄存器alcommandhandlers(IEnumerable程序集){
//获取所有实现ICommandHandler的具体类的类型
var commandHandlerOpenGenericType=typeof(ICommandHandler);
变量类型=新列表();
foreach(程序集中的变量程序集){
types.AddRange(assembly.GetTypes()
其中(x=>x.IsClass&!x.isastract&&x.GetInterfaces().Any(i=>i.IsGenericType&&i.GetGenericTypeDefinition()==commandHandlerOpenGenericType));
}
}
以下是编译器错误的图像:


如何使用新的反射API执行相同的操作?

这是由于类型/typeinfo拆分造成的。看

请尝试以下代码:

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

您的PCL针对哪些平台?@Markus Profile 78(Xamarin.IOS、Xamarin.Android、.net 4.5、windows应用商店、windows phone 8)您得到了哪些编译器错误?(图像未显示编译器错误)。@elgonzo无法解析红色每个项目的“符号”